关于opengl中颜色表函数glcolortable出现异常的问题(opengl红宝书8-7程序)解决方法
来源:互联网 发布:sql2005附加数据库 编辑:程序博客网 时间:2024/06/05 16:59
最近使用glcolortable()函数,运行是出现异常,网上查找也有人遇到类似问题,但是都没有给出解决方法。
#include "Glee.h" #include <GL/glut.h> #include<stdio.h> #include <stdlib.h> GLubyte pixels[64][64][3]; void init(void) { int i,j,c; GLubyte colorTable[256][3]; //pixels = readImage("leeds.bin", &width, &height); for (i = 0; i < 64; i++) { for (j = 0; j < 64; j++) { c = ((((i&0x8)==0)||((j&0x8))==0))*255; pixels[i][j][0] = (GLubyte) c; pixels[i][j][1] = (GLubyte) c; pixels[i][j][2] = (GLubyte) c; } } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glClearColor(0.0, 0.0, 0.0, 0.0); /* Set up an inverse color table */ for ( i = 0; i < 256; ++i ) { colorTable[i][0] = 255 - i; colorTable[i][1] = 255 - i; colorTable[i][2] = 255 - i; } glColorTable(GL_COLOR_TABLE, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE,colorTable);// 出错位置 glEnable(GL_COLOR_TABLE); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glRasterPos2i( 1, 1 ); glDrawPixels(64, 64, GL_RGB, GL_UNSIGNED_BYTE, pixels ); glFlush(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho (0, w, 0, h, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(640, 480); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutMainLoop(); return 0; }
在实验了各种方法都没解决问题。
红宝书中230页有样一句段话:
尽管图像处理自己一直是一个OpenGL扩展,但其功能在OpenGL 3.0中废弃了,并且从OpenGL3.1规范中删除了。
开始怀疑是opengl版本问题。于是测试版本
const char* verstr = (const char*)glGetString( GL_VERSION );
出错机器是opengl 2.1,没有错误的机器是opengl3.1版本。
同样glGenvertexArrays在2.1版本中也出错,在3.1版本中没有问题。也有人这么解决
http://blog.csdn.net/niexiao2008/article/details/8898171
,在glewInit()在添加
glewExperimental = GL_TRUE;
但我在2.1版本中测试没有通过。
出错机器的版本号2.1.0-Build 8.15.10.1840 没有错误的版本号3.1 NVIDIA 188.98,所以应该显卡对opengl版本支持不一样的。
主要原因见:
http://blog.csdn.net/zhouschina/article/details/8960309
- 关于opengl中颜色表函数glcolortable出现异常的问题(opengl红宝书8-7程序)解决方法
- opengl红宝书 第8章的代码中readImage()的简单解决方法(Intel 处理器上)
- 《高效学习OpenGL》 之 颜色表 glColorTable(),glColorTableParameter(),glCopyColorTable()
- 揭秘OpenGL红宝书中棋盘生成程序
- opengl红宝书第11章, gluTessCallback函数的例子在vs.net编译不过的解决方法
- OpenGL 红宝书
- opengl红宝书关于name stack操作两个函数glLoadName,glPushName的用法区别
- 关于在vs2013中配置opengl红宝书第八版环境
- 关于在vs2013中配置opengl红宝书第八版环境
- OpenGL编程指南(OpenGL红宝书)
- opengl的测试程序出现的问题
- openGL 中 glColor3f()函数 颜色设定
- 【OpenGL】关于OpenGL中Bind函数的理解
- 【OpenGL】关于OpenGL中glBindTexture函数的理解
- OpenGL红宝书附带源码编译问题集锦
- [OpenGL红宝书]第一章 OpenGL概述
- 再读OpenGL红宝书(1-8章)
- 再读OpenGL红宝书(1-8章)【续】
- ok6410学习笔记(4.ioctl字符驱动)
- 今天遇到一个问题,很纠结include(authenticate.php): failed to open stream: No such file or directory
- Defunct进程 僵尸进程
- SQLite学习笔记之一
- 软件开发是瓜熟蒂落,不能强迫
- 关于opengl中颜色表函数glcolortable出现异常的问题(opengl红宝书8-7程序)解决方法
- solaris 起图形 和操作系统版本有关系
- js基本概念的了解
- DTD文档
- java泛型(泛形)
- 设计模式读书笔记-----装饰者模式
- Android的android.mk
- 直接拿来用!最火的Android开源项目
- python 类机制的几个注意点