为什么我在创建着色器类型35663时遇到运行时错误

问题描述 投票:1回答:1

我想学习OpenGL,并且遵循此tutorial,然后在教程1.3中出现了问题。目的是制作一个三角形,但我遇到了错误。代码已编译,但是在运行时始终会在创建着色器类型时出错。

/*
Tutorial 03 - First triangle
*/
#include <stdio.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include "math_3d.h"

GLuint VBO;

static void RenderSceneCB()
{
  glClear(GL_COLOR_BUFFER_BIT);
  glEnableVertexAttribArray(0);
  glBindBuffer(GL_ARRAY_BUFFER, VBO);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
  glDrawArrays(GL_TRIANGLES, 0, 3);
  glDisableVertexAttribArray(0);
  glutSwapBuffers();
}

static void InitializeGlutCallbacks()
{
  glutDisplayFunc(RenderSceneCB);
}

static void CreateVertexBuffer() {
  Vector3f Vertices[3];
  Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f);
  Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
  Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);

  glGenBuffers(1, &VBO);
  glBindBuffer(GL_ARRAY_BUFFER, VBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}


int main(int argc, char** argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
  glutInitWindowSize(1024, 768);
  glutInitWindowPosition(100, 100);
  glutCreateWindow("Tutorial 03");

  InitializeGlutCallbacks();

  // Must be done after glut is initialized!
  GLenum res = glewInit();
  if (res != GLEW_OK) {
    fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
    return 1;
  }
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  CreateVertexBuffer();
  glutMainLoop();
  return 0;
}

感谢@kilon提醒我,是否可能因为我使用Windows?问题与Windows相关吗?

赞赏指向资源

error msgerror msg in new tab

c opengl shader
1个回答
0
投票

如果使用.vsh和.fsh文件,请尝试将其添加到项目中:

Go to your project -> Targets -> Build Phases -> Copy Bundle Recourses

并添加这两个文件。

希望获得帮助。

UPD:这适用于Mac OS(Xcode)。

© www.soinside.com 2019 - 2024. All rights reserved.