skybox

i am trying to render a skybox i can get the images up but it just looks like a box.

here is my code:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glDisable(GL_DEPTH_TEST | GL_BLEND | GL_ALPHA_TEST |
GL_TEXTURE_GEN_S | GL_TEXTURE_GEN_T);
glDepthMask(GL_FALSE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);

GLdouble mv[16];
glGetDoublev(GL_MODELVIEW_MATRIX, mv);
mv[12] = 0.0; mv[13] = 0.0; mv[14] = 0.0;
glPushMatrix();
glLoadMatrixd(mv);

glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_FRONT].name);

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex3f(-10, -10, -5);
glTexCoord2i(1, 0);
glVertex3f(10, -10, -5);
glTexCoord2i(1, 1);
glVertex3f(10, 10, -5);
glTexCoord2i(0, 1);
glVertex3f(-10, 10, -5);
glEnd();

glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_BACK].name);

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex3f(-10, -10, -25);
glTexCoord2i(1, 0);
glVertex3f(10, -10, -25);
glTexCoord2i(1, 1);
glVertex3f(10, 10, -25);
glTexCoord2i(0, 1);
glVertex3f(-10, 10, -25);
glEnd();

glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_RIGHT].name);

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex3f(-10, -10, -25);
glTexCoord2i(1, 0);
glVertex3f(-10, -10, -5);
glTexCoord2i(1, 1);
glVertex3f(-10, 10, -5);
glTexCoord2i(0, 1);
glVertex3f(-10, 10, -25);
glEnd();

glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_LEFT].name);

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex3f(10, -10, -5);
glTexCoord2i(1, 0);
glVertex3f(10, -10, -25);
glTexCoord2i(1, 1);
glVertex3f(10, 10, -25);
glTexCoord2i(0, 1);
glVertex3f(10, 10, -5);
glEnd();

glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_UP].name);

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex3f(-10, 10, -25);
glTexCoord2i(1, 0);
glVertex3f(10, 10, -25);
glTexCoord2i(1, 1);
glVertex3f(10, 10, -5);
glTexCoord2i(0, 1);
glVertex3f(-10, 10, -5);
glEnd();

glBindTexture(GL_TEXTURE_2D, skyBoxTexture[SKYBOX_DOWN].name);

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex3f(10, -10, 25);
glTexCoord2i(1, 0);
glVertex3f(-10, -10, 25);
glTexCoord2i(1, 1);
glVertex3f(-10, -10, 5);
glTexCoord2i(0, 1);
glVertex3f(10, -10, 5);
glEnd();

glFlush();

glutSwapBuffers();

glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

glPopMatrix(); }

anyone see any errors or what i am missing?
incus

glDisable(GL_DEPTH_TEST | GL_BLEND | GL_ALPHA_TEST |
GL_TEXTURE_GEN_S | GL_TEXTURE_GEN_T);

This is obviuosly wrong, and should rather be,

glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);

But that’s maybe not the prob, can you make a screenshot of how it look wrong?

Hi, I’ve never implemented skybox, but shouldn’t the texture coords be generated based on the viewer perspective to seemingly ‘project’ the texture away from the viewer? Other wise the texturing will just make a box. Right?

John.

Try using textures from a skybox you know works. The textures are probibly your prob. They may be too 2D looking. And no, the TexCoords don’t have to be projected.

Also, you can’t be close to any wall. You have to be fairly close to the center of the skybox or else the box will be noticable. As you walk through a map, ground or world of some sort the sky must follow the camera. Thy sky and camera must share the same center point.

[This message has been edited by reubenhawkins (edited 09-14-2002).]

[This message has been edited by reubenhawkins (edited 09-14-2002).]

The texture coordinates are always the same. There should be no lighting. The box should always be centered on the viewer (and thus always have the same coordinates, modulo rotation).

Search in this very forum on “sky box” and you’ll probably both code and suggestions for how to generate textures. Note that the trick with sky boxes is in the texture generation – each face has to be a 90-degree FOV projection onto a square, just like a cubic environment map, else it’ll look wrong.

In your code, you use a variety of coordinate values. That’s wrong. Try using only the values “-10” and “10” for your x, y and z coordinates. This is the same thing as centering the box around the viewer. Once you got this working, you can rotate the box by the inverse of the camera rotation (but don’t translate!).

EDIT: You also don’t need to clear the color buffer before drawing a sky box, as it will fill the screen anyway. Thus, you can draw the sky box INSTEAD of clearing the color buffer.

[This message has been edited by jwatte (edited 09-14-2002).]

jwatte,

You don’t even have to clear the depth buffer. Just disable z test, enable z writes, and push the skybox waaaaaay out (or use glDepthRange).

Fresh,

If you do that, then either you won’t clear the depth buffer to the furthest possible value, OR you run the risk of clipping out the sky box (unless you use depth clamp).

Clearing to the furthest possible value is useful when you want to read back depth values to test for occlusion (for that must-have lens flare effect, say).

Also, on modern cards, “fast depth clear” makes glClear of the depth bit and stencil bit combined, and then drawing a sky box with depth disabled, much faster than drawing it in overdraw mode.

jwatte,

Yup, you’re right. I just tested this on my 9700 and it is in fact faster. Thanks for the tip! I was still stuck in old-skool 3dfx mode I guess