我最近开始通过 SuperBible 第五版学习 OpenGl,不幸的是在他们提供的第一个示例中被卡住了。
这是代码:
#include <GLTools.h>
#include <GLShaderManager.h>
#include <GL/glew.h>
#include <GL/glut.h>
GLShaderManager shaderManager;
GLBatch triangleBatch;
void ChangeSize(GLsizei w, GLsizei h);
void ChangeSize(int w, int h){
glViewport(0,0,w,h);
}
void SetupRC(){
//background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
shaderManager.InitializeStockShaders();
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f};
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLfloat vRed[] = {1.0f, 0.0f, 0.0f, 1.0f};
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
//gltSetWorkingDirectory(argv[0]);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800,600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
//
glutDisplayFunc(RenderScene);
GLenum err=glewInit();
if(GLEW_OK != err) {
fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
这是错误:
我在评论的行尾显示了错误。