OpenGL立方体地图总是黑色的

使用立方体贴图纹理创建和渲染天空盒时,天空盒是黑色的。

以下是我如何创建立方体贴图纹理:

GLuint loadCubemap(std::vector<std::string> faces) { GLuint textureID; glGenTextures(1, &textureID); glActiveTexture(GL_TEXTURE0); int width,height; unsigned char* image; glBindTexture(GL_TEXTURE_CUBE_MAP, textureID); for(GLuint i = 0; i < faces.size(); i++) { image = SOIL_load_image(faces[i].c_str(), &width, &height, 0, SOIL_LOAD_RGBA); glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image ); } glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_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); glBindTexture(GL_TEXTURE_CUBE_MAP, 0); return textureID; } 

以下是我如何绘制立方体贴图:

 void Skybox::update() { //the sky box should be in the background glDepthMask(GL_FALSE); //set the position of the skybox around the camera pos = Camera::getCurrentlyBound()->getPos(); //faces of the cube map std::vector<std::string> faces = { "/home/a/Programming/GameEngine/Game/Assets/skybox_px.png", //+x "/home/a/Programming/GameEngine/Game/Assets/skybox_nx.png", //-x "/home/a/Programming/GameEngine/Game/Assets/skybox_py.png", //+y "/home/a/Programming/GameEngine/Game/Assets/skybox_ny.png", //-y "/home/a/Programming/GameEngine/Game/Assets/skybox_pz.png", //+z "/home/a/Programming/GameEngine/Game/Assets/skybox_nz.png", //-z }; //create the texture object GLuint cubeMap = loadCubemap(faces); //set up some matrices glm::mat4 modelMatrix = glm::translate(glm::mat4(), pos)*glm::mat4_cast(orien); glm::mat4 mvpMatrix = Camera::getCurrentlyBound()->getVP()*modelMatrix; //you can ignore this part Program* prog = ProgramManager::getProgram(msh.getProgramPath()); //bind the program prog->bind(); //set uniform data prog->setUniformData(mvpMatrix, "MVP"); //bind the VAO msh.bind(); //bind the cube map texture glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMap); glDrawElements(GL_TRIANGLES, msh.getNumVerts(), GL_UNSIGNED_INT, 0); //draw msh.unbind(); //unbind the VAO prog->unbind(); glDepthMask(GL_TRUE); } 

这里是着色器:

顶点着色器:

 #version 330 core in vec3 pos; uniform mat4 MVP; out vec3 fragTexVector; void main() { gl_Position = MVP*vec4(pos, 1); fragTexVector = pos; } 

片段着色器:

 #version 330 core out vec4 finalColor; in vec3 fragTexVector; uniform samplerCube skybox; void main() { //finalColor = vec4(1,1,1,1); finalColor = texture(skybox, fragTexVector); } 

我已经扫描了这段代码,并在我的整个项目上多次查找错误,找不到任何东西。 samplerCube似乎总是得到黑色像素。

额外的信息(可能是有帮助的,我不确定):

我已经尝试用VOGL(Valve的opengldebugging器)debugging程序,但是当我尝试捕获一个帧的快照时,它崩溃了一个错误:

 Internal error: KTX texture failed internal consistency check, texture 7 target GL_TEXTURE_CUBE_MAP. This should not happen! 

我对OpenGL很新,如果有OpenGL经验的人可以帮我解决问题,将不胜感激。

谢谢。

事实certificate,立方体贴图纹理必须是正方形,否则OpenGL将会中断,而且由于某种原因,当我这样做的时候,它不会抛出错误,所以我不知道这是否是SOIL错误或OpenGL错误…

编辑:我用一个不同的库来加载纹理,看起来纹理仍然是黑色时,它不是完全正方形。