From d9e94b2d5460fd7be70fe995ab5ba74a02a98ab9 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 20 Oct 2006 10:42:43 +0000 Subject: [PATCH] Don't repaint() from a separate thread in AWT demos. This results in a smoother rendering. --- .../opengl/LinuxAWTGLCanvasPeerInfo.java | 6 ++--- .../org/lwjgl/test/opengl/awt/AWTGears.java | 12 +--------- .../org/lwjgl/test/opengl/awt/AWTTest.java | 23 ++++--------------- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java b/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java index 50c16664..1b69a03a 100644 --- a/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java +++ b/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java @@ -51,12 +51,12 @@ final class LinuxAWTGLCanvasPeerInfo extends LinuxPeerInfo { } protected void doLockAndInitHandle() throws LWJGLException { - int screen = -1; - try { + int screen = 0;//-1; +/* try { screen = LinuxCanvasImplementation.getScreenFromDevice(canvas.getGraphicsConfiguration().getDevice()); } catch (LWJGLException e) { LWJGLUtil.log("Got exception while trying to determine screen: " + e); - } + }*/ nInitHandle(screen, awt_surface.lockAndGetHandle(canvas), getHandle()); } private static native void nInitHandle(int screen, ByteBuffer surface_buffer, ByteBuffer peer_info_handle) throws LWJGLException; diff --git a/src/java/org/lwjgl/test/opengl/awt/AWTGears.java b/src/java/org/lwjgl/test/opengl/awt/AWTGears.java index 87341b05..04724629 100644 --- a/src/java/org/lwjgl/test/opengl/awt/AWTGears.java +++ b/src/java/org/lwjgl/test/opengl/awt/AWTGears.java @@ -116,6 +116,7 @@ public class AWTGears extends Frame { GL11.glPopMatrix(); swapBuffers(); + repaint(); } catch (LWJGLException e) { throw new RuntimeException(e); } @@ -139,17 +140,6 @@ public class AWTGears extends Frame { }); setResizable(true); setVisible(true); - - new Thread() { - { - setDaemon(true); - } - public void run() { - for (;;) { - canvas0.repaint(); - } - } - }.start(); } private void setup() { diff --git a/src/java/org/lwjgl/test/opengl/awt/AWTTest.java b/src/java/org/lwjgl/test/opengl/awt/AWTTest.java index 4d498b0e..d35cc5ba 100644 --- a/src/java/org/lwjgl/test/opengl/awt/AWTTest.java +++ b/src/java/org/lwjgl/test/opengl/awt/AWTTest.java @@ -53,7 +53,7 @@ public class AWTTest extends Frame { /** AWT GL canvas */ private AWTGLCanvas canvas0, canvas1; - private float angle; + private volatile float angle; /** * C'tor @@ -80,6 +80,7 @@ public class AWTTest extends Frame { GL11.glRectf(-50.0f, -50.0f, 50.0f, 50.0f); GL11.glPopMatrix(); swapBuffers(); + repaint(); } catch (LWJGLException e) { throw new RuntimeException(e); } @@ -89,6 +90,7 @@ public class AWTTest extends Frame { add(canvas1 = new AWTGLCanvas() { public void paintGL() { try { + angle += 1.0f; makeCurrent(); GL11.glViewport(0, 0, getWidth(), getHeight()); GL11.glClearColor(0.0f, 1.0f, 0.0f, 1.0f); @@ -103,6 +105,7 @@ public class AWTTest extends Frame { GL11.glRectf(-50.0f, -50.0f, 50.0f, 50.0f); GL11.glPopMatrix(); swapBuffers(); + repaint(); } catch (LWJGLException e) { throw new RuntimeException(e); } @@ -117,24 +120,6 @@ public class AWTTest extends Frame { }); setResizable(true); setVisible(true); - - new Thread() { - { - setDaemon(true); - } - public void run() { - for (;;) { - angle += 1.0f; - canvas0.repaint(); - canvas1.repaint(); - try { - sleep(20); - } catch (InterruptedException e) { - break; - } - } - } - }.start(); } public static void main(String[] args) throws LWJGLException {