3D Rendering with JOGL - PowerPoint PPT Presentation

About This Presentation
Title:

3D Rendering with JOGL

Description:

Representations of three-dimensional geometry are projected to a two-dimensional ... Supports integration with the Java platform's AWT and Swing widget sets ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 23
Provided by: ricardov4
Learn more at: http://ece.uprm.edu
Category:

less

Transcript and Presenter's Notes

Title: 3D Rendering with JOGL


1
3D Rendering with JOGL
  • Introduction to Java OpenGL Graphic Library

By Ricardo Veguilla
http//ece.uprm.edu/veguilla/java_opengl_demo/
2
3D Graphics Intro
  • 3D graphics are images generated from abstract
    descriptions of three dimensional objects.
  • Representations of three-dimensional geometry are
    projected to a two-dimensional plane (screen) for
    viewing by a user.
  • The projection process simulates the interaction
    between light and the object surfaces. This
    creates an illusion of 3D, hence the name 3D
    rendering.

3
Requirements for 3D Rendering
  • A virtual camera
  • Decides what should end up in the final image
  • A 3D scene
  • Geometry (triangles, lines, points, and more)
  • Light sources
  • Material properties of geometry
  • Textures (images to glue onto the geometry)
  • A triangle consists of 3 vertices
  • A vertex is 3D position, and may
    include normals and more.

4
Virtual Camera
  • Defined by position, direction vector, up vector,
    field of view, near and far plane.
  • Create image of geometry inside gray region

5
Geometry Manipulation
  • Originally, an object is in model space
  • Move, orient, and transform geometrical objects
    into world space
  • Example, a sphere is defined with origin at
    (0,0,0) with radius 1
  • Translate, rotate, scale to make it appear
    elsewhere
  • Done per vertex with a 4x4 matrix multiplication!
  • The user can apply different matrices over time
    to animate objects

6
Example A 3D square
glTranslatef(0,7,0) glRotatef(45,0,0,2)
y
glTranslatef(8,6,0) glScalef(2,2,2)
x
glTranslatef(8,0,0)
7
The Geometry Color
  • Triangle color defined per vertex
  • Interpolate colors over the triangle

8
Texturing
  • Painting images onto geometrical objects

9
Geometry Projection
  • Orthogonal
  • Perspective

10
OpenGL The Open Graphics Language
  • De facto Application Programming Interface (API)
    for cross-platform development of 3D graphics
    applications.
  • Implementations available for all major Operating
    Systems and hardware platforms.
  • Support for hardware accelerated 3D rendering.
  • Scalable, high-level, easy to use, well
    documented.

11
JOGL
  • Jogl is a Java programming language binding for
    the OpenGL 3D graphics API
  • Supports integration with the Java platform's AWT
    and Swing widget sets
  • Provides access to the latest OpenGL routines
    (OpenGL 2.0 with vendor extensions)
  • Also provides platform-independent access to
    hardware-accelerated off-screen rendering.

12
OpenGL - Primitive types
13
Defining OpenGL primitives
  • glBegin( GL_PRIMITIVE_TYPE)
  • glVertex()
  • glVertex()
  • glEnd() Block.

14
Transformation Matrices
  • OpenGL provide 3 transformation matrix stacks
  • Perspective Matrix Used for viewing
    transformations equivalent to positioning and
    aiming a camera.
  • Modeling Matrix Used for modeling
    transformations equivalent to positioning and
    orienting the model to be drawn.
  • Texture Matrix Used for texture transformations
    equivalent to positioning and orienting the
    texture to be drawn over a polygon.

15
Transformation functions
  • glLoadIdentity()
  • glTranslate(TYPE x, TYPE y, TYPE z)
  • glRotate(TYPE angle, TYPE x, TYPE y, TYPE z)
  • glScale(TYPE x, TYPE y, TYPE z)
  • glPushMatrix()
  • glPopMatrix()

16
glLoadIdentity
  • glLoadIdentity()
  • Loads the identity matrix into the current
    transformation matrix.
  • Used to reset the current transformation matrix
    before performing a transformation.

17
Translatoin
  • glTranslate(TYPE x, TYPE y, TYPE z)
  • Multiplies the current transformation matrix by a
    matrix that moves an object (the local coordinate
    system) by the given x, y, and z values.

18
Rotation
  • glRotate(TYPE angle, TYPE x, TYPE y, TYPE z)
  • Multiplies the current transformation matrix by a
    matrix that rotates an object (or the local
    coordinate system) in a counter clockwise
    direction about the ray from the origin through
    the point (x, y, z). The angle parameter
    specifies the angle of rotation in degrees.

19
Scaling
  • glScale(TYPE x, TYPE y, TYPE z)
  • Multiplies the current transformation matrix by a
    matrix that stretches, shrinks, or reflects and
    object (or the local coordinate system) along the
    axes. Each x, y, and z coordinate of every point
    in the object is multiplied by the corresponding
    argument x, y, or z.

20
Controlling the transformation matrix stacks
  • glPushMatrix()
  • Pushed the current transformation matrix into the
    stack.
  • glPopMatrix()
  • Loads the matrix at the top of the stack into the
    current transformation matrix.

21
OpenGL - Code Example
  • // Set the viewport size
  • glViewport(0, 0, width, height)
  • // Clear the window
  • glClear(GL_COLOR_BUFFER_BIT)
  • // Set the drawing color
  • glColor3f(1.0, 1.0, 1.0)
  • // Start primitive type definition
  • glBegin(GL_POLYGON)
  • // Specify verticies
  • glVertex2f(-0.5, -0.5)
  • glVertex2f(-0.5, 0.5)
  • glVertex2f(0.5, 0.5)
  • glVertex2f(0.5, -0.5)
  • // End primitive type definition
  • glEnd()
  • // Flush the buffer to force drawing of all
    objects thus far
  • glFlush()

22
References
  • OpenGL - The Industry Standard for High
    Performance Graphics
  • http//www.opengl.org/
  • Jogl Java OpenGL Bindings
  • https//jogl.dev.java.net/
  • Wikipidia OpenGL
  • http//en.wikipedia.org/wiki/OpenGL
Write a Comment
User Comments (0)
About PowerShow.com