3D Rendering with JOGL

22
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla p:// ece.uprm.edu/~veguilla/java_opengl_demo /

description

3D Rendering with JOGL. Introduction to Java OpenGL Graphic Library. By Ricardo Veguilla. http://ece.uprm.edu/~veguilla/java_opengl_demo/. 3D Graphics Intro. 3D graphics are images generated from abstract descriptions of three dimensional objects . - PowerPoint PPT Presentation

Transcript of 3D Rendering with JOGL

3D Rendering with JOGL Introduction to Java OpenGL Graphic Library

By Ricardo Veguilla

http://ece.uprm.edu/~veguilla/java_opengl_demo/

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.

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.

Virtual Camera Defined by position, direction vector, up vector, field of view, near and far plane.

Create image of geometry inside gray region

pointdir

near

far

fov(angle)

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

Example: A 3D square

x

y

glTranslatef(8,0,0);glTranslatef(8,0,0);

glTranslatef(8,6,0);glTranslatef(8,6,0);

glScalef(2,2,2);glScalef(2,2,2);

glTranslatef(0,7,0);glTranslatef(0,7,0);

glRotatef(45,0,0,2);glRotatef(45,0,0,2);

The Geometry Color

Triangle color defined per vertex Interpolate colors over the

triangleblueblue

redred greengreen

Texturing

+ =

Painting images onto geometrical objects

Geometry Projection Orthogonal

Perspective

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.

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.

OpenGL - Primitive types

Defining OpenGL primitivesglBegin( GL_PRIMITIVE_TYPE)glVertex(…)glVertex(…)…glEnd() Block.

Transformation MatricesOpenGL 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.

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()

glLoadIdentity

glLoadIdentity()

Loads the identity matrix into the current transformation matrix.

Used to reset the current transformation matrix before performing a transformation.

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.

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.

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.

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.

OpenGL - Code Example// Set the viewport sizeglViewport(0, 0, width, height); // Clear the windowglClear(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 farglFlush();

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