OpenGL CubeMapping黑色纹理
OpenGL CubeMapping black texture
所以我试图得到一个立方体地图在openGL工作,但不断提出黑色纹理。我希望其他人能指出我的错误。模型确实出现了,我可以在片段着色器中改变它的颜色。但是当我尝试使用纹理时,它看起来是黑色的,好像它没有绑定。
bool result = true;
result &= shader.loadFromFile("Assets\Shader\skybox.vert", "Assets\Shader\skyBox.Frag");
result &= shader.compileShader();
result &= shader.linkShader();
result &= shader.validate();
if (!result){
printf("ShaderFail");
}
shader.use();
glm::mat4 model = glm::mat4(1.0);
glm::mat4 rotationMatrix = glm::mat4_cast(glm::quat(glm::vec3(0, 0, 0)));
glm::mat4 translationMatrix = glm::translate(glm::vec3(10, 10, 0));
glm::mat4 scaleMatrix = glm::scale(glm::vec3(1, 1, 1));
model = rotationMatrix * translationMatrix * scaleMatrix;
shader.setUniform("M", model);
cube2 = new VBOCube();
Bitmap bmp1 = Bitmap::bitmapFromFile("Assets\Images\TowerHousepano_r.jpg");
Bitmap bmp2 = Bitmap::bitmapFromFile("Assets\Images\TowerHousepano_l.jpg");
Bitmap bmp3 = Bitmap::bitmapFromFile("Assets\Images\TowerHousepano_u.jpg");
Bitmap bmp4 = Bitmap::bitmapFromFile("Assets\Images\TowerHousepano_d.jpg");
Bitmap bmp5 = Bitmap::bitmapFromFile("Assets\Images\TowerHousepano_f.jpg");
Bitmap bmp6 = Bitmap::bitmapFromFile("Assets\Images\TowerHousepano_b.jpg");
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
/// Applies the images to each side of the map.
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, bmp1.width(), bmp1.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, bmp1.pixelBuffer());
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, bmp2.width(), bmp2.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, bmp2.pixelBuffer());
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, bmp3.width(), bmp3.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, bmp3.pixelBuffer());
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, bmp4.width(), bmp4.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, bmp4.pixelBuffer());
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, bmp5.width(), bmp5.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, bmp5.pixelBuffer());
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, bmp6.width(), bmp6.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, bmp6.pixelBuffer());
/// Applies CLAMPING and sets bilinear texture filtering.
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);
void Skybox::render(Camera& camera){
glEnable(GL_DEPTH_TEST);
shader.use();
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
shader.setUniform("V", camera.view());
shader.setUniform("P", camera.projection());
cube2->render();
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
glDisable(GL_DEPTH_TEST);
}
顶点着色器:
#version 400
layout (location = 0) in vec3 vp;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
out vec3 texcoords;
void main () {
texcoords = vp;
gl_Position = P * V* M * vec4 (vp, 1.0);
}
片段着色器:
#version 400
in vec3 texcoords;
uniform samplerCube cubeTexture;
out vec4 FragColour;
void main () {
vec4 cubeMapColour = texture (cubeTexture, texcoords);
FragColour = cubeMapColour;
}
当我正在查看我自己的帖子时,我发现了这个问题。
我使用GL_TEXTURE_CUBE_MAP_POSITIVE_Y
两次,而不是GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,它现在工作。
相关文章:
- 为什么我会得到黑色纹理?
- 黑色纹理,如果图片大小在第二个 OpenGL 线程中> 1 * 1
- 纹理显示为黑色
- 现代OpenGL 3.3核心黑色纹理
- 带有Clang的DirectX11显示黑色纹理(与Visual Studio配合使用)
- Direct3D11:在设备之间共享纹理:黑色纹理
- 使用着色器渲染时,OpenGL纹理都是黑色的
- 片段着色器中的 OpenGL 纹理黑色
- opengl-黑色纹理,如何在缓冲区上使用glm::vec*
- GLSL 150 GL 3.2黑色纹理
- GLSL纹理功能仅返回黑色的天空盒
- 从libpng加载的png纹理在OpenGL中显示为黑色
- OpenGL 3.3不会渲染任何纹理(黑色纹理、C++、GLFW/SOIL)
- OpenGL3两组着色器,纹理显示为黑色
- GLSL 将纹理渲染为黑色和蓝色
- OpenGL 3.30/GLSL 3.30-MRT输出黑色纹理
- SDL_CreateRGBSurface使用OpenGL纹理产生黑色纹理
- OpenGL CubeMapping黑色纹理
- OpenGL中纹理的采样是黑色的
- OpenGL纹理在3.3中都是黑色的-但在3.1中工作