OpenGL GLut compiling issues
hi im doing an openGL project but after downloading and installing the glut library files it still wont compile and i get 12 error C3861: identifier not found, any help would be great
#include <windows.h>
#include <gl/gl.h>
void init(void);
void display(void);
void keyboard(unsigned char, int, int);
void resize(int, int);
int is_depth;
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(40, 40);
glutCreateWindow("3D World");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(resize);
glutMainLoop();
return 0;
}
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
is_depth = 1;
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
if (is_depth)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
else
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(0.2f, 0.2f, 0.2f);
glVertex3f(-100.0, 0.0, -100.0);
glColor3f(0.4f, 0.4f, 0.4f);
glVertex3f(-100.0, 0.0, 100.0);
glColor3f(0.6f, 0.6f, 0.6f);
glVertex3f(100.0, 0.0, 100.0);
glColor3f(0.8f, 0.8f, 0.8f);
glVertex3f(100.0, 0.0, -100.0);
glEnd();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 'a':
glTranslatef(5.0, 0.0, 0.0);
break;
case 'd':
glTranslatef(-5.0, 0.0, 0.0);
break;
case 's':
glTranslatef(0.0, 0.0, -5.0);
break;
case 'w':
glTranslatef(0.0, 0.0, 5.0);
break;
}
display();
}
void resize(int width, int height)
{
if(height == 0) height = 1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, width / height, 1.0, 400.0);
glTranslatef(0.0, -5.0, -150.0);
glMatrixMode(GL_MODELVIEW);
}
and my errors are
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(17) : error C3861: 'glutInit': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(18) : error C2065: 'GLUT_DOUBLE' : undeclared identifier
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(18) : error C2065: 'GLUT_RGB' : undeclared identifier
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(18) : error C3861: 'glutInitDisplayMode': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(19) : error C3861: 'glutInitWindowSize': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(20) : error C3861: 'glutInitWindowPosition': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(21) : error C3861: 'glutCreateWindow': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(23) : error C3861: 'glutDisplayFunc': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(24) : error C3861: 'glutKeyboardFunc': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(25) : error C3861: 'glutReshapeFunc': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(27) : error C3861: 'glutMainLoop': identifier not found
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(97) : error C3861: 'gluPerspective': identifier not found
the glut32.dll file is in my system32 folder
my glut.h file is in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include
and my glut.lib file is in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib
UPDATE added and now i have these errors
error LNK2019: unresolved external symbol _glutMainLoop@0 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutReshapeFunc@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutKeyboardFunc@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutDisplayFunc@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutCreateWindow@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutInitWindowPosition@8 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutInitWindowSize@8 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutInitDisplayMode@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutInit@8 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 ref开发者_运维技巧erenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function "void __cdecl keyboard(unsigned char,int,int)" (?keyboard@@YAXEHH@Z)
1>openGL.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function "void __cdecl resize(int,int)" (?resize@@YAXHH@Z)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "void __cdecl resize(int,int)" (?resize@@YAXHH@Z)
This problem resulted from wrong .lib linking.
In Project's properites, choose: Configuration properties -> linker -> input
in the right column choose: additional dependencies, add following libraries to the list, seperated by semi colon: opengl32.lib ; glut32.lib ; glu32.lib ;
This will solve the problem.
Only use #include <glut.h>
GLUT contains all the gl.h functions anyway. just make sure that in the project settings you set all the dependancies for glut32.lib, openGL32.lib etc.
You include gl.h, but since you are using GLUT, which is not included in OpenGL proper, you also need to #include <glut.h>
.
i created a video on how to set up glfw. it was 20 minutes of pain, but finally got it to work. http://www.youtube.com/watch?v=dpsC4kP2ME0 visual studio 2010 seems to be very sensitive to configuration, make sure configuration is set to "all configurations".
精彩评论