I am trying to render a couple of cubic objects (10 lines and 20 rows of them) each of them between 2 or 5 units in diameter. To have the camera see them all, I have to move it so far away, that they are past the clipping distance.
This is what I do to initiate the scene:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| final GL gl = drawable.getGL(); int w = 500, h = 500; float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; gl.glShadeModel(GL.GL_SMOOTH); gl.glClearDepth(1.0f); gl.glDepthFunc(GL.GL_LEQUAL); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); gl.glEnable(GL.GL_TEXTURE_2D); red = 1.0f; green = 1.0f; blue = 1.0f; gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos, 0); gl.glEnable(GL.GL_CULL_FACE); gl.glEnable(GL.GL_LIGHTING); gl.glEnable(GL.GL_LIGHT0); gl.glEnable(GL.GL_DEPTH_TEST); gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(50.0, 1, 2.0, 40.0); gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glEnable(GL.GL_NORMALIZE); |
For (re-)drawing the scene I do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| GL gl = drawable.getGL(); if ((drawable instanceof GLJPanel) && !((GLJPanel) drawable).isOpaque() && ((GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) { gl.glClear(GL.GL_DEPTH_BUFFER_BIT); } else { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); } gl.glLoadIdentity(); float divX = calcX(); float divY = calcY(); glu.gluLookAt(divX, divY, 50, divX, divY, 0, 0, 1, 0); gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); for (int i = 0; i < g.getQuantity(); i ++) { gl.glPushMatrix(); gl.glPopMatrix(); } |
As soon as I specify a highter Zfar value by adding
1
| gl.glDepthRange(1.0f, 90.0f); |
to the display function, the Depth Testing fails completly. I have found references, that some zNear / zFar values break DepthTesting due to a limited accurency, but does that occur in such smal values?
Regards
Lorgarn