【循序渐进学图形学之】OpenGL安装glew扩展库

我在运行《OpenGL编程指南(第六版)》中文版第142页的程序blendeqn.c时,遇到错误:

1>------ 已启动生成: 项目: blendeqn, 配置: Debug Win32 ------
1>正在编译...
1>blendeqn.cpp
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(23) : error C2065: 
“GL_FUNC_ADD”: 未声明的标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(23) : error C3861: 
“glBlendEquation”: 找不到标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(26) : error C2065: 
“GL_FUNC_SUBTRUCT”: 未声明的标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(26) : error C3861: 
“glBlendEquation”: 找不到标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(29) : error C2065: 
“GL_FUNC_REVERSE_SUBTRUCT”: 未声明的标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(29) : error C3861: 
“glBlendEquation”: 找不到标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(32) : error C2065: 
“GL_FUNC_MIN”: 未声明的标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(32) : error C3861: 
“glBlendEquation”: 找不到标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(35) : error C2065: 
“GL_FUNC_MAX”: 未声明的标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(35) : error C2143: 语法错
误 : 缺少“)”(在“;”的前面)
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(35) : error C3861: 
“glBlendEquation”: 找不到标识符
1>e:\学习\程序练习\opengl\blendeqn\blendeqn\blendeqn.cpp(38) : error C3861: 
“exit”: 找不到标识符
1>生成日志保存在“file://e:\学习\程序练习\OpenGL\blendeqn\blendeqn\Debug
\BuildLog.htm”
1>blendeqn - 12 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========


出错原因是:glBlendEquation是OpenGL扩展部分的函数。解决方法是安装OpenGL的glew扩展库。

我的编译环境:VS2008。

首先下载glew库:http://glew.sourceforge.net/

然后进行安装:

拷贝glew32.dll至system32文件夹下,拷贝glew32.lib至VC目录下lib文件夹,拷贝glew.h和wglew.h至VC目录下include/GL目录下。

在程序开始要导入头文件:#include <GL/glew.h>。

其次还要导入库文件glew32.lib:


初始化glew:

可以在init函数开始处初始化:

glewInit();

还可以加入错误处理代码。

编译运行,成功。

完整代码:

#include <GL/glew.h> #include <GL/glut.h> #include <stdlib.h> void init() { glewInit(); glClearColor(1.0,1.0,0.0,0.0); glBlendFunc(GL_ONE,GL_ONE); glEnable(GL_BLEND); } void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,0.0,1.0); glRectf(-0.5,-0.5,0.5,0.5); glFlush(); } void keyboard(unsigned char key,int x,int y) { switch(key) { case 'a':case 'A': glBlendEquation(GL_FUNC_ADD); break; case 's':case 'S': glBlendEquation(GL_FUNC_SUBTRACT); break; case 'r':case 'R': glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); break; case 'm':case 'M': glBlendEquation(GL_MIN); break; case 'x':case 'X': glBlendEquation(GL_MAX); break; case 27: exit(0); break; } glutPostRedisplay(); } int main(int argc,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }
运行结果:


转载于:https://www.cnblogs.com/xiajun/archive/2011/11/05/2298633.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值