1 / 22

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 .

Download Presentation

3D Rendering with JOGL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. far dir point fov (angle) near 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. blue red green 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

More Related