160 likes | 174 Views
Learn about OpenGL, the de facto API for cross-platform 3D graphics development. Understand transformation matrices, transformation functions, and code examples for implementation. Explore development considerations and auxiliary toolkits for OpenGL applications.
E N D
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla
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.
History of OpenGL • Originally released by SGI in the early 90s. • Descendant of IRIX GL. • Previous 3D graphics APIs were generally platform dependant. • Born out of market pressure for a cross-platform 3D API during the late 80s.
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.
Transformation Matrix Selection • Using glMatrixMode(GLenum mode) function with one of the following argument: • GL_MODELVIEW • GL_PROJECTION • GL_TEXTURE. • All subsequent transformation commands affect the specified matrix.
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 tranformation 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 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();
Development Considerations • OpenGL API designed only for drawing images. • Auxiliary visual toolkits are required for developing OpenGL applications for modern windowed desktop environments. • Potential cross-platform options: • GLUT, SDL, GTK+
Auxiliary Toolkits • GLUT: Specifically designed for developing OpenGL demo applications. • SDL (Simple DirectMedia Layer): Library for multimedia and game development. • GTK+: General purpose toolkit for creating graphical user interfaces with OpenGL extensions available.
References: OpenGL - The Industry Standard for High Performance Graphics • http://www.opengl.org/ Wikipidia – OpenGL • http://en.wikipedia.org/wiki/OpenGL