Clipping problem - port to JSR-231 b5

Edit: Problem solved! See post near the end.

I’m porting some code from the old net.java.games.jogl packages to JSR-231 (beta5).
This example has a first-person camera class that can look and move around an XZ grid.

Problem is, the grid seems to clip against the near plane, but altering near/far values, FOV, start points, etc all has no effect:

http://vault101.co.uk/downloads/jsr231_clipping.jpg

Current values:

Grid spacing: 1 OGL unit
Camera height from ground: 1 OGL unit
FOV: 45
Near plane: 0.5
Far plane: 50



frame/canvas setup:

        frame = new Frame ();
        canvas = new GLCanvas ();
        canvas.addGLEventListener (new Renderer (canvas));
        final Animator animator = new Animator (canvas);
        frame.add (canvas);
        frame.setSize (1024, 768);
        frame.setVisible (true);
        animator.start ();
        canvas.requestFocus ();


init() // outside the rendering loop
{
        gl.glEnable (gl.GL_TEXTURE_2D);
        gl.glClearDepth (1.0);
        gl.glDepthFunc (gl.GL_LESS);
        gl.glEnable (gl.GL_DEPTH_TEST);
        gl.glShadeModel (gl.GL_SMOOTH);
        gl.glMatrixMode (gl.GL_PROJECTION);
        gl.glLoadIdentity ();
        glu.gluPerspective (45, ((double)1024/ (double)768), 0.5, 50);
        gl.glMatrixMode (gl.GL_MODELVIEW);
        gl.glHint (gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST);
        gl.setSwapInterval (1);
        gl.glClearColor (0.5f, 0.5f, 0.5f, 1f); 
}

renderingloop
{
        gl.glClear (gl.GL_DEPTH_BUFFER_BIT);
        gl.glPolygonMode (gl.GL_FRONT_AND_BACK, gl.GL_FILL);
        gl.glLoadIdentity ();
        glu.gluLookAt (cam.pos.x, cam.pos.y, cam.pos.z, cam.view.x, cam.view.y, cam.view.z, 0, 1, 0);
        drawGrid();
}

Getting it working with JSR-231 was a copy-paste operation from code that used to work fine using the old net.java.games.jogl packages.
I must be doing something stupid here but I can see what! Any help much appreciated!

Thanks.

Have you tried doing your projection matrix setup each frame to see if it changes the behavior?

Have you tried specifying -Djogl.glu.nojava on the command line to switch back to the old C-based GLU implementation and to see whether that changes the behavior?

Hi Ken, I’ve just tried both of these options and the behaviour doesn’t change at all.
This really has me puzzled!

Edit: Not sure if this helps but if I look at the horizon, I can see the grid drawn all the way to the bottom of the screen.
If I then ‘look down’ or tilt down towards where my feet would be in the game, the grid starts to disappear perhaps 3 or 4 OGL units before my feet.

Looking at horizon:

http://vault101.co.uk/downloads/clipping_before.jpg

Looking down towards feet:

http://vault101.co.uk/downloads/clipping_after.jpg

What are the glClearDepth and glDepthFunc calls doing? Could you take them out and see if that changes anything?

Those calls are left over from some larger terrain work. Commenting out the calls changes nothing.

Well, it definitely looks like a near-plane clipping problem. See the barrel below, seen from a distance:

http://vault101.co.uk/downloads/barrel_before.jpg

and then the same barrel clipped as the camera gets closer:

http://vault101.co.uk/downloads/barrel_after.jpg

I don’t know what the difference could be – JOGL does nothing with the near clipping plane. The major differences between the old JOGL and the JSR-231 implementation are largely around pixel format selection. You may want to make sure you have the number of depth bits, etc. that you expect. If you have two small self-contained test cases, one for the old JOGL 1.1.1 and one for the current one, which exhibit the difference in behavior please post them.

Yep, thanks for you help Ken! I’ve still got all the old code including the jar and natives I used for the old JOGL example. I’ll have to cut them down to the basics.
I’ll either post the answer to this (if I find it) or post both test cases for folks to puzzle over!

Ken, rest assured it’s nothing to do with JSR-231 - see the comparison test apps below. (same output!)
I’ve got copy-paste happy and done something stupid in my other code!

http://vault101.co.uk/downloads/compare.jpg

Found the answer - tucked away into the reshape method was the following code - removing all of this has fixed the issue!


    public void reshape (GLAutoDrawable gLAutoDrawable, int x, int y, int width, int height)
    {
        float h = (float)height / (float)width;
        
        gl.glMatrixMode (GL.GL_PROJECTION);        
        gl.glLoadIdentity ();
        gl.glFrustum (-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
        gl.glMatrixMode (GL.GL_MODELVIEW);
        gl.glLoadIdentity ();
        gl.glTranslatef (0.0f, 0.0f, -40.0f);
    }

Great. Glad you found it.