Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / DepthTest not working when zFar distance is raised on: 2008-10-07 13:17:10
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);              // Enable Smooth Shading
gl.glClearDepth(1.0f);                      // Depth Buffer Setup
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();
              //caling the function, that draws the object
          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
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (41 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!