I'm in a bind :) Viewspace/DepthBuffer

I can’t figure out how to do something…

I want to render a skydome and when I do that, all of the triangles will be far away… ( z values around - 10000 ) or so…

Here is my problem
My View matrix is built like this…
gluPerspective(45.0f,(GLfloat)srn.d[0]/(GLfloat)srn.d[1],1.0f,1000.0f);

Notice the 1.0f , 1000.0f

Now when i goto render my triangles… I turn off depth test and depth buffer writes…

I want to render my triangles but they will all bout of of the 1.0f - 1000.0f range from my view matrix…

How can I get around this???

I don’t want to raise my viewmatrix to 10000.0f because then you get lots of jaggies with other polys that are close up.

Does anyone know what I’m talking about???

Please help me out with this bind…!

Thankx,
Mongoose

O yeah and one more thing…

What is the command to turn on/off depth buffer writes??

I know you have to do this
glEnable or glDisable( GL_DEPTH_TEST ) to turn off the testing…

But I want to turn off both the test and the writes…

Thankx,
Mongoose

I don’t fully understand what your first question is about, sorry. But for your second question, disable depth writes with glDepthMask(GL_FALSE);

Originally posted by DFrey:
I don’t fully understand what your first question is about, sorry. But for your second question, disable depth writes with glDepthMask(GL_FALSE);

To make you understand the problem just set up your perspective matrix as I do and render a few triangles off in the z distance by about 5000…

I’m trying to figure out a way to turn the distance check off!

It sounds like you are experiencing problems with depth-buffer precision. A couple of options that come to mind are:

  • minimize the distance between the near & far clip planes, either by bringing the far clip plane closer to your viewpoint or moving the near clip plane out a bit
  • use a higher-prcision depth buffer (eg, 32-bit)

Originally posted by Mongoose:
I’m trying to figure out a way to turn the distance check off!

That can’t be done (the distance check, by the way, is clipping).

Instead, disable GL_DEPTH_TEST and draw the skybox/skydome safely within your near/far clip planes. For example, if you have near and far of 1 and 1000, drawing a sphere of radius 30 is definitely safe.

The depth information is still used for other things, such as fog and perspective correction, but for perspective correction, only the ratios of W values matter, not their absolute values.

Note that disabling GL_DEPTH_TEST automatically turns off depth writes. If you want to write to depth but not test it, you need to enable GL_DEPTH_TEST and set the DepthFunc to GL_ALWAYS, with the DepthMask set to GL_TRUE.

  • Matt