I use the basic OpenGl container created by Kevin Duling to learn how to use Jogl.
You have the choice to use the old Jogl or Jogl JSR-231.
See Tutorial 01
First, go to Jogl page at https://jogl.dev.java.net/ and download
Jogl files (Don't download JSR 231).
The archives download must contain the jar :
jogl.jar
and these libraries (Windows): or for Linux :
jogl.dll libjogl.so
jogl_cg.dll libjogl_cg.so
(cg library is not used by any of my tutorials)
Place the jar in the folder :
C:\Program Files\java\j2sdk1.4.2_04\jre\lib\ext
and the libraries in :
C:\Program Files\java\j2sdk1.4.2_04\jre\bin
Note :
For people who have difficulties to find the old Jogl files, you
can find unofficial files
here. These files are distributed here without any guaranty.
The best way is probably to use Jogl JSR-231.
First, go to Jogl page at https://jogl.dev.java.net/ and download
Jogl JSR 231.
The archives download must contain the jar :
jogl.jar
gluegen-rt.jar
and these libraries (Windows): or for Linux :
jogl.dll libjogl.so
jogl_awt.dll libjogl_awt.so
jogl_cg.dll libjogl_cg.so
gluegen-rt.dll
gluegen-rt.so
(cg library is not used by any of my tutorials)
Place the jar in the folder :
C:\Program Files\java\j2sdk1.4.2_04\jre\lib\ext
and the libraries in :
C:\Program Files\java\j2sdk1.4.2_04\jre\bin
This tutorial contains only changes from gl4java to Jogl. To
know what is in '...', take a look at the Tutorial 1
(same code for Gl4java and Jogl).
The differences between Gl4java and Jogl start with the creation of the component that holds the OpenGl scene.
In Jogl, the component class is the class :
net.java.games.jogl.GLCanvas
//Jogl
javax.media.opengl.GLCanvas
//Jogl JSR-231
In Jogl, GLCanvas is a final class and the constructor is hidden. So, we can't
use new operator to instance a new
GLCanvas. To create a
GLCanvas, we use
GLDrawableFactory.
The code is similar to the first tutorial, I keep
here OpenGL related code :
org.jouvieje.jogl/jsr231.tutorials.******Container.java |
//Jogl import |
We have seen in Gl4java that we use differents methods like :
reshape, init, display
In Jogl, these method are events and defined by the interface :
net.java.games.jogl.GLEventListener
//Jogl
javax.media.opengl.GLEventListener
//Jogl JSR-231
The events are :
init <=> init (in Gl4java)
reshape <=> reshape (in Gl4java)
displayChanged <=> no equivalent in Gl4java
display <=> drawGlScene (in Gl4java)
To defines these methods, creates a class that implements the
GLEventListener interface.
Underneath, we will define these events like for the tutorial 1.
The code in the events is similar.
The difference is that the GL &
GLU objects is replaced by a GLDrawable object,
which provide access to the GL &
GLU object.
Another difference is that the display method is not called in loop. The scene is only render one time.
To animate it, an
Animator object is here to call display in
loop :
Animator animator = new Animator(glDrawable);
animator.start(); //start the animation loop
To stop the animation, we only have to call :
animator.stop(); //stop the animation loop
Please refer you to the first tutorial for the complete commented code (common part).
org.jouvieje.jogl/jsr231.tutorials.Tutorial2 |
package
org.jouvieje.jogl/jsr231.tutorials; |
See Tutorial 1
Tutorial 2 - src : Jogl & Jogl JSR231 ( 9 ko) //Port to Jogl JSR-231 initially done by Magarrett Dias
Tutorial 2 - jar : Jogl & Jogl JSR231 (19 ko)
If you've got any remarks on this tutorial, please let
me know to improve
it.
Thanks in advance for your feedback.
Copyright © 2004-2012 Jérôme Jouvie - All rights reserved. | http://jerome.jouvie.free.fr/ |