Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  DepthTest not working when zFar distance is raised  (Read 934 times)
0 Members and 1 Guest are viewing this topic.
Offline Lorgarn

Innocent Bystander





« Posted 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
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2008-10-07 17:28:05 »

You'll get more luck if you put this in the JOGL or LWJGL forum.

See my work:
OTC Software
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2008-10-07 20:14:33 »

You should modify the clipping planes with "glu.gluPerspective(50.0, 1, NEAR, FAR);"

Just re-init your PROJECTION_MATRIX every frame, if you want to vary your depth.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (15 views)
2014-09-12 09:08:26

Norakomi (45 views)
2014-09-10 13:57:51

TehJavaDev (57 views)
2014-09-10 06:39:09

Tekkerue (26 views)
2014-09-09 02:24:56

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (21 views)
2014-09-07 01:11:22

Longarmx (20 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
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!