3
\$\begingroup\$

I am trying to get a skybox rendered correctly in my first person shooter game. I have the skybox cube rendering using GL_TEXTURE_CUBE_MAP. I author the cube with extents of -1 and 1 along X,Y and Z.

However, I can't wrap my head around the camera transformations that I need to apply to get it right. My render loop looks something like this:

  • mp_Camera->ApplyTransform() :: Takes the current player transformation and inverts it and pushes that on the modelview stack.
  • Draw GameObjects
  • Draw Skybox

DrawSkybox does the following:

glEnable(GL_TEXTURE_CUBE_MAP);
glDepthMask(GL_FALSE);

// draw the cube here with extents

glDisable(GL_TEXTURE_CUBE_MAP);
glDepthMask(GL_TRUE);


Do I need to translate the skybox by the translation of the camera ? (btw, that didn't help either)

EDIT: I forgot to mention: It looks like a small cube with unit extents. Also, I can strafe in/out of the cube. Screenshot: Skybox as seen when stepped back in space

\$\endgroup\$
  • \$\begingroup\$ Have you tried drawing the skybox before drawing the game objects? Also a screenshot would help. \$\endgroup\$ – Tetrad Feb 5 '11 at 19:18
4
\$\begingroup\$

What you want to do is construct a matrix with only the rotation of the camera, and use that for the camera's world matrix, render the skybox there (i.e., as if the camera is at 0,0,0), and then render the other geometry with the camera's real position.

\$\endgroup\$
  • 1
    \$\begingroup\$ You can still add a little translation (your world translation * 0.001f, or some other appropiate scale) to simulate that you are travelling along the world. This works best if you are adding a 3d skybox. \$\endgroup\$ – r2d2rigo Feb 6 '11 at 1:21
  • \$\begingroup\$ @r2d2rigo: It is a 3D skybox (cube). when I try to add translation to the skybox, I soon run out of the cube. \$\endgroup\$ – brainydexter Feb 6 '11 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.