+ All Categories
Home > Documents > 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla...

3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla...

Date post: 23-Dec-2015
Category:
Upload: walter-jordan
View: 229 times
Download: 0 times
Share this document with a friend
Popular Tags:
22
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla p:// ece.uprm.edu/~veguilla/java_opengl_demo /
Transcript
Page 1: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

3D Rendering with JOGL Introduction to Java OpenGL Graphic Library

By Ricardo Veguilla

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

Page 2: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla 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.

Page 3: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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.

Page 4: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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)

Page 5: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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

Page 6: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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

Page 7: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

The Geometry Color

Triangle color defined per vertex Interpolate colors over the

triangleblueblue

redred greengreen

Page 8: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

Texturing

+ =

Painting images onto geometrical objects

Page 9: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

Geometry Projection Orthogonal

Perspective

Page 10: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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.

Page 11: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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.

Page 12: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

OpenGL - Primitive types

Page 13: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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

Page 14: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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.

Page 15: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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

Page 16: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

glLoadIdentity

glLoadIdentity()

Loads the identity matrix into the current transformation matrix.

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

Page 17: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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.

Page 18: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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.

Page 19: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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.

Page 20: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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.

Page 21: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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

Page 22: 3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla veguilla/java_opengl_demo

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


Recommended