freeglut.ext中的函数不能调用的问题

_子宽 _子宽 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
参考《OPENGL编程宝典》第八版,第一章的实例,我去掉着色器部分后敲入电脑,如下:
#include<iostream>
#include<gl/glew.h>
#define GLUT_DISABLE_ATEXIT_HACK
#include<gl/glut.h>
#include<gl/freeglut_ext.h>
#include<gl/freeglut.h>

#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "freeglut_static.lib")
#pragma comment(lib, "freeglut.lib")
#pragma comment(lib, "glew32.lib")

using namespace std;

GLuint VAOs[1];
GLuint Buffers[1];

void init()
{
glGenVertexArrays(0, VAOs);
glBindVertexArray(VAOs[0]);

GLfloat vertices[6][2] = {
{-0.90, -0.90},
{ 0.85, -0.90},
{-0.90, 0.85},
{ 0.90, -0.85},
{ 0.90, 0.90},
{-0.85, 0.90},
};

glGenBuffers(1, Buffers);
glBindBuffer(GL_ARRAY_BUFFER,Buffers[0]);
glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);

glBindVertexArray(0);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);

glBindVertexArray(VAOs[0]);
glDrawArrays(GL_TRIANGLES, 0, 6);
glFlush();

glBindVertexArray(0);
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(512,512);
glutInitContextVersion(4,3);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutCreateWindow(argv[0]);

if(glewInit()){
cerr<<"Unable to initialize GLEW..."<<endl;
exit(EXIT_FAILURE);
}

init();
glutDisplayFunc(display);

glutMainLoop();

}


因为遇到了freeglut库的链接问题,所以代码前加了
#define GLUT_DISABLE_ATEXIT_HACK

以及
#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "freeglut_static.lib")
#pragma comment(lib, "freeglut.lib")
#pragma comment(lib, "glew32.lib")

但是即使这样,还是无法链接到freeglut_ext.h头文件里面的函数,报错如下:
1>Source.obj : error LNK2019: 无法解析的外部符号 __imp__glutInitContextVersion@8,该符号在函数 _main 中被引用
1>Source.obj : error LNK2019: 无法解析的外部符号 __imp__glutInitContextProfile@4,该符号在函数 _main 中被引用
1>E:\Project\VS\tem\Debug\tem.exe : fatal error LNK1120: 2 个无法解析的外部命令

我又试了一下freeeglut_ext.h下的其他函数,都是同样的错误。

freeglut库使用的3.0.0,配置应该没有问题,lib、dll和头文件都放好了。

哪位大侠能给点提示、 、不胜感激T^T
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
_子宽
非技术区 15,446 成员 58,111 内容