Skip to content

Instantly share code, notes, and snippets.

@kendzi

kendzi/Test.java Secret

Created September 23, 2015 14:34
Show Gist options
  • Save kendzi/ef37408e22cfe3af5f6e to your computer and use it in GitHub Desktop.
Save kendzi/ef37408e22cfe3af5f6e to your computer and use it in GitHub Desktop.
package kendzi.jogl.ui;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.awt.TextureRenderer;
public class Test implements GLEventListener {
@Override
public void init(GLAutoDrawable drawable) {
TextureRenderer tr = new TextureRenderer(128, 128, true, true);
}
@Override
public void display(GLAutoDrawable drawable) {
}
public static void main(String[] args) {
Test sj = new Test();
sj.initUi();
}
public void initUi() {
Frame frame = new Frame("Simple JOGL Application");
GLCanvas canvas = createCanvas();
canvas.addGLEventListener(this);
frame.add(canvas);
frame.setSize(640, 480);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
/*
* Run this on another thread than the AWT event queue to make
* sure the call to Animator.stop() completes before exiting.
*/
new Thread(new Runnable() {
@Override
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
canvas.setFocusable(true);
canvas.requestFocus();
}
public static GLCanvas createCanvas() {
// create a profile, in this case OpenGL 2 or later
GLProfile profile = GLProfile.get(GLProfile.GL2);
// configure context
GLCapabilities capabilities = new GLCapabilities(profile);
// setup z-buffer
capabilities.setDepthBits(16);
// initialize a GLDrawable of your choice
GLCanvas canvas = new GLCanvas(capabilities);
return canvas;
}
@Override
public void dispose(GLAutoDrawable drawable) {
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment