Advertisement
Guest User

Jogl Example

a guest
Aug 17th, 2011
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1.  
  2. import javax.media.opengl.*;
  3. import com.jogamp.newt.*;
  4. import com.jogamp.newt.event.*;
  5. import com.jogamp.newt.opengl.*;
  6.  
  7.  
  8. class Example {
  9.  
  10.   private static volatile boolean quit = false;
  11.  
  12.  
  13.   public static void main(String[] args) {
  14.     NewtFactory.setUseEDT(true);
  15.  
  16.     Display display = NewtFactory.createDisplay(null);
  17.     Screen screen  = NewtFactory.createScreen(display, 0);
  18.     GLProfile profile = GLProfile.get(GLProfile.GL2ES2);
  19.     if (profile == null) throw new RuntimeException("Required GL profile is not supported.");
  20.     GLCapabilities capabilities = new GLCapabilities(profile);
  21.    
  22.     Window newtWindow = NewtFactory.createWindow(screen, capabilities);
  23.     GLWindow window = GLWindow.create(newtWindow);
  24.  
  25.     WindowAdapter exitListener = new WindowAdapter() {
  26.       public void windowDestroyNotify(WindowEvent e) { quit = true; }
  27.     };
  28.     KeyListener exitListener2 = new KeyListener() {
  29.       public void  keyPressed(KeyEvent e) {}
  30.       public void  keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) quit = true; }
  31.       public void  keyTyped(KeyEvent e) {}
  32.     };
  33.    
  34.     window.addWindowListener(exitListener);
  35.     window.addKeyListener(exitListener2);
  36.    
  37.     window.addKeyListener(wrappedInput);
  38.  
  39.     window.addGLEventListener(glEventListener);
  40.     window.setAutoSwapBufferMode(true);
  41.  
  42.     window.setPosition(0, 0);
  43.     window.setSize(800, 600);
  44.     window.setVisible(true);
  45.     window.setFullscreen(false); // must follow setVisible(true) on Linux
  46.     window.enablePerfLog(false);
  47.     window.requestFocus(); // does not work on Linux
  48.  
  49.    
  50.     while (!quit) { window.display(); }
  51.     window.destroy();
  52.   }
  53.  
  54.   private static final GLEventListener glEventListener = new GLEventListener() {
  55.     public void display(GLAutoDrawable arg0) { }
  56.     public void dispose(GLAutoDrawable arg0) { }
  57.     public void init(GLAutoDrawable arg0) { }
  58.     public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { }
  59.   };
  60.  
  61.   private static final KeyListener wrappedInput = new KeyListener() {
  62.     public void keyPressed(KeyEvent arg0) {
  63.         System.out.println("Q code: " + KeyEvent.VK_Q + ", pressed key code: " + arg0.getKeyCode());
  64.     }
  65.    
  66.     public void keyReleased(KeyEvent arg0) { }
  67.     public void keyTyped(KeyEvent arg0) { }
  68.   };
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement