I’m using windows 7 ultimate 64 bit version, and visual C++ 2010 with Freeglut to do my works, before I use the GLEW, there was no problem.
However, when I need to create buffer, I need to use library. I searched in the Internet, those people said that GLEW is a easy way to go, so I decided to use GLEW.
But after I added the library, VC++2010 still cannot compile my work.
I added glew32.dll, glew32mx.dll to my system32 and sysWOW64,
glew.h, gxlew.h and wglew.h to VC/include/GL,
and glew32.lib, glew32mx.lib, glew32msx.lib, glew32s.lib to VC/lib.
The version of glew i used is 32 bit version 1.7.0. I linked the lib in my project properties, additional dependencies, glew.lib.
Here is the source code:
#define GLEW_STATIC
#include <windows.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#define BUFFER_OFFSET(bytes) ((GLubyte*) NULL + (bytes))
const int NumVAOs = 1;
GLuint VAO[NumVAOs];
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAO[0]);
glDrawArrays(GL_QUADS, 0, 4);
glutSwapBuffers();
}
void reshape(int w,int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void init(void)
{
enum { Vertices, Colors, NumVBOs };
GLuint buffers[NumVBOs];
{
GLfloat verts[][3] = {
{-40.0, 40.0, 1.0},
{-40.0, -40.0, 1.0},
{40.0, -40.0, 1.0},
{40.0, 40.0, 1.0},
};
GLfloat colors[][3] = {
{1.0, 0.0, 0.0},
{0.0, 1.0, 0.0},
{0.0, 0.0, 1.0},
{1.0, 1.0, 1.0},
};
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glGenVertexArrays(NumVAOs, VAO);
glGenBuffers(GL_ARRAY_BUFFER, buffers);
glBindBuffer(GL_ARRAY_BUFFER, buffers[Vertices]);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, buffers[Colors]);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
glColorPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);
}
}
int main(int argc, char **argv)
{
glewInit();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
And Here is the build output:
1>------ Build started: Project: OpenGLTest, Configuration: Debug Win32 ------
1>main.obj : error LNK2001: unresolved external symbol ___glewBindVertexArray
1>main.obj : error LNK2001: unresolved external symbol ___glewBufferData
1>main.obj : error LNK2001: unresolved external symbol ___glewBindBuffer
1>main.obj : error LNK2001: unresolved external symbol ___glewGenBuffers
1>main.obj : error LNK2001: unresolved external symbol ___glewGenVertexArrays
1>Q:\Users\Chi\Documents\Visual Studio 2010\Projects\OpenGLTest\Debug\OpenGLTest.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help me, I try to fix it for 2 days, but I still cannot get it fixed… Thanks so much.