我正在重写我的纹理代码的很大一部分。我希望能够指定某些内部格式:GL_RGB8I,GL_RGB8UI,GL_RGB16I,GL_RGB16UI,GL_RGB32I和GL_RGB32UI。 OpenGL 2中不存在这些令牌。
当指定这些内部格式作为glTexImage2D的参数时,纹理化失败(纹理显示为白色)。检查错误时,我得到[编辑:] 1282(“无效操作”)。我认为这意味着OpenGL仍然在为glTexImage2D使用OpenGL 2,因此调用失败了。显然,它需要使用更新的版本才能成功。枚举如GL_RGB,GL_RGBA和(奇怪的)GL_RGB32F,GL_RGBA32F按预期工作。
我配置为使用GLEW或GLee进行扩展。我可以在其他地方使用OpenGL 4调用没有问题(例如,glPatchParameteri,glBindFramebuffer等),并且有问题的枚举肯定存在。为完整起见,glGetString(GL_VERSION)返回“4.2.0”。我的问题:我可以强制使用其中一个扩展库来使用OpenGL 4.2版本吗?如果是这样,怎么样?
编辑:代码太复杂而无法发布,但这是一个使用GLee的简单,自包含的示例,它也演示了这个问题:#include <GLee5_4/GLee.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <gl/glut.h>
//For Windows
#pragma comment(lib,"GLee.lib")
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
#pragma comment(lib,"glut32.lib")
#include <stdlib.h>
#include <stdio.h>
const int screen_size[2] = {512,512};
#define TEXTURE_SIZE 64
//Choose a selection. If you see black, then texturing is working. If you see red, then the quad isn't drawing. If you see white, texturing has failed.
#define TYPE 1
void error_check(void) {
GLenum error_code = glGetError();
const GLubyte* error_string = gluErrorString(error_code);
(error_string==NULL) ? printf("%d = (unrecognized error--an extension error?)\n",error_code) : printf("%d = \"%s\"\n",error_code,error_string);
}
#if TYPE==1 //############ 8-BIT TESTS ############
inline GLenum get_type(int which) { return (which==1)? GL_RGB8: GL_RGB; } //works
#elif TYPE==2
inline GLenum get_type(int which) { return (which==1)? GL_RGBA8:GL_RGBA; } //works
#elif TYPE==3
inline GLenum get_type(int which) { return (which==1)? GL_RGB8UI: GL_RGB; } //doesn't work (invalid op)
#elif TYPE==4
inline GLenum get_type(int which) { return (which==1)? GL_RGB8I: GL_RGB; } //doesn't work (invalid op)
#elif TYPE==5
inline GLenum get_type(int which) { return (which==1)? GL_RGBA8UI:GL_RGBA; } //doesn't work (invalid op)
#elif TYPE==6
inline GLenum get_type(int which) { return (which==1)? GL_RGBA8I:GL_RGBA; } //doesn't work (invalid op)
#elif TYPE==7 //############ 16-BIT TESTS ############
inline GLenum get_type(int which) { return (which==1)? GL_RGB16: GL_RGB; } //works
#elif TYPE==8
inline GLenum get_type(int which) { return (which==1)? GL_RGBA16:GL_RGBA; } //works
#elif TYPE==9
inline GLenum get_type(int which) { return (which==1)? GL_RGB16UI: GL_RGB; } //doesn't work (invalid op)
#elif TYPE==10
inline GLenum get_type(int which) { return (which==1)? GL_RGB16I: GL_RGB; } //doesn't work (invalid op)
#elif TYPE==11
inline GLenum get_type(int which) { return (which==1)?GL_RGBA16UI:GL_RGBA; } //doesn't work (invalid op)
#elif TYPE==12
inline GLenum get_type(int which) { return (which==1)? GL_RGBA16I:GL_RGBA; } //doesn't work (invalid op)
#elif TYPE==13 //############ 32-BIT TESTS ############
inline GLenum get_type(int which) { return (which==1)? GL_RGB32: GL_RGB; } //token doesn't exist
#elif TYPE==14
inline GLenum get_type(int which) { return (which==1)? GL_RGBA32:GL_RGBA; } //token doesn't exist
#elif TYPE==15
inline GLenum get_type(int which) { return (which==1)? GL_RGB32UI: GL_RGB; } //doesn't work (invalid op)
#elif TYPE==16
inline GLenum get_type(int which) { return (which==1)? GL_RGB32I: GL_RGB; } //doesn't work (invalid op)
#elif TYPE==17
inline GLenum get_type(int which) { return (which==1)?GL_RGBA32UI:GL_RGBA; } //doesn't work (invalid op)
#elif TYPE==18
inline GLenum get_type(int which) { return (which==1)? GL_RGBA32I:GL_RGBA; } //doesn't work (invalid op)
#elif TYPE==19 //############ 32-BIT FLOAT ############
inline GLenum get_type(int which) { return (which==1)? GL_RGB32F: GL_RGB; } //works
#elif TYPE==20
inline GLenum get_type(int which) { return (which==1)? GL_RGBA32F:GL_RGBA; } //works
#endif
GLuint texture;
void create_texture(void) {
printf(" Status before texture setup: "); error_check();
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D,texture);
printf(" Status after texture created: "); error_check();
GLenum data_type = GL_UNSIGNED_BYTE;
int data_length = TEXTURE_SIZE*TEXTURE_SIZE*4; //maximum number of channels, so it will work for everything
unsigned char* data = new unsigned char[data_length];
for (int i=0;i<data_length;++i) {
data[i] = (unsigned char)(0);
};
glTexImage2D(GL_TEXTURE_2D,0,get_type(1), TEXTURE_SIZE,TEXTURE_SIZE, 0,get_type(2),data_type,data);
printf(" Status after glTexImage2D: "); error_check();
delete [] data;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
printf(" Status after texture filters defined: "); error_check();
}
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 27: //esc
exit(0);
break;
}
}
void draw(void) {
glClearColor(1.0,0.0,0.0,1.0); //in case the quad doesn't draw
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glViewport(0,0,screen_size[0],screen_size[1]);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,screen_size[0],0,screen_size[1]);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(0,0);
glTexCoord2f(2,0); glVertex2f(screen_size[0],0);
glTexCoord2f(2,2); glVertex2f(screen_size[0],screen_size[1]);
glTexCoord2f(0,2); glVertex2f(0,screen_size[1]);
glEnd();
glutSwapBuffers();
}
int main(int argc, char* argv[]) {
glutInit(&argc,argv);
glutInitWindowSize(screen_size[0],screen_size[1]);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Texture Types - Ian Mallett");
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
printf("Status after OpenGL setup: "); error_check();
create_texture();
printf("Status after texture setup: "); error_check();
glutDisplayFunc(draw);
glutIdleFunc(draw);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}