1 / 12

Java + OpenGL = JOGL

Java and OpenGL Rich Truban Andrew Potozniak. Java + OpenGL = JOGL. Getting Started. Java 5 SDK http://java.sun.com/j2se/1.5.0/download.jsp Eclipse IDE http://www.eclipse.org/ ( http://download.eclipse.org/eclipse/downloads/drops/R-3.0.1-200409161125/eclipse-SDK-3.0.1-win32.zip )

cady
Download Presentation

Java + OpenGL = JOGL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Getting Started Java 5 SDK http://java.sun.com/j2se/1.5.0/download.jsp Eclipse IDE http://www.eclipse.org/ (http://download.eclipse.org/eclipse/downloads/drops/R-3.0.1-200409161125/eclipse-SDK-3.0.1-win32.zip) JOGL’s Main site https://jogl.dev.java.net/

  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, you’re 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. Let’s 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 (http://java.sun.com/j2se/1.5.0/docs/api/) • Let’s just face it. It’s a lot better than Python <smirk>

More Related