Download Java programming language bindings for OpenGL (JOGL)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Video card wikipedia , lookup

Free and open-source graphics device driver wikipedia , lookup

Tektronix 4010 wikipedia , lookup

Molecular graphics wikipedia , lookup

Graphics processing unit wikipedia , lookup

Mesa (computer graphics) wikipedia , lookup

OpenGL wikipedia , lookup

Transcript
Java program language bindings for OpenGL (JOGL)
JOGL is a Java programming language binding for the OpenGL 3D graphics API (JSR231), and is designed to provide hardware-supported 3D graphics to applications written
in Java. JOGL provides full access to the APIs in the OpenGL specification as well as
nearly all vendor extensions. You can integrate JOGL with the AWT, Swing, and other
windowing kits, and numerous 3rd party applications like Processing.
The JOGL project is maintained by http://jogamp.org/
Download Jogamp
Go to http://jogamp.org/deployment/jogamp-current/archive/ and download the all-in-one
7z archive file: jogamp-all-platforms.7z. Unzip the archive in a suitable directory. Keep
this download site open for now.
You should have something like the following:
CS421 – Advanced Computer Graphics
Jay Urbain
1
Native JARs vs. native library files
JOGL uses native libraries to interface with each platform's OpenGL library. You can
either download these native libraries wrapped up in JAR files (the "native JARs"
option), or you can download them as separate .dll/.so/.jnilib files (the "native library
files" option).
When using native JARs, JOGL automatically unzips the native JARs at startup into a
temporary directory, and then loads the resulting .dll/.so/.jnilib files from there. When
using native library files, JOGL just loads them directly from their location. No
unzipping is required.
Using native JARs is usually easiest, since there are fewer files to manage and it allows
different platforms' native library files to coexist in the same directory. Only use the
native library files directly if you need fine control over native library file placement or if
your app doesn't have permissions to create temporary directories.
CS421 – Advanced Computer Graphics
Jay Urbain
2
Create a jogl Java Eclipse project



Add a lib folder to your jogl Eclipse project.
Copy gluegen-rt.jar and jogl-all.jar from the jar directory of your jogl archive
…\jogamp-all-platforms\jar to your project’s lib folder …\jogl\lib. These jar files
include dll’s for the underlying OpenGL C implementation, and the JOGL API
wrapper.
Copy the source distributions gluegen-java-src.zip and jogl-java-src.zip from the
archive root directory …\jogamp-all-platforms to your project lib directory.

Go back to http://jogamp.org/deployment/jogamp-current/archive/ and download
gluegen-javadoc.7z, jogl-javadoc.7z into your project lib directory. No need to
unzip.

Go to http://jogamp.org/deployment/jogamp-current/archive/Sources/ and
download jogl-demos-v2.0-rc10.tar.7z demos. You can unzip for now in any
suitable directory. Will get back to this later in the lab.


Refresh your project (right-mouse click – Refresh).
Add gluegen-rt.jar and jogl-all.jar to your Java Build Path. Select project
properties, Java Build Path, and the Libraries Tab. Expand each jar file and add
the source and javadoc. The contents of the Libraries Tab should look as follows:
CS421 – Advanced Computer Graphics
Jay Urbain
3

Expand each jar file (gluegen-rt.jar and jogl-all.jar) and add their src jars
(gluegen-java-src.zip and jogl-hava-src.zip) and their javadocs (gluegenjavadoc.7z and jogl-javadoc.7z) from your project lib directory.

Under your jogl project properties, make sure gluegen-rt.jar and jogl-all.jar are
listed and selected under the Order and Export Tab of your Java Build Path.
CS421 – Advanced Computer Graphics
Jay Urbain
4
Return to your jogl-demos directory. Import the gears directory under src into your
project src. You may have to adjust the package name depending on whether you
copy+Refresh or import the directory.
Run your app. If life is good, you should see rotating gears.
CS421 – Advanced Computer Graphics
Jay Urbain
5
Adding a project dependency





For each new project that you will be creating, you can create a project
dependency back to this jogl project to include everything you will need from
OpenGL.
Right-click your project and click "Properties".
Select the "Java Build Path" on the left, then click the "Projects" tab on the right.
Click the "Add..." button, check "JOGL", and click "OK".
Your dependent project should look like this. Click "OK" to dismiss the
"Properties" dialog.
CS421 – Advanced Computer Graphics
Jay Urbain
6
GLAutoDrawable
Jogl provides two basic widgets into which OpenGL rendering can be performed. The
GLCanvas is a heavyweight AWT widget which supports hardware acceleration and
which is intended to be the primary widget used by applications.
The GLJPanel is a fully Swing-compatible lightweight widget which supports hardware
acceleration but which is not as fast as the GLCanvas because it typically reads back the
frame buffer in order to draw it using Java2D. The GLJPanel is intended to provide 100%
correct Swing integration in the circumstances where a GLCanvas can not be used.
Both the GLCanvas and GLJPanel implement a common interface called
GLAutoDrawable so applications can switch between them with minimal code changes.
The GLAutoDrawable interface provides:





access to the GL object for calling OpenGL routines
a callback mechanism (GLEventListener) for performing OpenGL rendering
a display() method for forcing OpenGL rendering to be performed
synchronously
AWT- and Swing-independent abstractions for getting and setting the size of the
widget and adding and removing event listeners.
There are other mechanisms to access OpenGL through Web interfaces using
javascript and throught powerful third party applications like Processing.
Gears.java
Review Gears.java. In particular, review the methods you need to provide to implement
the javax.media.opengl.GLEventListener interface:
void display(GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void displayChanged(GLAutoDrawable drawable,
boolean modeChanged, boolean deviceChanged)
Called by the drawable when the display mode or the display device associated with the
GLAutoDrawable has changed.
void init(GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void reshape(GLAutoDrawable drawable, int x, int y,
int width, int height)
Called by the drawable during the first repaint after the component has been resized.
CS421 – Advanced Computer Graphics
Jay Urbain
7
Consider:

Running additional demos. A description of the examples can be found here:
http://download.java.net/media/jogl/demos/www/

Review the jogamp.org or the JavaWorld tutorials on JOGL:
http://jogamp.org/wiki/index.php/Jogl_Tutorial
http://www.javaworld.com/javaworld/jw-09-2008/jw-09-opensourcejavajogl.html?page=1
Document and demo your application.
Cheers,
Jay Urbain
CS421 – Advanced Computer Graphics
Jay Urbain
8