1. Introduction to JOGL and 3d Concepts
● Bill Adams
Bill.Adams@octanner.com
Manager of Innovation
O.C. Tanner Company
● Kenneth Russell
JOGL Project Lead
Sun Microsystems, Inc.
UJUG.org 2007-6-21
2. Webstart Demos
● F16 Sim
http://www.simulation.com/download/Demos/F16WorldWindDemo/F16WorldWindDemo.jnlp
● WorldWind
http://worldwind.arc.nasa.gov/java/0.2.0/webstart/BasicDemo.jnlp
● Jake2
http://bytonic.de/html/jake2.html
● The source to get SunSPOT feedback which could be fed
to a camera rotation method will be posted the week
June 25th.
● Kindly notify Bill Adams of any errors found in this
material
3. 3d Computer Graphics Becoming Mainstream
● Applications
– NASA World Wind
– ITunes 7, Iris
– Google Earth, Sketch
– 3d Charts & graphs
– Looking Glass
● Operating systems
– Linux Beryl & XGL, OSX, Vista
● Movies
– Toy story, Madagascar, Cars, etc.
● Gadgets
– GPS, phones/pda's, PSP, I-Phone
4. State of the Hardware Industry
● Hardware is Ready
– Multi-core CPU's now standard
– All new computers support GPU 3d support
– $40 Extremely fast GPU video cards
– $150 HD flat panel monitors
– AMD buys ATI (GPU+CPU on-die rumored)
– NVidia – CUDA GPU math libraries
– Scalable Link Interface – multi-GPU solutions
5. Video Game Market
● The Market is Ready ($7.4 billion in 2007)
– 2004, PC games sales = $1.1 billion (45 million
units)
– 2004, $1 billion (42.3 million units) in portable
software sales
– In 2004, 34% of heads of households play
games on a wireless device
– In 2004, 19% of Americans over age of 50
played video games
– In 2007, 171+ million consoles sold
* (Entertainment Software Association)
6. Java = Digital Distribution Opportunity
Stewart Alsop - 2nd Annual Video Game Investor Conference
"We believe the change to digital presents the next billion dollar
opportunity. Ironically, even though video games are
inherently digital... the video game industry is stuck in
what I call analog distribution. You have to encode it on a CD/DVD, put it in
a jewel case and ship it physically to the store distribution system," Alsop began.
"So we believe that once the video game business writes their games and
delivers them to people through the Internet and through digital
distribution systems, that the character of the business will be dramatically different, and
that's what presents the opportunity to build a new
billion dollar company."
7. JOGL – What It Is
JOGL: Java™ Binding to the OpenGL® API
● OpenGL: Industry standard, cross-platform 3D API
– Low-level C API designed for real-time 3D graphics
● JOGL: thin wrapper exposing OpenGL to Java
– Access latest features of graphics cards
– Helpful utilities: textures, text, Java 2D interop
– Java -> JOGL -> OpenGL -> OS -> Video card
● High performance (comparable to C/C++)
● Write your 3D program once, run it everywhere
(Windows, Mac OS X, Linux, Solaris)
● Deliver 3D over the Web with no installation
– In web pages as applets
– As full applications with Java Web Start
8. JOGL – What It Is Not
● Not a full scene graph –
much lighter than
java3d or jmonkey
● Not a 3D game engine
● Not a ray-tracer – photo
quality, slow renderer
● Not a modelling
application
● No collision detection or
physics used in games
9. JOGL – Where to Start
● Download and install JOGL for
development
– Follow JOGL User's Guide
– Don't drop directly into JRE
● http://pepijn.fab4.be (JOGL NeHe ports)
● http://jogl-demos.dev.java.net/
– More demos, OpenGL Red Book Examples, ...
10. JOGL – Where to Start
● Example usage:
class MyRenderer implements GLEventListener
● Override init, reshape and display methods
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new
MyRenderer());
frame.add(canvas);
frame.setVisible(true);
new Animator(canvas).start();
11. 3d Basics – Where to Start
● Play: modelling, rendering and mesh
formats with:
– Blender & Gimp (both free)
– Lightwave, Maya, 3d Studio Max, Rhino
(commercial)
● Become familiar with OpenGL
http://www.opengl.org/
● Add to JOGL app
12. 3d Basics – Meshes
● A mesh is:
– Vertex (an x,y,z point)
– Edge (2 vertices)
– Face (3 or more edges)
– Normal & UV texture coordinates
● Create or download and convert existing meshes
– www.blender.org (modeller/converter for file loader)
– http://www.3dcafe.com/ (free meshes)
● Importing a mesh requires a file loader (ie. 3DS)
● Draw vertices for each face
GL.glBegin(GL_TRIANGLES); // Drawing Using Triangles
GL.glVertex3f( 0.0f, 1.0f, 0.0f); // Top
GL.glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
GL.glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
GL.glEnd(); // Finished Drawing The Triangle
14. 3d Basics – Materials
● Materials
– Front & back, color, texture
● Color
GL.glBegin(GL_TRIANGLES); // Drawing Triangles
GL.glColor3f(1.0f,0.0f,0.0f); // Color Red
GL.glVertex3f( 0.0f, 1.0f, 0.0f); // Top
GL.glColor3f(0.0f,0.0f,1.0f); // Color Blue
GL.glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
GL.glColor3f(0.0f,1.0f,0.0f); // Color Green
GL.glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
GL.glEnd();
● Texture
– gl.glBindTexture(GL.GL_TEXTURE_2D, textures[1]);
– gl.glTexCoord2d(0.0f, 0.0f); // First Texture Coord before first vertex
– See also texture utilities that ship with JOGL
http://www.java-tips.org/other-api-tips/jogl/2d-texture-font-nehe-tutorial-jogl-port.html
15. 3d Basics – Transforms
● OpenGL matrix stack (push, pop)
● 4x4 matrix (16 float values) 1.0 0.0 0.0 0.0
– Rotate 0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
– Scale 0.0 0.0 0.0 1.0
– Shift (translate)
● Used for Perspective, Meshes & Textures
GL.glPushMatrix(); // 1) save initial matrix
GL.glTranslatef(x,y,z); // 2) relative position for drawing torso
DrawTorso(); // 3) draw torso
GL.glPushMatrix(); // 4) save torso matrix
GL.glTranslatef(x,y,z); // 5) relative position for drawing arm
DrawArm(); // 6) draw arm
GL.glPopMatrix(); // 7) restore torso matrix
GL.glPopMatrix(); // 8) restore initial matrix
16. 3d Basics – Camera
Pixel on Camera
Position Frustrum Not seen
Screen
by camera
Camera
Lookat
● Just a concept with its own GL mode (perspective)
– Option 1: transform the scene instead
– Option 2: GLU Position & lookat (does work for you)
– Hard: 6DOF (degrees of freedom) / arcball
GL.glMatrixMode(GL_PROJECTION); //set camera mode
GL.glLoadIdentity(); //Reset the camera matrix
GL.glMatrixMode(GL_MODELVIEW); //set scene mode
GL.glLoadIdentity(); //Reset the scene matrix
GL.glRotatef(-RotatedX , 1.0f, 0.0f, 0.0f); //Option 1 – transform the scene (all meshes)
GL.glRotatef(-RotatedY , 0.0f, 1.0f, 0.0f);
GL.glRotatef(-RotatedZ , 0.0f, 0.0f, 1.0f);
GL.glTranslatef( -Position.x, -Position.y, -Position.z );
17. A Complete Render Example
public class IglEL implements GLEventListener { // @author Kevin Duling (jattier@hotmail.com)
private GLU glu = new GLU();
public void display(GLAutoDrawable gLDrawable) { //draw an RGB triangle
final GL gl = gLDrawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-1.5f, 0.0f, -6.0f);
gl.glBegin(GL.GL_TRIANGLES); // Drawing Using Triangles
gl.glColor3f(1.0f, 0.0f, 0.0f); // Set the current drawing color to red
gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top
gl.glColor3f(0.0f, 1.0f, 0.0f); // Set the current drawing color to green
gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
gl.glColor3f(0.0f, 0.0f, 1.0f); // Set the current drawing color to blue
gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
gl.glEnd(); // Finished Drawing The Triangle
gl.glFlush();
}
public void displayChanged(GLAutoDrawable glD, boolean mChng, boolean dChng) {}
public void init(GLAutoDrawable gLDrawable) {
GL gl = gLDrawable.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_SMOOTH); //try setting this to GL_FLAT and see what happens.
}
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
final GL gl = gLDrawable.getGL();
if (height <= 0) height = 1; // avoid a divide by zero error
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
} //From http://pepijn.fab4.be/?page_id=34
18. JOGL – What to do Next
1.Go through JOGL nehe tutorials
http://pepijn.fab4.be (JOGL nehe tutorials)
2.Study a simple game (JavaOne '07 presentation)
http://jsolutions.se/DukeBeanEm/
3.Bookmark reference material
http://www.opengl.org/ (see the FAQ sections)
http://www.gamedev.net (game forums & good resources)
http://www.talisman.org/opengl-1.1/Reference/ (OpenGL API reference)
http://www.euclideanspace.com/ (Martin Baker's math references)
http://ak.kiet.le.googlepages.com/theredbookinjava.html (opengl redbook examples)
4.Extra credit: use a free 3d engine
Free 3d Java Engines (some use JNI for more than OpenGL):
http://www.jmonkeyengine.com/ (LWJGL with Plans for JOGL, collision, audio, loaders, skins)
http://www.jpct.net (jPCT uses LWJGL)
http://irrlicht.sourceforge.net/ (uses jirr JNI to bind to c++ 3d and audio libs)
http://java.sun.com/products/java-media/3D/ (JOGL capable)
19. What Can You Do with 3d Graphics?
● 3d products in
web pages
● Create a game
(JavaOne'07 -
Create a game in
50 minutes)
● Customize
NASA's World
Wind (demo)
● 3d chart / graph
your datasets
● 3d UML
http://www.timespace.com
20. What Can You Do with 3d Graphics?
● 3d products into
web pages
● Create a game
(JavaOne'07 -
Create a game
in 50 minutes)
● Customize
NASA's World
Wind (demo)
● 3d chart / graph
your datasets
● 3d UML
http://jsolutions.se/DukeBeanEm/
21. What Can You Do with 3d Graphics?
● 3d products into
web pages
● Create a game
(JavaOne'07 -
Create a game in
50 minutes)
● Customize
NASA's World
Wind (demo)
● 3d chart / graph
your datasets
● 3d UML
http://worldwind.arc.nasa.gov/java/index.html
22. What Can You Do with 3d Graphics?
● 3d products into
web pages
● Create a game
(JavaOne'07 -
Create a game in
50 minutes)
● Customize
NASA's World
Wind (demo)
● 3d chart /
graph your
datasets
● 3d UML
http://www.techfak.uni-bielefeld.de/ags/ani/projects/tmbiomed/
23. What Can You Do with 3d Graphics?
● 3d products into
web pages
● Create a game
(JavaOne'07 -
Create a game in
50 minutes)
● Customize
NASA's World
Wind (demo)
● 3d chart / graph
your datasets
● 3d UML
http://www.opencroquet.org
24. Summary
● 3d graphics are now standard
● The game market is growing
● JOGL is a wrapper around OpenGL
● It makes real-time rendering low-level 2d
and 3d easy and flexible
– Most 3d games likely require an engine
● Can be incorporated with SunSPOTs
● Enables visualization of arbitrary data