package com.tdmd.test; import com.jogamp.nativewindow.util.Rectangle; import com.jogamp.newt.Display; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; import com.jogamp.newt.Window; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.event.WindowListener; import com.jogamp.newt.event.WindowUpdateEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.GL2; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLProfile; public class TestNewt implements WindowListener, GLEventListener, MouseListener { public static void main(String[] args) { new TestNewt(); } public TestNewt() { GLProfile glp = GLProfile.get(GLProfile.GL2); GLCapabilities caps = new GLCapabilities(glp); Display dpy = NewtFactory.createDisplay(null); Screen screen = NewtFactory.createScreen(dpy, 0); GLWindow win = GLWindow.create(screen, caps); win.setTitle("Test Me"); win.setPosition(100, 100); win.setSize(300, 300); win.addWindowListener(this); win.addGLEventListener(this); win.addMouseListener(this); win.setVisible(true); while (win.isVisible()) { try { Thread.sleep(500); } catch (InterruptedException e){} } } @Override public void windowResized(WindowEvent e) { if (!Window.class.isInstance(e.getSource())) return; Rectangle rect = ((com.jogamp.newt.Window)e.getSource()).getBounds(); System.out.println(String.format("Resized: (%d %d), %d x %d", rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight())); } @Override public void windowMoved(WindowEvent e) { if (!Window.class.isInstance(e.getSource())) return; Rectangle rect = ((com.jogamp.newt.Window)e.getSource()).getBounds(); System.out.println(String.format("Moved: (%d %d), %d x %d", rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight())); } @Override public void windowDestroyNotify(WindowEvent e){} public void windowDestroyed(WindowEvent e){} public void windowGainedFocus(WindowEvent e){} public void windowLostFocus(WindowEvent e){} public void windowRepaint(WindowUpdateEvent e){} @Override public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); } @Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); } public void dispose(GLAutoDrawable drawable){} public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){} @Override public void mouseClicked(MouseEvent e) { Rectangle rect = ((com.jogamp.newt.Window)e.getSource()).getBounds(); System.out.println(String.format("Clicked: (%d %d), %d x %d", rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight())); } @Override 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){} }