SlideShare a Scribd company logo
1 of 25
Download to read offline
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
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
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
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
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)
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."
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
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
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, ...
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();
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
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
3d Basics – Lights
●   Lights
    –   Ambient (indirect light)
    –   Diffuse (rough surface)
    –   Specular (shiny surface)
    –   Emission (neon tube)
    float specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
    GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specular);
    float global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
    GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, global_ambient);
    float specular[] = {1.0f, 1.0f, 1.0f , 1.0f};
    GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specular);
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
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
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 );
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
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)
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
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/
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
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/
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
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
Q&A

More Related Content

Viewers also liked

Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1Por Non
 
Multiple Screens
Multiple ScreensMultiple Screens
Multiple Screensgraphitech
 
Visualizing STEP Files
Visualizing STEP FilesVisualizing STEP Files
Visualizing STEP FilesRichard Haney
 
ICON 2011 Introduction to OpenGL ES
ICON 2011 Introduction to OpenGL ESICON 2011 Introduction to OpenGL ES
ICON 2011 Introduction to OpenGL ESSeongWan Kim
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open glArvind Devaraj
 
CG simple openGL point & line-course 2
CG simple openGL point & line-course 2CG simple openGL point & line-course 2
CG simple openGL point & line-course 2fungfung Chen
 
CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9fungfung Chen
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityMark Kilgard
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.Girish Ghate
 
SIGGRAPH Asia 2008 Modern OpenGL
SIGGRAPH Asia 2008 Modern OpenGLSIGGRAPH Asia 2008 Modern OpenGL
SIGGRAPH Asia 2008 Modern OpenGLMark Kilgard
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and MoreMark Kilgard
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016Mark Kilgard
 

Viewers also liked (18)

Akashdeepsinghjandu13
Akashdeepsinghjandu13Akashdeepsinghjandu13
Akashdeepsinghjandu13
 
Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1
 
Arkanoid Game
Arkanoid GameArkanoid Game
Arkanoid Game
 
Multiple Screens
Multiple ScreensMultiple Screens
Multiple Screens
 
Visualizing STEP Files
Visualizing STEP FilesVisualizing STEP Files
Visualizing STEP Files
 
OpenGL Starter L02
OpenGL Starter L02OpenGL Starter L02
OpenGL Starter L02
 
JavaFX 2.0 への誘い
JavaFX 2.0 への誘いJavaFX 2.0 への誘い
JavaFX 2.0 への誘い
 
ICON 2011 Introduction to OpenGL ES
ICON 2011 Introduction to OpenGL ESICON 2011 Introduction to OpenGL ES
ICON 2011 Introduction to OpenGL ES
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
OpenGL L01-Primitives
OpenGL L01-PrimitivesOpenGL L01-Primitives
OpenGL L01-Primitives
 
CG simple openGL point & line-course 2
CG simple openGL point & line-course 2CG simple openGL point & line-course 2
CG simple openGL point & line-course 2
 
CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
SIGGRAPH Asia 2008 Modern OpenGL
SIGGRAPH Asia 2008 Modern OpenGLSIGGRAPH Asia 2008 Modern OpenGL
SIGGRAPH Asia 2008 Modern OpenGL
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016
 
OpenGL Basics
OpenGL BasicsOpenGL Basics
OpenGL Basics
 

Similar to Ujug07presentation

OpenGL L02-Transformations
OpenGL L02-TransformationsOpenGL L02-Transformations
OpenGL L02-TransformationsMohammad Shaker
 
The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.8 book - Part 61 of 202The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.8 book - Part 61 of 202Mahmoud Samir Fayed
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android GamesPlatty Soft
 
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210Mahmoud Samir Fayed
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APITomi Aarnio
 
3D Programming Basics: WebGL
3D Programming Basics: WebGL3D Programming Basics: WebGL
3D Programming Basics: WebGLGlobant
 
The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212Mahmoud Samir Fayed
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing StuffMark Kilgard
 
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212Mahmoud Samir Fayed
 

Similar to Ujug07presentation (20)

OpenGL L02-Transformations
OpenGL L02-TransformationsOpenGL L02-Transformations
OpenGL L02-Transformations
 
CGLabLec6.pptx
CGLabLec6.pptxCGLabLec6.pptx
CGLabLec6.pptx
 
The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.8 book - Part 61 of 202The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.8 book - Part 61 of 202
 
Development with OpenGL and Qt
Development with OpenGL and QtDevelopment with OpenGL and Qt
Development with OpenGL and Qt
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android Games
 
OpenGL Starter L01
OpenGL Starter L01OpenGL Starter L01
OpenGL Starter L01
 
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210
 
BYO3D 2011: Rendering
BYO3D 2011: RenderingBYO3D 2011: Rendering
BYO3D 2011: Rendering
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
3D Programming Basics: WebGL
3D Programming Basics: WebGL3D Programming Basics: WebGL
3D Programming Basics: WebGL
 
The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185
 
Bai 1
Bai 1Bai 1
Bai 1
 
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
 
Games 3 dl4-example
Games 3 dl4-exampleGames 3 dl4-example
Games 3 dl4-example
 

Ujug07presentation

  • 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
  • 13. 3d Basics – Lights ● Lights – Ambient (indirect light) – Diffuse (rough surface) – Specular (shiny surface) – Emission (neon tube) float specular[] = {1.0f, 1.0f, 1.0f, 1.0f}; GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specular); float global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f }; GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, global_ambient); float specular[] = {1.0f, 1.0f, 1.0f , 1.0f}; GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specular);
  • 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
  • 25. Q&A