How to use Java OpenGL

looneyvillestaticSoftware and s/w Development

Aug 15, 2012 (4 years and 10 months ago)

443 views

How use Java OpenGL (JOGL
)

Java OpenGL

(
JOGL
) is a wrapper
library

that allows
OpenGL

to be used in the
Java


We will use Netbeans as our programming IDE, since it is more convenient
to
install Netbeans
plugin to use JOGL. Fo
r hardcore eclipse users, I am afraid it is more complicated. You need to
follow the instructions from this website:
http://pixel.cs.vt.edu/courses/3744/install
-
eclipse.html
.


Assume

you have already installed Netbeans:

Step 1:

Download
NetBeans OpenGL Pack

from

http://kenai.com/projects/netbeans
-
opengl
-
pack/pages/Home

Step 2:

Install
NetBeans OpenGL Pack
. You
might need to uncheck the GLSL Editor plugin option.

Setp 3:

Create a new JOGL project: File
-
> New Project. Then select Java Project
-
> JOGL
Application
. Alternative, you can chose other types of JOGL projects
.

Step

4
:

You can compile the template provided by the plugin.


Tutorial:

To learn more about JOGL, you can take a look at this excellent tutorial:

http://robot.unipv.it/index.php/didattica/gra
fica
-
3d/54


To learn more advance techniques about OpenGL, e.g., OpenGL ES for iOS and Android, you can
take a look at:

http://nehe.gamedev.net/


Some explanation about the function in your template:


Init

is an ini
talization function
. When your JOGL program starts up,
OpenGL/Jogl will call
Init
function to set up the graphics information, such as
global settings and initalize the GL instance
with your programs options.


Display

is very similar to
java.awt.Component.paint()

in that it is called each time the canvas
needs to b
e repainted
.


Reshape

is
called when you r
esize the display window.
We

need to ch
ange the viewport size to
match the window size.


DisplayChanged
: In some cases, the display mode can change while the program is running.
Y
ou
can
ignore this bit to
have an empty
function
.


To undertand lighting:
http://www.oogtech.org/content/tag/gllightfv/