I’ve recently started learning OpenGl through the SuperBible fifth edition, unfortunately got stuck right at the first example they provide.
Here’s the code:
#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;
}
Here is the errors:
I showed errors at end of the lines in comments.
Well the errors now are due to the fact that you have not linked to the glew library. Find glew.lib (if you downloaded a binary distribution it should have come with the headers). Edit the properties for the project, select the linker options, and add an additional library directory. Add the location of the glew lib (should be called glew32.lib or similiar). Then in expand the linker tab, and select input, and at the end of additional dependencies add the name of the lib file including extension.