Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL : How can I put the skybox in the infinity

Tags:

opengl

I need to know how can I make the skybox appears as it's in the infinity?? I know that it's something related to depth, but I don't know the exact thing to disable or to enable??

like image 814
Lisa Avatar asked May 18 '10 17:05

Lisa


4 Answers

First, turn off depth writes/testing (you don't need to bother with turning off depth testing if you draw the skybox first and clear your depth buffer):

glDisable(GL_DEPTH_TEST);
glDepthMask(false);

Then, move the camera to the origin and rotate it the inverse of the modelview matrix:

// assume we're working with the modelview
glPushMatrix();

// inverseModelView is a 4x4 matrix with no translation and a transposed 
// upper 3x3 portion from the regular modelview
glLoadMatrix(&inverseModelView);

Now, draw your sky box and turn depth writes back on:

DrawSkybox();

glPopMatrix();
glDepthMask(true);
glEnable(GL_DEPTH_TEST);

You'll probably want to use glPush/PopAttrib() to ensure your other states get correctly set after you draw the skybox too (make sure to turn off things like lighting or blending if necessary).

You should do this before drawing anything so all color buffer writes happen on top of your sky box.

like image 151
Ron Warholic Avatar answered Nov 12 '22 10:11

Ron Warholic


First, Clear the buffer.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Then, save your current modelview matrix and load the identity.

glPushMatrix();
glLoadIdentity();

Then render your skybox.

Skybox.render();

Then, clear the depth buffer and continue normally with rendering

glClear(GL_DEPTH_BUFFER_BIT);

OtherStuff.render();

glutSwapBuffers();
like image 38
Ned Bingham Avatar answered Nov 12 '22 10:11

Ned Bingham


The only problem with drawing the sky box is first is that your pixel shader will execute for every pixel in the sky box. Just to be overwritten by other object in your world later on. Your best bet is to render all opaque object first then render your sky box. That way the pixel shader for the sky box only gets executed for the pixel who pass the z buffer test.

like image 43
BornToCode Avatar answered Nov 12 '22 09:11

BornToCode


There is no infinity. A skybox is just a textured box, with normaly 0,0,0 in the middle. Here is a short tut: link text

like image 41
InsertNickHere Avatar answered Nov 12 '22 10:11

InsertNickHere