Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: when i'm using opengl glsl to implement skybox, getting something wrong.

  1. #1
    Newbie Newbie
    Join Date
    May 2013
    Posts
    2

    when i'm using opengl glsl to implement skybox, getting something wrong.

    I'm currently using glsl to draw a skybox, but final result of my program is not my expect, the six sides of the skybox looks like all sides flipped vertically, then flipped vertically. If I make the six image (right.bmp, left.bmp, top.bmp, and so on) vertical and vertical manually in some image editor, the skybox works fine. To locate the problem within my program quickly, I just simplify my program to draw only one side, front side.

    here is the relevant code :



    vertics shader:

    attribute vec3 VertexPosition;
    varying vec3 ReflectDir;

    void main()
    {
    ReflectDir = VertexPosition;

    gl_Position = gl_ModelViewProjectionMatrix * vec4(VertexPosition,1.0);
    }

    fragment shader:

    varying vec3 ReflectDir;
    uniform samplerCube CubeMapTex;

    void main() {
    vec4 cubeMapColor = texture(CubeMapTex,ReflectDir );

    gl_FragColor= cubeMapColor;
    }



    Some code within my opengl program:

    This used for binding my cube map into shader.

    glActiveTexture(GL_TEXTURE5);

    GLuint texID;
    glGenTextures(1, &texID);
    glBindTexture(GL_TEXTURE_CUBE_MAP, texID);

    GLuint targets[] = {
    GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
    GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
    GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
    };

    const char* baseFileName[] = {
    "Right",
    "Left",
    "Top",
    "Bottom",
    "Front",
    "Back"


    };

    for( int i = 0; i < 6; i++ ) {
    string texName = string(baseFileName[i])+".bmp";

    IMAGE img;
    img.Load((char*)texName.c_str());
    img.ExpandPalette();

    glTexImage2D(targets[i], 0, GL_RGBA, img.width, img.height, 0,
    img.format, GL_UNSIGNED_BYTE, img.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);

    m_shader->compileandlink();
    m_shader->useprogram();
    m_shader->setUniform("CubeMapTex", 5);
    m_shader->unuseprogram();

    And this 's my front side vertics, it's clock-wise winding.

    float extend2 = extend*.5f;
    m_cube_v = new vertex_t[24];

    //front
    m_cube_v[0].pos[0] = -extend2;
    m_cube_v[0].pos[1] = -extend2;
    m_cube_v[0].pos[2] = extend2;

    m_cube_v[1].pos[0] = extend2;
    m_cube_v[1].pos[1] = -extend2;
    m_cube_v[1].pos[2] = extend2;

    m_cube_v[2].pos[0] = extend2;
    m_cube_v[2].pos[1] = extend2;
    m_cube_v[2].pos[2] = extend2;

    m_cube_v[3].pos[0] = -extend2;
    m_cube_v[3].pos[1] = extend2;
    m_cube_v[3].pos[2] = extend2;

    What went wrong? thank you.
    Last edited by qxsl2000; 05-06-2013 at 07:44 AM.

  2. #2
    Newbie Newbie
    Join Date
    May 2013
    Posts
    2
    here is my program screenshot that was totally fliped over.

    image link: i1345.photobucket.com/albums/p668/nimaccc/front_zps741fc377.jpg


    here is my original material:

    image link: i1345.photobucket.com/albums/p668/nimaccc/original_zps3dbccf2e.jpg

  3. #3
    Junior Member Newbie Dave Driesen's Avatar
    Join Date
    Apr 2009
    Location
    Belgium
    Posts
    7
    Hi,

    Sorry -- you probably checked this, but what is loading the image?
    (BMP files are saved upside down )

    Dave Driesen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •