Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Skybox

  1. #1
    Intern Newbie
    Join Date
    Jul 2013
    Posts
    35

    Skybox

    I drew a standard textured cube like so:

    glBindTexture(GL_TEXTURE_2D, top);
    glBegin(GL_QUADS);
    //glNormal3f(0.0f, 1.0f, 0.0f);
    glTexCoord2d(1.0f, 0.0f); glVertex3f( width, height, -length); // Top Right Of The Quad (Top)
    glTexCoord2d(1.0f, 1.0f); glVertex3f(-width, height, -length); // Top Left Of The Quad (Top)
    glTexCoord2d(0.0, 1.0f); glVertex3f(-width, height, length); // Bottom Left Of The Quad (Top)
    glTexCoord2d(0.0, 0.0f); glVertex3f( width, height, length); // Bottom Right Of The Quad (Top)
    glEnd();

    glBindTexture(GL_TEXTURE_2D, front);
    glBegin(GL_QUADS);
    //glNormal3f(0.0f, 0.0f, -1.0f);
    glTexCoord2d(0.0f, 0.0f); glVertex3f( width, height, length); // Top Right Of The Quad (Front)
    glTexCoord2d(1.0f, 0.0f); glVertex3f(-width, height, length); // Top Left Of The Quad (Front)
    glTexCoord2d(1.0f, 1.0f); glVertex3f(-width, -height, length); // Bottom Left Of The Quad (Front)
    glTexCoord2d(0.0f, 1.0f); glVertex3f( width, -height, length); // Bottom Right Of The Quad (Front)
    glEnd();

    glBindTexture(GL_TEXTURE_2D, back);
    glBegin(GL_QUADS);
    //glNormal3f(0.0f, 0.0f, 1.0f);
    glTexCoord2d(0.0f, 1.0f); glVertex3f( width, -height, -length); // Bottom Left Of The Quad (Back)
    glTexCoord2d(1.0f, 1.0f); glVertex3f(-width, -height, -length); // Bottom Right Of The Quad (Back)
    glTexCoord2d(1.0f, 0.0f); glVertex3f(-width, height, -length); // Top Right Of The Quad (Back)
    glTexCoord2d(0.0f, 0.0f); glVertex3f( width, height, -length); // Top Left Of The Quad (Back)
    glEnd();

    glBindTexture(GL_TEXTURE_2D, left);
    glBegin(GL_QUADS);
    //glNormal3f(-1.0f, 0.0f, 0.0f);
    glTexCoord2d(1.0f, 0.0f); glVertex3f(-width, height, -length); // Top Right Of The Quad (Left)
    glTexCoord2d(1.0f, 1.0f); glVertex3f(-width, -height, -length); // Top Left Of The Quad (Left)
    glTexCoord2d(0.0f, 1.0f); glVertex3f(-width, -height, length); // Bottom Left Of The Quad (Left)
    glTexCoord2d(0.0f, 0.0f); glVertex3f(-width, height, length); // Bottom Right Of The Quad (Left)
    glEnd();

    glBindTexture(GL_TEXTURE_2D, right);
    glBegin(GL_QUADS);
    //glNormal3f(1.0f, 0.0f, 0.0f);
    glTexCoord2d(0.0f, 0.0f); glVertex3f( width, height, -length); // Top Right Of The Quad (Right)
    glTexCoord2d(1.0f, 0.0f); glVertex3f( width, height, length); // Top Left Of The Quad (Right)
    glTexCoord2d(1.0f, 1.0f); glVertex3f( width, -height, length); // Bottom Left Of The Quad (Right)
    glTexCoord2d(0.0f, 1.0f); glVertex3f( width, -height, -length); // Bottom Right Of The Quad (Right)
    glEnd();
    And it works... But it just clearly looks like a cube:



    What am I missing?

  2. #2
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    56
    You are missing correct textures for a sky box. You need textures that are seamless with the corresponding adjacent cube faces or else you'll obviously see a difference between the faces.

  3. #3
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by Quaver View Post
    What am I missing?
    Quote Originally Posted by Ed Daenar View Post
    You are missing correct textures for a sky box. You need textures that are seamless with the corresponding adjacent cube faces or else you'll obviously see a difference between the faces.
    It's not just a case of textures being seamless, they need to be the result of projecting a panorama onto the faces of a cube. If you're using photographs, you can't just paste them together; you have to re-project them correctly.

    Also: a skybox doesn't move; it's always centred on the viewpoint. If that grass is the bottom face of the skybox, you'd better not be planning on moving the viewpoint.

    And you want to avoid the horizon being visible. You typically ensure that the range of possible viewpoints is enclosed within a border of opaque geometry so that this can't happen. Failing that, you need to find some way to make the terrain blend into the skybox; this is somewhat simpler if the distant terrain is flat and featureless, e.g. sea or desert.

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    445
    Have you remembered to turned off lighting when drawing the skybox?

  5. #5
    Intern Newbie
    Join Date
    Jul 2013
    Posts
    35
    Thanks all, it turned out that some of my texture coords where wrong and that some of the faces were back to front or upside down, disabling lighting when drawing the skybox also helped make it look better.

    I have a new problem now though. Sometimes the skybox has these faint lines between each face like so:



    How can I stop this?

    EDIT: I forgot to mention that using GL_CLAMP_TO_EDGE for both my T and S wrapping modes doesn't fix the problem.
    Last edited by Quaver; 07-28-2013 at 03:43 AM.

  6. #6
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by Quaver View Post
    I have a new problem now though. Sometimes the skybox has these faint lines between each face like so:
    Is polygon anti-aliasing (GL_POLYGON_SMOOTH) enabled? If that is enabled without the correct blending mode or without an alpha buffer, it can cause the background to bleed through at shared edges.

  7. #7
    Intern Newbie
    Join Date
    Jul 2013
    Posts
    35
    It is off; turning it on has no effect.

  8. #8
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362
    Maybe you can try to enable seamless cubemap filtering .

  9. #9
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Quote Originally Posted by trinitrotoluene View Post
    Maybe you can try to enable seamless cubemap filtering .
    That only works when using a cube map.

  10. #10
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362
    Quote Originally Posted by Alfonse Reinheart View Post
    That only works when using a cube map.
    Oups, then try with a cube map texture with seamless filtering if your graphic card can do that.

Posting Permissions

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