Welcome to my first Tutorial !
This tutorial will show you how to install Gl4java in your Java environment.
After this, I will explain you how to create an empty OpenGl scene in a Java application.
For beginner, it is better to go to
next tutorial and use the JOGL-JSR231 OpenGl API.
I use and modify the basic OpenGl loader created by Jeff Kirby and Darren Hodges and updated by Ron Sullivan.
First, you have to install Java. Go to Sun's
site and download the Java SDK (Software Development Kit).
Install Java 1.5 (also known as 5.0) or later.
Run the installation and add the environment variable PATH :
(My installation is here : C:\Java\jdk1.5.0_05)
This environment variable is used by your system to know where Java is installed and to know in
which folder he should search Java utilities like java, javac ...
Go to the System Properties (properties of "Poste de Travail",
"work station" or something like that in English). In the Advanced tab, click on the Environment variable button.
Create a new environment variable named PATH.
His value is something like that (depends on your installation folder) :
C:\Java\jdk1.5.0_05\bin;C:\Java\jdk1.5.0_05\jre\bin
If PATH already exist, add at the the begining (; is a path separator) :
C:\Java\jdk1.5.0_05\bin;C:\Java\jdk1.5.0_05\jre\bin;
Open the file :
C:/autoexec.bat
Into this file, add a line like:
SET PATH=C:\Java\jdk1.5.0_05\bin;C:\Java\jdk1.5.0_05\jre\bin
Remark :
You need to reboot your machine to takes this in account.
Copy these command line on a terminal (console) :
setenv PATH /home/java/jdk1.5.0_05/bin:/home/java/jdk1.5.0_05/jre/bin
or
export PATH=/home/java/jdk1.5.0_05/bin:/home/java/jdk1.5.0_05/jre/bin
Go to Gl4java page at http://www.jausoft.com/gl4java.php and download Gl4java.
The archives downloaded must contain these jar :
png.jar
gl4java.jar
gl4java-glffonts.jar
gl4java-glutfonts.jar
and these libraries (Windows): or for Linux :
GL4JavaJauGljJNI14.dll GL4JavaJauGljJNI14.so
WARNING :
Gl4java development has been stopped since a lot of time. Now, Gl4java site (www.jausoft.com)
is CLOSED, older version can be obtained at :
http://gl4java.sourceforge.net/.
I encourage you to use JOGL (JSR231).
Tutorial 02 introduce this OpenGL API.
Copy all jars in the folder :
C:\Java\jdk1.5.0_05\jre\lib\ext
//Windows
/home/java/jdk1.5.0_05/jre/lib/ext
//Linux
and the library in :
C:\Java\jdk1.5.0_05\jre\bin
//Windows
/home/java/j2sdk1.4.2_04/jre/lib/i386 //Linux
Note :
For people who have difficulties to find gl4java => Go
to next tutorial and use Jogl !
This first program load a frame with an empty OpenGl scene (ie black screen).
This is the base code for an OpenGl animated scene.
In the Tutorial 3, I will introduce a more complicated base code but I encouraged you to use this
for the beginning (the simpliest).
For people new in OpenGl, this could be hard to understand all of the code by the first reading. By learning OpenGL and looking at the following tutorials, it should be
easier to understand.
Don't be discouraged !
This tutorial is composed of two classes : one for loading the frame (or an applet), the other for the OpenGl scene.
An animated OpenGl scene can be created in a GLAnimCanvas component
(included in GL4Java API) :
gl4java.awt.GLAnimCanvas
This class extends java.awt.Component (more precisely extends gl4java.awt.GLCanvas
and java.awt.Canvas).
First, we have to create a frame, I used to use swing components, so let start with a JFrame
(this also works with AWT gui).
Tutorial1 class is an instance of GLAnimCanvs, it can be added into our frame.
The OpenGl animation is starten with the call start.
org.jouvieje.gl4java.container.FrameContainer |
package
org.jouvieje.gl4java.Container; |
We can also load an OpenGl scene in an Applet (JApplet here).
This can be done with this similar code :
org.jouvieje.gl4java.Container.AppletContainer |
package
org.jouvieje.gl4java.Container; |
Now the container is created, we will create our basic OpenGl scene.
This scene will just clear the background to black.
There are 3 importants methods to declare : reshape, init and display.
the reshape method : called at each resize
event (generally when the frame is resized).
This method defines the Viewport and the Viewing Volume. These two properties are relative to how the scene is drawn into the screen.
This method will be explicated in more details in the Lesson 1 & Lesson 2.
the init method : this method initialise all you need. You can put in it the initialisation of your data like importing texture, initialise OpenGl properties ...
Called one time at the initilization.
the display
method : this method is the drawing loop (loop for animation). It calls drawGlScene
in which we will add the drawing code for the OpenGl scene.
To have access to the OpenGl methods, we mainly use two objects of the GLAnimCanvas instance :
gl (GLFunc) : provides access to OpenGl functionality and graphics card extension.
glu (GLUFunc) : provides access to OpenGl utility library routine.
This two objects will be used for the initialisation, drawing ...
Here is the commented code :
org.jouvieje.gl4java.tutorials.Tutorial1 |
package
oorg.jouvieje.gl4java.tutorials; |
To run the application, just execute one of these files:
Tutorial01.jar (run the frame)
runFrame-Gl4java.bat (run the frame)
runApplet-Gl4java.bat (run the applet in a frame)
Tutorial01-Gl4java.html (run the applet)
If it fails, your environment may not be well installed !
If a windows is loaded with a black background, OpenGl is well installed. You
can go to next tutorials.
Tutorial 1 - src : Gl4java ( 7 ko)
Tutorial 1 - jar : Gl4java (10 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/ |