在我不使用 Optirun 之前,我无法理解为什么这段代码可以工作
//Initialize GLUT and OpenGL
void ViewPort::startVideo(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(XWIN, YWIN);
glutCreateWindow("Titolo");
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_CUBE_MAP);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//OpenGL INFO
printf("GL_VERSION: %s\n", glGetString(GL_VERSION));
printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER));
printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
shadow = new ShadowMap(256 * SHADOW_QUALITY, 256 * SHADOW_QUALITY);
}
/*...*/
ShadowMap::ShadowMap(int w, int h) {
this->h = h;
this->w = w;
shadowShader = new Shader("./basicShader.vs", "./shadowShader.fs");
// Create the cube map
glGenTextures(1, &shadowCubeID);
glBindTexture(GL_TEXTURE_CUBE_MAP, shadowCubeID);
if (int err = glGetError())
cerr << "glDebug: " << gluErrorString(err) << " shadow map" << endl;
for (unsigned int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, w, w, 0,
GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
if (int err = glGetError())
cerr << "glDebug: " << gluErrorString(err) << " shadow map" << endl;
}
//now i render to the shadowFBO
glGenFramebuffers(1, &shadowFBO);
glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
//disable read and write from color buffer
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X,
shadowCubeID, 0);
errorCheckFBO();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
}
错误(无效操作)是当我使用 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, ...) 创建立方体贴图的六个面时,我唯一能想象的是与 OpenGL 版本存在一些不兼容。
程序运行时打印的 OpenGL 信息:
GL_VERSION: 3.0 Mesa 10.1.3
GL_RENDERER: Mesa DRI Intel(R) Haswell Mobile
GL_VENDOR: Intel Open Source Technology Center
当它不起作用时:
GL_VERSION: 2.1 Mesa 10.1.3
GL_RENDERER: Gallium 0.4 on llvmpipe (LLVM 3.4, 256 bits)
GL_VENDOR: VMware, Inc.
我怎样才能绕过这个问题?(对不起我的英语不好)