Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Depth Buffer not working in Linux using b07  (Read 589 times)
0 Members and 1 Guest are viewing this topic.
Offline gusgus84

Senior Newbie




Java games rock!


« Posted 2004-11-22 23:28:02 »

Since the new fix in b07, I'm now able to run my JOGL app on my linux machine (running Fedora Core 2)  it all runs peachy except for one problem I've noticed.  The objects are not drawn in correct depth order even though I have enabled the GL_DEPTH_TEST.  When I try the code on Windows and OS X I have no problems at all.  I've written some simple source code to demonstrate the error.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
import net.java.games.jogl.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;


class Main
{
      public static void main(String [] args)
      {
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            GLPanel panel=new GLPanel();
            frame.getContentPane().add(panel);
            frame.pack();
            frame.setVisible(true);
            panel.showCanvas();
      }
}

class GLPanel extends JPanel implements GLEventListener
{
      private GLCanvas canvas;
      private GLCapabilities capabilities;
      //Constructor: Initializes a JOGL canvas with Hardware Acceleration and Dubble Buffering enabled
     public GLPanel()
      {
                   capabilities=new GLCapabilities();
              capabilities.setHardwareAccelerated(false);
              capabilities.setDoubleBuffered(false);
              canvas=GLDrawableFactory.getFactory().createGLCanvas(capabilities);
              canvas.addGLEventListener(this);
              add(canvas);
              setPreferredSize(new Dimension(300,200));
              canvas.setVisible(false);
      }
      public void repaintCanvas()
      {
            canvas.display();
      }
      public void showCanvas()
      {
            canvas.setSize(getSize().width, getSize().height);
            canvas.setVisible(true);
      }
      //init:  Initializes the canvas by setting the viewport, lighting, etc.
     public void init(GLDrawable glDrawable)
      {
            GL myGL=glDrawable.getGL();
            GLU myGLU=glDrawable.getGLU();
            int w=canvas.getSize().width, h=canvas.getSize().height;
            myGL.glEnable(GL.GL_DEPTH_TEST);
            myGL.glMatrixMode(GL.GL_PROJECTION);
            myGL.glLoadIdentity();
            myGLU.gluPerspective(45.0,w/(double)h,0.01,300);
      }
      public void drawDisk(GLDrawable glDrawable, double x, double y, double z, int rad, Point prec)
      {
            GL myGL=glDrawable.getGL();
            GLU myGLU=glDrawable.getGLU();
            GLUquadric sphere;
            myGL.glPushMatrix();
                  sphere=myGLU.gluNewQuadric();
                  myGLU.gluQuadricOrientation(sphere, GLU.GLU_OUTSIDE);
                  myGL.glTranslatef((float)x, (float)y, (float)z);
                  myGLU.gluDisk(sphere, rad, 0, prec.x, prec.y);
            myGLU.gluDeleteQuadric(sphere);
            myGL.glPopMatrix();
      }
      public void display(GLDrawable glDrawable)
      {
            GL myGL=glDrawable.getGL();
            GLU myGLU=glDrawable.getGLU();
        myGL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
          myGL.glMatrixMode(GL.GL_MODELVIEW);
        myGL.glLoadIdentity();
            myGLU.gluLookAt(0,0, 100,
                        0,0, 0,
                        0, 1, 0);
            /*The disks are called in the order(Farthest from camera to nearest):
             *Red, Green, Blue, White, Magenta
             *But using the depth buffer they should appear(Farthest from camera to nearest):
             *Magenta, Green, White, Red, Blue
             */

            myGL.glColor3f(1.0f, 0.0f, 0.0f);
            drawDisk(glDrawable, 0,0,3,10,new Point(15,15));
            myGL.glColor3f(0.0f, 1.0f, 0.0f);
            drawDisk(glDrawable, 8,8,1,10,new Point(15,15));
            myGL.glColor3f(0.0f, 0.0f, 1.0f);
            drawDisk(glDrawable, -8,8,4,10,new Point(15,15));
            myGL.glColor3f(1.0f, 1.0f, 1.0f);
            drawDisk(glDrawable, 8,-8,2,10,new Point(15,15));
            myGL.glColor3f(1.0f, 0.0f, 1.0f);
            drawDisk(glDrawable, -8,-8,0,10,new Point(15,15));
            myGL.glFlush();
      }
      public void reshape(GLDrawable glDrawable, int i, int i1, int width, int height)
      {
            GL myGL = glDrawable.getGL();
            GLU myGLU = glDrawable.getGLU();
            int w=canvas.getSize().width, h=canvas.getSize().height;
            myGL.glViewport(0, 0, w, h);
            myGL.glMatrixMode(GL.GL_PROJECTION);
            myGL.glLoadIdentity();
            myGLU.gluPerspective(45.0,w/(double)h,0.01,300);
      }
      public void displayChanged(GLDrawable glDrawable, boolean b, boolean b1)
      {
      }
}


The code should draw the disks in the order: Magenta, Green, White, Red, Blue, but when I run it on Windows that's what happens, but in Linux Red is on top.  Ken tried this on his but it worked fine...any ideas?
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 (23 views)
2014-09-12 09:08:26

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

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

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

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

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

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

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

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

mitcheeb (39 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!