gpt4 book ai didi

c++ - OpenGL GLut 编译问题

转载 作者:太空狗 更新时间:2023-10-29 20:18:04 60 4
gpt4 key购买 nike

嗨,我正在做一个 openGL 项目,但在下载并安装过剩库文件后,它仍然无法编译,我得到 12 错误 C3861:找不到标识符,任何帮助都将是很好的

#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);
}

我的错误是

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

glut32.dll 文件在我的 system32 文件夹中

我的 glut.h 文件在 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include

我的 glut.lib 文件位于 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib

更新添加,现在我有这些错误

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 referenced 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)

最佳答案

此问题是由错误的 .lib 链接引起的。

在项目的属性中,选择:配置属性 -> 链接器 -> 输入

在右栏中选择:附加依赖项,将以下库添加到列表中,以分号分隔:opengl32.lib ; glut32.lib ; glu32.lib ;

这将解决问题。

关于c++ - OpenGL GLut 编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5365441/

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com