Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java + OpenGL = JOGL Java and OpenGL Rich Truban Andrew Potozniak.

Similar presentations

Presentation on theme: "Java + OpenGL = JOGL Java and OpenGL Rich Truban Andrew Potozniak."— Presentation transcript:

1 Java + OpenGL = JOGL Java and OpenGL Rich Truban Andrew Potozniak

2 Getting Started Java 5 SDK Eclipse IDE ( /eclipse-SDK /eclipse-SDK JOGLs Main site

3 Installing JOGL Download: –The JAR file: jogl.jar –The Natives: jogl-natives-linux.jar jogl-natives-win32.jar

4 Installing JOGL into the JRE Find the directory where your JRE is installed. Windows & Linux (Global Install) –Drop the JOGL.jar file into: jre1.5.0/lib/ext/ –Drop the natives into: jre1.5.0/bin/

5 Incorporating JOGL into Eclipse Make a new Java Project –Create a lib/ directory –Import the sample code Drop JOGL.jar into the lib directory –You can drop the natives into this directory as well. Had to do this as well as another little trick to make JOGL work in Linux.

6 Simple JOGL test code public class JOGLTest { public static void main(String args[]) { try { //Load the libraries System.loadLibrary("jogl"); System.out.println("Hello World! (The native libraries are installed.)"); //Test for the presence of the JAR GLCapabilities glCaps = new GLCapabilities(); System.out.println("Hello JOGL! (The jar appears to be available.)"); } catch (Exception e) { System.out.println(e); }

7 Testing JOGL Run the sample program If it fails, make sure you installed the JOGL.jar and JOGL natives in the correct places. If it runs, youre well on your way to make OGL programs in Java

8 Setting up a GLCanvas public class Main extends JFrame { private static GLCanvas glCanvas; private GraphicEngine ge; public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GLCapabilities glCaps = new GLCapabilities(); glCaps.setDoubleBuffered(true); glCaps.setHardwareAccelerated(true); glCanvas = GLDrawableFactory.getFactory().createGLCanvas(glCaps); ge = new GraphicEngine(); glCanvas.addGLEventListener(ge); getContentPane().add(glCanvas); setSize(640, 480); } public static void main(String args[]) { Main main = new Main(); main.setVisible(true); while(true){glCanvas.repaint();} }

9 Setting up the GLEventListener public class GraphicEngine implements GLEventListener{ public void init(GLDrawable gld){ gld.getGL().glClearColor(0.0f, 0.0f, 0.0f, 1.0f); } public void display(GLDrawable gld){ GL gl = gld.getGL(); GLU glu = gld.getGLU(); GLUT glut = new GLUT(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glLoadIdentity(); } //Have to implement these methods for the GLEventListener public void displayChanged(GLDrawable gld, boolean arg1, boolean arg2) { } public void reshape(GLDrawable gld, int x, int y, int width, int height) { } }

10 Any questions so far? Except for that one Anton! Why did we do that? Because we can!

11 Lets add some spice to the mix! Adding a GL_QUADS call Adding a GLUT object

12 Advantages of using Java User-friendly and Robust Development Environment Platform independent Javadoc API ( Lets just face it. Its a lot better than Python

Download ppt "Java + OpenGL = JOGL Java and OpenGL Rich Truban Andrew Potozniak."

Similar presentations

Ads by Google