Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.media.opengl.*;
- import com.jogamp.newt.*;
- import com.jogamp.newt.event.*;
- import com.jogamp.newt.opengl.*;
- class Example {
- private static volatile boolean quit = false;
- public static void main(String[] args) {
- NewtFactory.setUseEDT(true);
- Display display = NewtFactory.createDisplay(null);
- Screen screen = NewtFactory.createScreen(display, 0);
- GLProfile profile = GLProfile.get(GLProfile.GL2ES2);
- if (profile == null) throw new RuntimeException("Required GL profile is not supported.");
- GLCapabilities capabilities = new GLCapabilities(profile);
- Window newtWindow = NewtFactory.createWindow(screen, capabilities);
- GLWindow window = GLWindow.create(newtWindow);
- WindowAdapter exitListener = new WindowAdapter() {
- public void windowDestroyNotify(WindowEvent e) { quit = true; }
- };
- KeyListener exitListener2 = new KeyListener() {
- public void keyPressed(KeyEvent e) {}
- public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) quit = true; }
- public void keyTyped(KeyEvent e) {}
- };
- window.addWindowListener(exitListener);
- window.addKeyListener(exitListener2);
- window.addKeyListener(wrappedInput);
- window.addGLEventListener(glEventListener);
- window.setAutoSwapBufferMode(true);
- window.setPosition(0, 0);
- window.setSize(800, 600);
- window.setVisible(true);
- window.setFullscreen(false); // must follow setVisible(true) on Linux
- window.enablePerfLog(false);
- window.requestFocus(); // does not work on Linux
- while (!quit) { window.display(); }
- window.destroy();
- }
- private static final GLEventListener glEventListener = new GLEventListener() {
- public void display(GLAutoDrawable arg0) { }
- public void dispose(GLAutoDrawable arg0) { }
- public void init(GLAutoDrawable arg0) { }
- public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { }
- };
- private static final KeyListener wrappedInput = new KeyListener() {
- public void keyPressed(KeyEvent arg0) {
- System.out.println("Q code: " + KeyEvent.VK_Q + ", pressed key code: " + arg0.getKeyCode());
- }
- public void keyReleased(KeyEvent arg0) { }
- public void keyTyped(KeyEvent arg0) { }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement