package demos; import java.lang.reflect.*; import javax.media.opengl.*; import javax.media.nativewindow.*; import com.jogamp.newt.*; import com.jogamp.newt.event.*; import com.jogamp.newt.opengl.*; public class GLNewtRun extends WindowAdapter implements KeyListener, MouseListener { static GLWindow window; static volatile boolean quit = false; public void windowDestroyNotify(WindowEvent e) { quit = true; } static int dx=0; static int dy=0; static int dw=0; static int dh=0; public void keyPressed(KeyEvent e) { System.out.println(e); if(e.getKeyChar()=='f') { window.setFullscreen(!window.isFullscreen()); } else if(e.getKeyChar()=='q') { quit = true; } else if(e.getKeyChar()=='p') { int x = window.getX() + dx; int y = window.getY() + dy; System.out.println("Reset Pos "+x+"/"+y); window.setPosition(x, y); } else if(e.getKeyChar()=='s') { int w = window.getWidth() + dw; int h = window.getHeight() + dh; System.out.println("Reset Size "+w+"x"+h); window.setSize(w, h); } } public void keyReleased(KeyEvent e) { System.out.println(e); } public void keyTyped(KeyEvent e) { System.out.println(e); } public void mouseClicked(MouseEvent e) { System.out.println(" mouseevent: "+e); switch(e.getClickCount()) { case 1: if(e.getButton()>MouseEvent.BUTTON1) { 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 boolean shouldQuit() { return quit; } public static int str2int(String str, int def) { try { return Integer.parseInt(str); } catch (Exception ex) { ex.printStackTrace(); } return def; } public static boolean setField(Object instance, String fieldName, Object value) { try { Field f = instance.getClass().getField(fieldName); if(f.getType().isInstance(value)) { f.set(instance, value); return true; } else { System.out.println(instance.getClass()+" '"+fieldName+"' field not assignable with "+value.getClass()+", it's a: "+f.getType()); } } catch (NoSuchFieldException nsfe) { System.out.println(instance.getClass()+" has no '"+fieldName+"' field"); } catch (Throwable t) { t.printStackTrace(); } return false; } public static void main(String[] args) { boolean parented = false; boolean useAWTTestFrame = false; boolean useAWT = false; boolean undecorated = false; boolean fullscreen = false; int x_p = 0; int y_p = 0; int x = 0; int y = 0; int width = 800; int height = 480; String glProfileStr = null; if(0==args.length) { throw new RuntimeException("Usage: "+GLNewtRun.class+" "); } GLNewtRun listener = new GLNewtRun(); int i=0; while(i