Jogl Tutorial
Jogl Tutorial
Tutorial
Introduction
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Introduction
Tutorial
JOGL: ( http://jogl.dev.java.net )
Good integration with AWT/Swing Under development by employees at Sun Will be used as basis for JSR-231 for integration into Java standard distribution (Java 6.0?) Under BSD license.
Introduction
Tutorial
JOGL: ( http://jogl.dev.java.net )
Good integration with AWT/Swing Under development by employees at Sun Will be used as basis for JSR-231 for integration into Java standard distribution (Java 6.0?) Under BSD license.
Introduction
Tutorial
JSR-231
Java Community Process (http://jcp.org ) JSR: Java Specication Request JSR-231: Java bindings to OpenGL (http://www.jcp.org/en/jsr/detail?id=231)
JOGL codebase recently forked to JSR-231. Large and small API changes. Package name moving to javax.media.opengl. (Currently: net.java.games.jogl) Future releases after JOGL 1.1.1 will be under the JSR-231 API.
Introduction
Tutorial
JSR-231
Java Community Process (http://jcp.org ) JSR: Java Specication Request JSR-231: Java bindings to OpenGL (http://www.jcp.org/en/jsr/detail?id=231)
JOGL codebase recently forked to JSR-231. Large and small API changes. Package name moving to javax.media.opengl. (Currently: net.java.games.jogl) Future releases after JOGL 1.1.1 will be under the JSR-231 API.
Introduction
Tutorial
JSR-231
Java Community Process (http://jcp.org ) JSR: Java Specication Request JSR-231: Java bindings to OpenGL (http://www.jcp.org/en/jsr/detail?id=231)
JOGL codebase recently forked to JSR-231. Large and small API changes. Package name moving to javax.media.opengl. (Currently: net.java.games.jogl) Future releases after JOGL 1.1.1 will be under the JSR-231 API.
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Java class library: jogl.jar (platform independent) JOGL shared native libraries (platform specic)
Windows: libjogl.dll and libjogl_cg.dll. Linux/UNIX: libjogl.so and libjogl_cg.so Mac OS X: libjogl.jnilib and libjogl_cg.jnilib
Useage:
Place jogl.jar in CLASSPATH. Place directory containing native libraries in system property java.library.path.
Specify java.library.path on command line, or Place native libs in default location.
Tutorial
Java class library: jogl.jar (platform independent) JOGL shared native libraries (platform specic)
Windows: libjogl.dll and libjogl_cg.dll. Linux/UNIX: libjogl.so and libjogl_cg.so Mac OS X: libjogl.jnilib and libjogl_cg.jnilib
Useage:
Place jogl.jar in CLASSPATH. Place directory containing native libraries in system property java.library.path.
Specify java.library.path on command line, or Place native libs in default location.
Tutorial
Java class library: jogl.jar (platform independent) JOGL shared native libraries (platform specic)
Windows: libjogl.dll and libjogl_cg.dll. Linux/UNIX: libjogl.so and libjogl_cg.so Mac OS X: libjogl.jnilib and libjogl_cg.jnilib
Useage:
Place jogl.jar in CLASSPATH. Place directory containing native libraries in system property java.library.path.
Specify java.library.path on command line, or Place native libs in default location.
Tutorial
Java class library: jogl.jar (platform independent) JOGL shared native libraries (platform specic)
Windows: libjogl.dll and libjogl_cg.dll. Linux/UNIX: libjogl.so and libjogl_cg.so Mac OS X: libjogl.jnilib and libjogl_cg.jnilib
Useage:
Place jogl.jar in CLASSPATH. Place directory containing native libraries in system property java.library.path.
Specify java.library.path on command line, or Place native libs in default location.
Tutorial
Packages:
net.java.games.jogl : Core classes. net.java.games.jogl.util : Buffer utilities and GLUT. net.java.games.cg : Classes for use with Cg shading language. net.java.games.glugen.runtime : JavaOpenGL JNI integration code.
Tutorial
Packages:
net.java.games.jogl : Core classes. net.java.games.jogl.util : Buffer utilities and GLUT. net.java.games.cg : Classes for use with Cg shading language. net.java.games.glugen.runtime : JavaOpenGL JNI integration code.
Tutorial
Packages:
net.java.games.jogl : Core classes. net.java.games.jogl.util : Buffer utilities and GLUT. net.java.games.cg : Classes for use with Cg shading language. net.java.games.glugen.runtime : JavaOpenGL JNI integration code.
Tutorial
Packages:
net.java.games.jogl : Core classes. net.java.games.jogl.util : Buffer utilities and GLUT. net.java.games.cg : Classes for use with Cg shading language. net.java.games.glugen.runtime : JavaOpenGL JNI integration code.
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Download zip le from: http://www.cs.plu.edu/~dwolff/talks/jogl-ccsc Import into Eclipse jogl.jar is included Execution: add to JVM command line args: -Djava.library.path=<path to native libs dir> Pre-made Eclipse launch congs.
Tutorial
Download zip le from: http://www.cs.plu.edu/~dwolff/talks/jogl-ccsc Import into Eclipse jogl.jar is included Execution: add to JVM command line args: -Djava.library.path=<path to native libs dir> Pre-made Eclipse launch congs.
Tutorial
Download zip le from: http://www.cs.plu.edu/~dwolff/talks/jogl-ccsc Import into Eclipse jogl.jar is included Execution: add to JVM command line args: -Djava.library.path=<path to native libs dir> Pre-made Eclipse launch congs.
Tutorial
Download zip le from: http://www.cs.plu.edu/~dwolff/talks/jogl-ccsc Import into Eclipse jogl.jar is included Execution: add to JVM command line args: -Djava.library.path=<path to native libs dir> Pre-made Eclipse launch congs.
Tutorial
Download zip le from: http://www.cs.plu.edu/~dwolff/talks/jogl-ccsc Import into Eclipse jogl.jar is included Execution: add to JVM command line args: -Djava.library.path=<path to native libs dir> Pre-made Eclipse launch congs.
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Interface GLDrawable
Key implementing classes:
GLCanvas - heavyweight component. Subclass of java.awt.Canvas.
Some drawing problems when mixing with lightweight components.
Selected methods:
void addGLEventListener(GLEventListener) GL getGL() void setGL(GL gl) boolean canCreateOffscreenDrawable() GLPbuffer createOffscreenDrawable( ...)
Tutorial
Creating a GLCanvas
Tutorial
Creating a GLCanvas
Tutorial
Creating a GLCanvas
Tutorial
Creating a GLCanvas
Tutorial
Creating a GLCanvas
Tutorial
public void reshape( GLDrawable d, int x, int y, int width, int height)
Called after init and on resize event. (x and y are always zero?).
Tutorial
public void reshape( GLDrawable d, int x, int y, int width, int height)
Called after init and on resize event. (x and y are always zero?).
Tutorial
public void reshape( GLDrawable d, int x, int y, int width, int height)
Called after init and on resize event. (x and y are always zero?).
Tutorial
public void reshape( GLDrawable d, int x, int y, int width, int height)
Called after init and on resize event. (x and y are always zero?).
Tutorial
public void reshape( GLDrawable d, int x, int y, int width, int height)
Called after init and on resize event. (x and y are always zero?).
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Calling GL Functions
First param for each GLEventListener method: GLDrawable.
The GLJPanel or GLCanvas.
GLDrawable provides access to GL and GLU objects. All GL functions available through GL object.
GL gl = drawable.getGL(); gl.glPushMatrix(); gl.glBegin( GL.GL_TRIANGLES ); ... gl.glEnd(); gl.glPopMatrix(); Recommendation: always retrieve GL object, rather than store as instance variable.
Tutorial
Calling GL Functions
First param for each GLEventListener method: GLDrawable.
The GLJPanel or GLCanvas.
GLDrawable provides access to GL and GLU objects. All GL functions available through GL object.
GL gl = drawable.getGL(); gl.glPushMatrix(); gl.glBegin( GL.GL_TRIANGLES ); ... gl.glEnd(); gl.glPopMatrix(); Recommendation: always retrieve GL object, rather than store as instance variable.
Tutorial
Calling GL Functions
First param for each GLEventListener method: GLDrawable.
The GLJPanel or GLCanvas.
GLDrawable provides access to GL and GLU objects. All GL functions available through GL object.
GL gl = drawable.getGL(); gl.glPushMatrix(); gl.glBegin( GL.GL_TRIANGLES ); ... gl.glEnd(); gl.glPopMatrix(); Recommendation: always retrieve GL object, rather than store as instance variable.
Tutorial
Calling GL Functions
First param for each GLEventListener method: GLDrawable.
The GLJPanel or GLCanvas.
GLDrawable provides access to GL and GLU objects. All GL functions available through GL object.
GL gl = drawable.getGL(); gl.glPushMatrix(); gl.glBegin( GL.GL_TRIANGLES ); ... gl.glEnd(); gl.glPopMatrix(); Recommendation: always retrieve GL object, rather than store as instance variable.
Tutorial
Calling GL Functions
First param for each GLEventListener method: GLDrawable.
The GLJPanel or GLCanvas.
GLDrawable provides access to GL and GLU objects. All GL functions available through GL object.
GL gl = drawable.getGL(); gl.glPushMatrix(); gl.glBegin( GL.GL_TRIANGLES ); ... gl.glEnd(); gl.glPopMatrix(); Recommendation: always retrieve GL object, rather than store as instance variable.
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Good performance compared to GLJPanel Integrates with Swing well in nearly all situations. Exceptions:
JInternalFrames JPopupMenus and swing tooltips.
Workarounds: JPopupMenu:
setLightWeightPopupEnabled(false) setDefaultLightWeightPopupEnabled(false)
ToolTipManager
setLightWeightPopupEnabled(false)
Tutorial
Good performance compared to GLJPanel Integrates with Swing well in nearly all situations. Exceptions:
JInternalFrames JPopupMenus and swing tooltips.
Workarounds: JPopupMenu:
setLightWeightPopupEnabled(false) setDefaultLightWeightPopupEnabled(false)
ToolTipManager
setLightWeightPopupEnabled(false)
Tutorial
Good performance compared to GLJPanel Integrates with Swing well in nearly all situations. Exceptions:
JInternalFrames JPopupMenus and swing tooltips.
Workarounds: JPopupMenu:
setLightWeightPopupEnabled(false) setDefaultLightWeightPopupEnabled(false)
ToolTipManager
setLightWeightPopupEnabled(false)
Tutorial
Good performance compared to GLJPanel Integrates with Swing well in nearly all situations. Exceptions:
JInternalFrames JPopupMenus and swing tooltips.
Workarounds: JPopupMenu:
setLightWeightPopupEnabled(false) setDefaultLightWeightPopupEnabled(false)
ToolTipManager
setLightWeightPopupEnabled(false)
Tutorial
Good performance compared to GLJPanel Integrates with Swing well in nearly all situations. Exceptions:
JInternalFrames JPopupMenus and swing tooltips.
Workarounds: JPopupMenu:
setLightWeightPopupEnabled(false) setDefaultLightWeightPopupEnabled(false)
ToolTipManager
setLightWeightPopupEnabled(false)
Tutorial
Tutorial
Tutorial
Tutorial
Threading Issues
All of the GLEventListener methods are executed on the AWT event dispatching thread. Future versions may change this. setRenderingThread() is currently a no-op. This is a change from previous versions in response to a variety of threading issues.
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Causes continual calls to display() As fast as possible, no FPS limit. Give GLDrawable instance to Animator upon creation. Can be started and stopped repeatedly. Can not be started until GLCanvas is realized Starting at the end of init() seems to work well
Tutorial
Uses java.util.Timer Calls GLDrawable.display() every x microseconds based on fps. JOGL communitys FPSAnimator possibly unstable.
Seems to fail when stopping and restarting on some OSs.
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Composable Pipelines
Add additional behaviors to GL pipeline. Wrap the GL object with new pipeline
drawable.setGL( new <Pipline>(drawable.getGL() ) )
Tutorial
DebugGL
drawable.setGL( new DebugGL(drawable.getGL() ) ) Calls glGetError() after each OpenGL call Throws GLException when an error is found This is a distinct advantage over C
TraceGL
drawable.setGL( new TraceGL(drawable.getGL() ) ) Prints logging info after each OpenGL call.
Tutorial
DebugGL
drawable.setGL( new DebugGL(drawable.getGL() ) ) Calls glGetError() after each OpenGL call Throws GLException when an error is found This is a distinct advantage over C
TraceGL
drawable.setGL( new TraceGL(drawable.getGL() ) ) Prints logging info after each OpenGL call.
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Slow?
Tutorial
BufferedImage provides access to pixel data in a variety of formats. JOGL prefers java.nio direct buffers. This example uses ByteBuffer:
ByteBuffer.allocateDirect( nBytes );
Unpack pixels from BufferedImage and pack into ByteBuffer. BufferedImage.getRGB(row,col) returns int pixel in ARGB format.
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Support depends on graphics card JOGL API is experimental, may change Check for support: drawable.canCreateOffscreenDrawable() drawable.createOffscreenDrawable(caps, w, h) Returns GLPbuffer The main drawable, and the Pbuffer may have separate GLEventListeners. Texture data and display lists are shared.
Tutorial
Direct render to texture is supported in limited hardware. This example: render to Pbuffer, copy pixels to texture. At end of display() in Pbuffer: glCopyTexImage2D(...)
Tutorial
Screenshot
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Sharing of display lists, texture data, etc. Second parameter to createGLCanvas(), is canvas to share with.
...createGLCanvas(caps, otherCanvas)
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Helper methods for creating buffers: net.java.games.jogl.util.BufferUtils Vertex, normal arrays: java.nio.DoubleBuffer Index array: java.nio.IntBuffer Creation: vertexBuffer = BufferUtils.newDoubleBuffer( nDoubles ) Append triple: vertexBuffer.put( vertex ) Give to OpenGL: gl.glVertexPointer(3, GL.GL_DOUBLE, 0, vertexBuffer)
Tutorial
Outline
1 2
Introduction Tutorial Installing JOGL Tutorial Files Example 1: Basic Framework Example 2: Hello JOGL Example 3: Swing and JOGL Example 4: Animation Example 5: Composable Pipelines Example 6: Textures Example 7: PBuffers Example 8: Multiple Canvases and Shared Data Example 9: Vertex Arrays Example 10: Screen Capture Summary and Discussion
Tutorial
Tutorial
Tutorial
Introduction
Tutorial
Deploy JOGL apps via web link. JNLP (Java Network Launch Protocol) le:
XML based Point to jar le and JOGL libraries. Pre-dened jnlp for JOGL libs hosted at: https://jogl.dev.java.net/webstart/jogl.jnlp Will select appropriate native libs. Avoids security headaches (signed by Sun with VeriSign cert.)
Introduction
Tutorial
Scenegraph Support
Introduction
Tutorial
Game Programming
Quake 2 engine developed by Clark et al. for instructional purposes, written in JOGL. (JCSC V. (20) 2, December 2004) Full featured Quake 2 engine (open source) called Jake 2, developed using JOGL.
http://www.bytonic.de Benchmarks: Fast JOGL 250 fps vs Original C code 315 fps.
Introduction
Tutorial
Pro
Spend less time on C++ review, and more on graphics Can use the Java Collection classes instead of the STL No need for a windowing toolkit such as GLUT, Qt, etc. Graphics is difcult enough without C++
Con
C++ is industry standard for 3D graphics Performance Its good for em
Introduction
Tutorial
Pro
Spend less time on C++ review, and more on graphics Can use the Java Collection classes instead of the STL No need for a windowing toolkit such as GLUT, Qt, etc. Graphics is difcult enough without C++
Con
C++ is industry standard for 3D graphics Performance Its good for em
Introduction
Tutorial
Previous experiments: GLUT, Qt At PLU: CS1/2 are taught in Java. STL skills? Java Collection API: Familiar, no extra instruction Student job market preparation
Introduction
Tutorial
Thanks!