diff options
author | Sven Gothel <[email protected]> | 2009-06-13 23:36:39 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-06-13 23:36:39 +0000 |
commit | a4f42ce7895ec5f58bf4494dcb21325e1d5201d4 (patch) | |
tree | 4c92e198d50799e1931a984abf2e4b23c00504c1 | |
parent | 5597463a23ddb6376be96422abf99a3432ab82d1 (diff) |
NEWT Multithreaded Windows: Must be created in their own thread (-> Windows)
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@345 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
-rwxr-xr-x | src/demos/es1/RedSquare.java | 38 | ||||
-rwxr-xr-x | src/demos/es2/RedSquare.java | 40 |
2 files changed, 31 insertions, 47 deletions
diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index 7541e0f..24da987 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -17,9 +17,13 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo private GLProfile glp; private GLU glu; private boolean quit = false; + private String glprofile; + private int type; - public RedSquare() { + public RedSquare(String glprofile, int type) { super(); + this.glprofile=glprofile; + this.type=type; } public void windowResized(WindowEvent e) { @@ -70,11 +74,15 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo public void mouseWheelMoved(MouseEvent e) { } - private void init(String glprofile, int type) { + private void runInMain() { + run(); + } + + public void run() { + System.err.println(glp+" RedSquare.run() 0"); int width = 800; int height = 480; glp = GLProfile.GetProfile(glprofile); - System.err.println(glp+" RedSquare.init() 1"); try { GLCapabilities caps = new GLCapabilities(glp); @@ -99,24 +107,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo // window.setFullscreen(true); window.setVisible(true); window.enablePerfLog(true); - } catch (Throwable t) { - t.printStackTrace(); - } - } - private void runInThread(String glprofile, int type) { - init(glprofile, type); - run(); - } - - private void start(String glprofile, int type) { - init(glprofile, type); - start(); - } - - public void run() { - System.err.println(glp+" RedSquare.run() 0"); - try { do { window.display(); } while (!quit && window.getDuration() < 20000) ; @@ -227,15 +218,16 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo int type = USE_NEWT ; for(int i=0; i<args.length; i++) { if(args[i].equals("-awt")) { - type |= USE_AWT; + type = USE_AWT; } if(args[i].startsWith("-GL")) { if(null!=glprofile) { - new RedSquare().start(glprofile, type); + new RedSquare(glprofile, type).start(); + type = USE_NEWT ; } glprofile=args[i].substring(1); } } - new RedSquare().runInThread(glprofile, type); + new RedSquare(glprofile, type).runInMain(); } } diff --git a/src/demos/es2/RedSquare.java b/src/demos/es2/RedSquare.java index 246eced..bcbae3d 100755 --- a/src/demos/es2/RedSquare.java +++ b/src/demos/es2/RedSquare.java @@ -19,9 +19,13 @@ public class RedSquare extends Thread implements WindowListener, MouseListener, private boolean quit = false; private long startTime; private long curTime; - - public RedSquare() { + private String glprofile; + private int type; + + public RedSquare(String glprofile, int type) { super(); + this.glprofile=glprofile; + this.type=type; } public void windowResized(WindowEvent e) { } @@ -62,11 +66,15 @@ public class RedSquare extends Thread implements WindowListener, MouseListener, public void mouseWheelMoved(MouseEvent e) { } - private void init(String glprofile, int type) { + private void runInMain() { + run(); + } + + public void run() { + System.err.println(glp+" RedSquare.run()"); int width = 800; int height = 480; glp = GLProfile.GetProfile(glprofile); - System.err.println(glp+" RedSquare.start()"); try { GLCapabilities caps = new GLCapabilities(glp); @@ -89,24 +97,7 @@ public class RedSquare extends Thread implements WindowListener, MouseListener, // window.setFullscreen(true); window.setVisible(true); window.enablePerfLog(true); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - private void runInThread(String glprofile, int type) { - init(glprofile, type); - run(); - } - private void start(String glprofile, int type) { - init(glprofile, type); - start(); - } - - public void run() { - System.err.println(glp+" RedSquare.run()"); - try { startTime = System.currentTimeMillis(); while (!quit && ((curTime = System.currentTimeMillis()) - startTime) < 20000) { @@ -272,15 +263,16 @@ public class RedSquare extends Thread implements WindowListener, MouseListener, int type = USE_NEWT ; for(int i=0; i<args.length; i++) { if(args[i].equals("-awt")) { - type |= USE_AWT; + type = USE_AWT; } if(args[i].startsWith("-GL")) { if(null!=glprofile) { - new RedSquare().start(glprofile, type); + new RedSquare(glprofile, type).start(); + type = USE_NEWT ; } glprofile=args[i].substring(1); } } - new RedSquare().runInThread(glprofile, type); + new RedSquare(glprofile, type).runInMain(); } } |