2
\$\begingroup\$

I implemented a skybox into my program using a tutorial, and using the provided 6 textures from that tutorial to make a cube map texture, my skybox looked fine. However, ever since then every other skybox texture set I have tried to add has had issues with the edges not blending together. Here is generally how they always end up looking:

enter image description here

here is my code for for loading the textures and the parameters:

glActiveTexture(GL_TEXTURE0);
textureID = SOIL_load_OGL_cubemap(textures[0], textures[1], textures[2], textures[3], textures[4], textures[5], 0, 0, SOIL_LOAD_RGB);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
if (textureID == 0)
{
    glGenTextures(1, &textureID);

    int width, height;
    unsigned char* image;

    glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
    for (GLuint i = 0; i < 6; i++)
    {
        GLuint sID = SOIL_load_OGL_texture(textures[i], 0, 0, 0);
        image = SOIL_load_image(textures[i], &width, &height, 0, SOIL_LOAD_RGB);
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
        SOIL_free_image_data(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);

And code for rendering the skybox:

glDepthMask(GL_FALSE);
shader->bind();
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
viewMatrix.r4.x = 0;
viewMatrix.r4.y = 0;
viewMatrix.r4.z = 0;
shader->loadMatrix("viewMatrix", &viewMatrix.m11);
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
shader->unbind();
glDepthMask(GL_TRUE);

And the shader code

const char vertexShader[] =
    "#version 330\r\n"
    "in vec3 position;\r\n;"
    "out vec3 texCoord;\r\n"
    "uniform mat4 projectionMatrix;\r\n"
    "uniform mat4 viewMatrix;\r\n"
    "void main()\r\n"
    "{\r\n"
    "gl_Position = projectionMatrix * viewMatrix * vec4(position, 1);\r\n"
    "texCoord = position;\r\n"
    "}";


const char fragmentShader[] =
    "#version 330\r\n"
    "in vec3 texCoord;\r\n"
    "out vec4 color;\r\n"
    "uniform samplerCube sampler;\r\n"
    "void main()\r\n"
    "{\r\n"
    "color = texture(sampler, texCoord);\r\n"
    "}";

Does anyone see something that I might be missing that's causing my skybox to not render properly for most cube maps?

\$\endgroup\$
1
  • \$\begingroup\$ Try to rotate the images \$\endgroup\$
    – tkausl
    Nov 10 '16 at 14:11
1
\$\begingroup\$

The solution for me was to re-order the right/left/front/back from the images I was getting online to different combinations in order to get it to look properly when rendering.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .