Problems with hidden surface removal

I posted this last night then promptly deleted it after I realized I didn’t call glEnable(GL_DEPTH_TEST) ::), but after just having another go today I still can’t seem to get the depth test to work properly, so I’m getting pixels that should be obscured from view being drawn to the screen. I tried the same code in jogl and it works fine and draws the model correctly. I had the same problem with JCD lwjgl buda demo.

Any ideas what’s causing this, is it something I’m doing wrong or is it a problem with lwjgl?

Thanks for your help

  1. Check glGetInteger with GL11.GL_DEPTH_BITS to check you’re actually getting a depth buffer.
  2. Perhaps check you’ve got your face culling correct, both for the mode you’ve set and whatever model you’re rendering.
  3. You might be getting z-fighting from lack of precision. Try pushing your front plane outwards somewhat to see if that helps (or request a greater accuracy in your depth buffer).
  4. Check you’re actually clearing the depth buffer at the start of the frame.

Ok here’s the code I’m using, I used the FullScreenWindowedTest that came with lwjgl for the main setup stuff, the main bulk of the original code hasn’t been changed, except that the window now only loads up at 800/600.

The parts that have been changed now look like this:


         private void glInit() 
       {
                  GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
                  GL11.glViewport(0, 0, 800, 600);
                  GL11.glEnable(GL11.GL_CULL_FACE);
                  GL11.glEnable(GL11.GL_DEPTH_TEST);
                  GL11.glCullFace(GL11.GL_BACK);
                  GL11.glMatrixMode(GL11.GL_PROJECTION);
                  GL11.glLoadIdentity();
                  GL11.glFrustum(-1.0f, 1.0f, -1.0f, 1.0f, 1.5f, 300.0f);
                  GL11.glMatrixMode(GL11.GL_MODELVIEW);
            }

        private void render()
        {
                 GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                 GL11.glLoadIdentity();
                 GL11.glTranslatef(x, y, z);
                 GL11.glScalef(scaleValue, scaleValue, scaleValue);
                 GL11.glRotatef(angle, 0.0f, 1.0f, 0.0f);
                 drawModel(GL11.GL_POLYGON);
        }

The draw model method is nothing fancy, it just draws a model. I’ve tried the same code in a jogl using JCD’s jogl work frame and the model is drawn without any problems.

cheers

What about the window init code?

Cas :slight_smile:

Sorry, the window init code is exactly the same as in the FullScreenWindowedTest example, I had changed it earlier and though I was still using that version but I’m not.

GL11.glCullFace(GL11.GL_BACK);
Try taking that bit out

Just tried it, no joy, its seems to be drawing the screen in a certain order as some objects do draw on top of others, even when there behind them :slight_smile:

Its just like the GL11.GL_DEPTH_BUFFER_BIT isn’t being called?

Well, the FullscreenWindowedTest use 0 for stencil, alpha and depth. Try passing something != 0 for the depth argument. It should work then.

  • elias

Nice one elias, down in one :wink:

I had no idea the window creation was that tied into the opengl system, should of looked through the source ::slight_smile:

Btw, what’s the recommended value for depth, is one satisfactory for most cases?

Cheers

I can now return to the red book with an annoyingly happy face ;D

16

Cas :slight_smile:

Cheers Cas, is I wasn’t such an impatient git I’d probably be able to answer my own questions, well, some anyway :slight_smile: