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) :
If PATH already exist, add at the the begining (; is a path separator) :
Open the file :
Into this file, add a line like:
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
Go to Gl4java page at http://www.jausoft.com/gl4java.php and download Gl4java.
The archives downloaded must contain these jar :
and these libraries (Windows): or for Linux :
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 :
and the library in :
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) :
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.
We can also load an OpenGl scene in an Applet (JApplet here).
This can be done with this similar code :
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 :
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.
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/|