package demos.readbuffer; import java.lang.reflect.*; import java.nio.*; import javax.media.opengl.*; import javax.media.nativewindow.*; import com.sun.javafx.newt.*; import com.sun.javafx.newt.opengl.*; public class Main implements WindowListener, MouseListener, SurfaceUpdatedListener { public boolean quit = false; public GLWindow window = null; public void surfaceUpdated(Object updater, NativeWindow window, long when) { if(null!=window) { this.window.display(); } } public void windowResized(WindowEvent e) { } public void windowMoved(WindowEvent e) { } public void windowGainedFocus(WindowEvent e) { } public void windowLostFocus(WindowEvent e) { } public void windowDestroyNotify(WindowEvent e) { quit = true; } public void mouseClicked(MouseEvent e) { System.out.println("mouseevent: "+e); switch(e.getClickCount()) { case 1: if(null!=window) { window.setFullscreen(!window.isFullscreen()); } break; default: quit=true; break; } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { } public void mouseWheelMoved(MouseEvent e) { } public GLWindow createOffscreen(GLCapabilities caps, int w, int h, boolean pbuffer) { GLCapabilities capsOffscreen = (GLCapabilities) caps.clone(); capsOffscreen.setOnscreen(false); capsOffscreen.setPBuffer(pbuffer); capsOffscreen.setDoubleBuffered(false); GLWindow windowOffscreen = GLWindow.create(capsOffscreen); windowOffscreen.enablePerfLog(true); windowOffscreen.setSize(w, h); windowOffscreen.setVisible(true); return windowOffscreen; } private void run(String glProfileStr, int typeNewt, boolean fullscreen, int typeTest, GLEventListener demo, boolean pbuffer) { GLProfile glp = GLProfile.get(glProfileStr); int width = 800; int height = 480; System.out.println("readbuffer.Main.run() Test: "+typeTest); try { GLCapabilities caps = new GLCapabilities(glp); // Full init pbuffer window .. GLWindow windowOffscreen = createOffscreen(caps, width, height, pbuffer); // setField(demo, "glDebug", new Boolean(true)); // setField(demo, "glTrace", new Boolean(true)); if(!setField(demo, "window", windowOffscreen)) { setField(demo, "glWindow", windowOffscreen); } windowOffscreen.addGLEventListener(demo); if ( TEST_SURFACE2FILE < typeTest ) { System.out.println("readbuffer.Main.run() Using a target onscreen window with read drawable attachment"); // Setup init onscreen window .. Window nWindow = null; if(0!=(typeNewt&USE_AWT)) { Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0 nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps); window = GLWindow.create(nWindow); } else { window = GLWindow.create(caps); } window.addWindowListener(this); window.addMouseListener(this); window.setSize(width, height); window.setFullscreen(fullscreen); window.setVisible(true); } GLDrawable readDrawable = windowOffscreen.getContext().getGLDrawable() ; if ( TEST_SURFACE2FILE == typeTest ) { Surface2File s2f = new Surface2File(); windowOffscreen.addSurfaceUpdatedListener(s2f); } else if ( TEST_READBUFFER2FILE == typeTest ) { ReadBuffer2File readDemo = new ReadBuffer2File( readDrawable ) ; window.addGLEventListener(readDemo); } else if ( TEST_READBUFFER2SCREEN == typeTest ) { ReadBuffer2Screen readDemo = new ReadBuffer2Screen( readDrawable ) ; window.addGLEventListener(readDemo); } if(null!=window) { windowOffscreen.addSurfaceUpdatedListener(this); } System.out.println("+++++++++++++++++++++++++++"); System.out.println(windowOffscreen); System.out.println("+++++++++++++++++++++++++++"); while ( !quit && windowOffscreen.getDuration() < 31000) { // System.out.println("..............................."); windowOffscreen.display(); } // Shut things down cooperatively window.destroy(); windowOffscreen.destroy(); window.getFactory().shutdown(); System.out.println("readbuffer.Main shut down cleanly."); } catch (GLException e) { e.printStackTrace(); } } public static int USE_NEWT = 0; public static int USE_AWT = 1 << 0; public static int TEST_SURFACE2FILE = 0; public static int TEST_READBUFFER2FILE = 1; public static int TEST_READBUFFER2SCREEN = 2; public static void main(String[] args) { String glProfileStr = null; boolean fullscreen = false; boolean pbuffer = true; int typeNewt = USE_NEWT ; int typeTest = TEST_SURFACE2FILE; int i=0; while(i