3 D Rendering with JOGL Introduction to Java

  • Slides: 22
Download presentation
3 D Rendering with JOGL Introduction to Java Open. GL Graphic Library By Ricardo

3 D Rendering with JOGL Introduction to Java Open. GL Graphic Library By Ricardo Veguilla http: //ece. uprm. edu/~veguilla/java_opengl_demo/

3 D Graphics Intro n n n 3 D graphics are images generated from

3 D Graphics Intro n n n 3 D graphics are images generated from abstract descriptions of three dimensional objects. Representations of three-dimensional geometry are projected to a twodimensional plane (screen) for viewing by a user. The projection process simulates the interaction between light and the object surfaces. This creates an illusion of 3 D, hence the name 3 D rendering.

Requirements for 3 D Rendering n A virtual camera: n n A 3 D

Requirements for 3 D Rendering n A virtual camera: n n A 3 D scene: n n n Decides what should end up in the final image 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 n A vertex is 3 D position, and may include normals and more.

Virtual Camera n Defined by position, direction vector, up vector, field of view, near

Virtual Camera n Defined by position, direction vector, up vector, field of view, near and far plane. point l dir far fov near (angle) Create image of geometry inside gray region

Geometry Manipulation n Originally, an object is in ”model space” Move, orient, and transform

Geometry Manipulation n 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 n n n Translate, rotate, scale to make it appear elsewhere Done per vertex with a 4 x 4 matrix multiplication! The user can apply different matrices over time to animate objects

Example: A 3 D square y gl. Translatef(0, 7, 0); gl. Rotatef(45, 0, 0,

Example: A 3 D square y gl. Translatef(0, 7, 0); gl. Rotatef(45, 0, 0, 2); gl. Translatef(8, 6, 0); gl. Scalef(2, 2, 2); x gl. Translatef(8, 0, 0);

The Geometry Color Triangle color defined per vertex n Interpolate colors over the triangle

The Geometry Color Triangle color defined per vertex n Interpolate colors over the triangle n blue red green

Texturing l Painting images onto geometrical objects + =

Texturing l Painting images onto geometrical objects + =

Geometry Projection n Orthogonal n Perspective

Geometry Projection n Orthogonal n Perspective

Open. GL – The Open Graphics Language De facto Application Programming Interface (API) for

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

JOGL n n Jogl is a Java programming language binding for the Open. GL

JOGL n n Jogl is a Java programming language binding for the Open. GL 3 D graphics API Supports integration with the Java platform's AWT and Swing widget sets Provides access to the latest Open. GL routines (Open. GL 2. 0 with vendor extensions) Also provides platform-independent access to hardware-accelerated offscreen rendering.

Open. GL - Primitive types

Open. GL - Primitive types

Defining Open. GL primitives gl. Begin( GL_PRIMITIVE_TYPE) gl. Vertex(…) … gl. End() Block.

Defining Open. GL primitives gl. Begin( GL_PRIMITIVE_TYPE) gl. Vertex(…) … gl. End() Block.

Transformation Matrices Open. GL provide 3 transformation matrix stacks: n Perspective Matrix – Used

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

Transformation functions n gl. Load. Identity() n gl. Translate(TYPE x, TYPE y, TYPE z)

Transformation functions n gl. Load. Identity() n gl. Translate(TYPE x, TYPE y, TYPE z) n gl. Rotate(TYPE angle, TYPE x, TYPE y, TYPE z) n gl. Scale(TYPE x, TYPE y, TYPE z) n gl. Push. Matrix() n gl. Pop. Matrix()

gl. Load. Identity n gl. Load. Identity() n Loads the identity matrix into the

gl. Load. Identity n gl. Load. Identity() n Loads the identity matrix into the current transformation matrix. n Used to reset the current transformation matrix before performing a transformation.

Translatoin n gl. Translate(TYPE x, TYPE y, TYPE z) n Multiplies the current transformation

Translatoin n gl. Translate(TYPE x, TYPE y, TYPE z) n 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 n gl. Rotate(TYPE angle, TYPE x, TYPE y, TYPE z) n Multiplies the

Rotation n gl. Rotate(TYPE angle, TYPE x, TYPE y, TYPE z) n 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 n gl. Scale(TYPE x, TYPE y, TYPE z) n Multiplies the current transformation

Scaling n gl. Scale(TYPE x, TYPE y, TYPE z) n 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 n gl. Push. Matrix() n Pushed the current transformation

Controlling the transformation matrix stacks n gl. Push. Matrix() n Pushed the current transformation matrix into the stack. n gl. Pop. Matrix() n Loads the matrix at the top of the stack into the current transformation matrix.

Open. GL - Code Example // Set the viewport size gl. Viewport(0, 0, width,

Open. GL - Code Example // Set the viewport size gl. Viewport(0, 0, width, height); // Clear the window gl. Clear(GL_COLOR_BUFFER_BIT); // Set the drawing color gl. Color 3 f(1. 0, 1. 0); // Start primitive type definition gl. Begin(GL_POLYGON); // Specify verticies gl. Vertex 2 f(-0. 5, -0. 5); gl. Vertex 2 f(-0. 5, 0. 5); gl. Vertex 2 f(0. 5, -0. 5); // End primitive type definition gl. End(); // Flush the buffer to force drawing of all objects thus far gl. Flush();

References: Open. GL - The Industry Standard for High Performance Graphics n http: //www.

References: Open. GL - The Industry Standard for High Performance Graphics n http: //www. opengl. org/ Jogl – Java Open. GL Bindings n https: //jogl. dev. java. net/ Wikipidia – Open. GL n http: //en. wikipedia. org/wiki/Open. GL