windows下编译与使用glew的静态库

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/toothing/article/details/80881137

1、源码获取
1、需要下载官网打好的zip源码包,github clone下来的不能用

1、静态库版本
1、编译
1、打开vs工程进行编译:
1、需要将release版本的/MT改为/MD,否则会出现:
MSVCRT.lib(MSVCR120.dll) : error LNK2005: free 已经在 LIBCMT.lib(free.obj) 中定义

LINK : warning LNK4098: 默认库“MSVCRT”与其他库的使用冲突;请使用 /NODEFAULTLIB:library
2、或者,添加[ /NODEFAULTLIB:library]进行编译也可以【未验证】
2、cmake工程进行编译:
1、需要将输出文件名glew32、glew32d分别改为glew32s、glew32sd,以区分静态库跟动态库
2、需要给glewinfo、visualinfo工程添加GLEW_STATIC预编译宏,以保证链接的是静态库
3、glewinfo、visualinfo工程:链接库需要改为相应的静态库;工程依赖项需要修改为相应的静态库工程
2、使用
1、需要给相应工程添加GLEW_STATIC预编译宏,否则会出现:
error LNK2019: 无法解析的外部符号 __imp_glewInit,该符号在函数 main 中被引用

cmake添加预编译宏:
1、ADD_DEFINITIONS( -DGLEW_STATIC )

参考:
1、http://glew.sourceforge.net/install.html

展开阅读全文

glew使用问题

10-31

我在网上下了glew库来先个实验一下OpenGL编程指南上三维纹理那节的一个例子,源代码编译链接都没有问题,但是运行到init函数中glTexImage3D这个函数的时候就会弹出一个对话框,显示内存引用错误...rn还有在看glew的那个installation文档的时候,里面有一句“need to change the GLEW_BUILD preprocessor constant to GLEW_STATIC when building a static library or executable, otherwise you get build errors.”什么意思啊?是写改变宏定义么?rn例子代码如下:rn#include rn#include rn#include rn#include rnrn#ifdef GL_VERSION_1_2rn#define iWidth 16rn#define iHeight 16rn#define iDepth 16rnrnstatic GLubyte image[iDepth][iHeight][iWidth][3];rnstatic GLuint texName;rnrn/* Create a 16x16x16x3 array with different color values inrn* each array element [r, g, b]. Values range from 0 to 255.rn*/rnrnvoid makeImage(void)rnrn int s, t, r;rn rn for (s = 0; s < 16; s++)rn for (t = 0; t < 16; t++)rn for (r = 0; r < 16; r++) rn image[r][t][s][0] = (GLubyte) (s * 17);rn image[r][t][s][1] = (GLubyte) (t * 17);rn image[r][t][s][2] = (GLubyte) (r * 17);rn rnrnrnvoid init(void)rn rn glClearColor (0.0, 0.0, 0.0, 0.0);rn glShadeModel(GL_FLAT);rn glEnable(GL_DEPTH_TEST);rn rn makeImage();rn glPixelStorei(GL_UNPACK_ALIGNMENT, 1);rn rn glGenTextures(1, &texName);rn glBindTexture(GL_TEXTURE_3D, texName);rn glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);rn glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);rn glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);rn glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, rn GL_NEAREST);rn glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, rn GL_NEAREST);rn glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, iWidth, iHeight,rn iDepth, 0, GL_RGB, GL_UNSIGNED_BYTE, image);rn glEnable(GL_TEXTURE_3D);rnrnrnvoid display(void)rnrn glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);rn glBegin(GL_QUADS);rn glTexCoord3f(0.0, 0.0, 0.0); glVertex3f(-2.25, -1.0, 0.0);rn glTexCoord3f(0.0, 1.0, 0.0); glVertex3f(-2.25, 1.0, 0.0);rn glTexCoord3f(1.0, 1.0, 1.0); glVertex3f(-0.25, 1.0, 0.0);rn glTexCoord3f(1.0, 0.0, 1.0); glVertex3f(-0.25, -1.0, 0.0);rn rn glTexCoord3f(0.0, 0.0, 1.0); glVertex3f(0.25, -1.0, 0.0);rn glTexCoord3f(0.0, 1.0, 1.0); glVertex3f(0.25, 1.0, 0.0);rn glTexCoord3f(1.0, 1.0, 0.0); glVertex3f(2.25, 1.0, 0.0);rn glTexCoord3f(1.0, 0.0, 0.0); glVertex3f(2.25, -1.0, 0.0);rn glEnd();rn glFlush();rnrnrnvoid reshape(int w, int h)rnrn glViewport(0, 0, (GLsizei) w, (GLsizei) h);rn glMatrixMode(GL_PROJECTION);rn glLoadIdentity();rn gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);rn glMatrixMode(GL_MODELVIEW);rn glLoadIdentity();rn glTranslatef(0.0, 0.0, -4.0);rnrnrnvoid keyboard(unsigned char key, int x, int y)rnrn switch (key) rn case 27:rn exit(0);rn break;rn rnrnrnint main(int argc, char** argv)rnrn glutInit(&argc, argv);rn glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);rn glutInitWindowSize(250, 250);rn glutInitWindowPosition(100, 100);rn glutCreateWindow(argv[0]);rn init();rn glutReshapeFunc(reshape);rn glutDisplayFunc(display);rn glutKeyboardFunc (keyboard);rn glutMainLoop();rn return 0; rnrn#elsernint main(int argc, char** argv)rnrn fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0 or 1.1.\n");rn fprintf (stderr, "If your implementation of OpenGL has the right extensions,\n");rn fprintf (stderr, "you may be able to modify this program to make it run.\n");rn return 0;rnrn#endif 论坛

没有更多推荐了,返回首页