Depth test does not work on Linux with SWT

Started by PJPoon, February 06, 2008, 01:11:32

Previous topic - Next topic

PJPoon

Hello.  I have been having some problems getting the depth test to work on a Linux machine using SWT's GLCanvas.
The following code(taken mostly from NeHe's tutorial) works fine in Windows, but in Linux it displays as if depth testing wasn't enabled.  It also works fine if I remove the SWT stuff.
public class Test{
	private static float rtri; // Angle For The Triangle
	private static float rquad; // Angle For The Quad
	static void draw(){
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

		GL11.glLoadIdentity(); // Reset The Current Modelview Matrix

		GL11.glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
		GL11.glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis
		GL11.glBegin(GL11.GL_TRIANGLES); // Drawing Using Triangles
		GL11.glColor3f(1.0f,0.0f,0.0f); // Red
		GL11.glVertex3f(0.0f,1.0f,0.0f); // Top Of Triangle (Front)
		GL11.glColor3f(0.0f,1.0f,0.0f); // Green
		GL11.glVertex3f(-1.0f,-1.0f,1.0f); // Left Of Triangle (Front)
		GL11.glColor3f(0.0f,0.0f,1.0f); // Blue
		GL11.glVertex3f(1.0f,-1.0f,1.0f); // Right Of Triangle (Front)
		GL11.glColor3f(1.0f,0.0f,0.0f); // Red
		GL11.glVertex3f(0.0f,1.0f,0.0f); // Top Of Triangle (Right)
		GL11.glColor3f(0.0f,0.0f,1.0f); // Blue
		GL11.glVertex3f(1.0f,-1.0f,1.0f); // Left Of Triangle (Right)
		GL11.glColor3f(0.0f,1.0f,0.0f); // Green
		GL11.glVertex3f(1.0f,-1.0f,-1.0f); // Right Of Triangle (Right)
		GL11.glColor3f(1.0f,0.0f,0.0f); // Red
		GL11.glVertex3f(0.0f,1.0f,0.0f); // Top Of Triangle (Back)
		GL11.glColor3f(0.0f,1.0f,0.0f); // Green
		GL11.glVertex3f(1.0f,-1.0f,-1.0f); // Left Of Triangle (Back)
		GL11.glColor3f(0.0f,0.0f,1.0f); // Blue
		GL11.glVertex3f(-1.0f,-1.0f,-1.0f); // Right Of Triangle (Back)
		GL11.glColor3f(1.0f,0.0f,0.0f); // Red
		GL11.glVertex3f(0.0f,1.0f,0.0f); // Top Of Triangle (Left)
		GL11.glColor3f(0.0f,0.0f,1.0f); // Blue
		GL11.glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)
		GL11.glColor3f(0.0f,1.0f,0.0f); // Green
		GL11.glVertex3f(-1.0f,-1.0f,1.0f); // Right Of Triangle (Left)
		GL11.glEnd(); // Finished Drawing The Triangle

		GL11.glLoadIdentity(); // Reset The Current Modelview Matrix
		GL11.glTranslatef(1.5f,0.0f,-7.0f); // Move Right 1.5 Units And Into The Screen 6.0
		GL11.glRotatef(rquad,1.0f,1.0f,1.0f); // Rotate The Quad On The X axis
		GL11.glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
		GL11.glBegin(GL11.GL_QUADS); // Draw A Quad
		GL11.glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
		GL11.glVertex3f(1.0f,1.0f,-1.0f); // Top Right Of The Quad (Top)
		GL11.glVertex3f(-1.0f,1.0f,-1.0f); // Top Left Of The Quad (Top)
		GL11.glVertex3f(-1.0f,1.0f,1.0f); // Bottom Left Of The Quad (Top)
		GL11.glVertex3f(1.0f,1.0f,1.0f); // Bottom Right Of The Quad (Top)
		GL11.glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange
		GL11.glVertex3f(1.0f,-1.0f,1.0f); // Top Right Of The Quad (Bottom)
		GL11.glVertex3f(-1.0f,-1.0f,1.0f); // Top Left Of The Quad (Bottom)
		GL11.glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
		GL11.glVertex3f(1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
		GL11.glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
		GL11.glVertex3f(1.0f,1.0f,1.0f); // Top Right Of The Quad (Front)
		GL11.glVertex3f(-1.0f,1.0f,1.0f); // Top Left Of The Quad (Front)
		GL11.glVertex3f(-1.0f,-1.0f,1.0f); // Bottom Left Of The Quad (Front)
		GL11.glVertex3f(1.0f,-1.0f,1.0f); // Bottom Right Of The Quad (Front)
		GL11.glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow
		GL11.glVertex3f(1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Back)
		GL11.glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Back)
		GL11.glVertex3f(-1.0f,1.0f,-1.0f); // Top Right Of The Quad (Back)
		GL11.glVertex3f(1.0f,1.0f,-1.0f); // Top Left Of The Quad (Back)
		GL11.glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
		GL11.glVertex3f(-1.0f,1.0f,1.0f); // Top Right Of The Quad (Left)
		GL11.glVertex3f(-1.0f,1.0f,-1.0f); // Top Left Of The Quad (Left)
		GL11.glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
		GL11.glVertex3f(-1.0f,-1.0f,1.0f); // Bottom Right Of The Quad (Left)
		GL11.glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet
		GL11.glVertex3f(1.0f,1.0f,-1.0f); // Top Right Of The Quad (Right)
		GL11.glVertex3f(1.0f,1.0f,1.0f); // Top Left Of The Quad (Right)
		GL11.glVertex3f(1.0f,-1.0f,1.0f); // Bottom Left Of The Quad (Right)
		GL11.glVertex3f(1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
		GL11.glEnd(); // Done Drawing The Quad

		rtri+=0.2f; // Increase The Rotation Variable For The Triangle
		rquad-=0.15f; // Decrease The Rotation Variable For The Quad
	}

	public static void main(String[] args){
		final Display display=new Display();
		Shell shell=new Shell(display);
		shell.setLayout(new FillLayout());
		Composite comp=new Composite(shell,SWT.NONE);
		comp.setLayout(new FillLayout());
		GLData data=new GLData();
		data.doubleBuffer=true;
		final GLCanvas canvas=new GLCanvas(comp,SWT.NONE,data);

		canvas.setCurrent();
		try{
			GLContext.useContext(canvas);
		}
		catch(LWJGLException e){
			e.printStackTrace();
		}

		canvas.addListener(SWT.Resize,new Listener(){
			public void handleEvent(Event event){
				Rectangle bounds=canvas.getBounds();
				float fAspect=(float)bounds.width/(float)bounds.height;
				canvas.setCurrent();
				try{
					GLContext.useContext(canvas);
				}
				catch(LWJGLException e){
					e.printStackTrace();
				}
				GL11.glViewport(0,0,bounds.width,bounds.height);
				GL11.glMatrixMode(GL11.GL_PROJECTION);
				GL11.glLoadIdentity();
				GLU.gluPerspective(45.0f,fAspect,0.5f,400.0f);
				GL11.glMatrixMode(GL11.GL_MODELVIEW);
				GL11.glLoadIdentity();
			}
		});

		GL11.glClearDepth(1.0); // Depth Buffer Setup
		GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
		GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do

		GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix

		shell.setSize(640,480);
		shell.open();

		display.asyncExec(new Runnable(){
			public void run(){
				if(!canvas.isDisposed()){
					canvas.setCurrent();
					try{
						GLContext.useContext(canvas);
					}
					catch(LWJGLException e){
						e.printStackTrace();
					}
					draw();
					canvas.swapBuffers();
					display.asyncExec(this);
				}
			}
		});

		while(!shell.isDisposed()){
			if(!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}

I'm using Red Hat 3.4.2-6.fc3

Is this a problem with LWJGL or SWT?

Matzon


Fool Running

QuoteIt also works fine if I remove the SWT stuff ..... Is this a problem with LWJGL or SWT?
More then likely a problem with SWT, I'm guessing. ;)
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D