Open GL The Open Graphics Language Introduction By
Open. GL: The Open Graphics Language Introduction By Ricardo Veguilla
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
Open. GL - Primitive types
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 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) 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 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 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 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 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 tranformation 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, 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. opengl. org/ Jogl – Java Open. GL Bindings n https: //jogl. dev. java. net/ Wikipidia – Open. GL n http: //en. wikipedia. org/wiki/Open. GL
- Slides: 13