c++opengltexturesskybox

OpenGL: Render skybox cubmap issue


I am creating a Sky box with a cube map so I used this site to generate the sides of the cube map Sky box generator, now I have 6 512 png files, I used the following code to render it:

glGenTextures(1, &cubemapTexture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
for (GLuint i = 0; i < images.size(); i++) {
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, images[i].width, images[i].height, 0, GL_RGB, GL_UNSIGNED_BYTE, images[i].data);
}
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);

the code was working fine with different images but those images that are downloaded from this site give me the following result

enter image description here

this is a sample of the image used not working:

Sample tha is not working

this is a sample of the worked images:

enter image description here


Solution

  • It seems that PNG files contain alpha channel, so you should use GL_RGBA in your glTexImage2D call like this:

    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, images[i].width, images[i].height, 0, GL_RGBA , GL_UNSIGNED_BYTE, images[i].data);