Chapter 3
Chapter 3
3
libraries in OpenGL program
• A number of libraries exist to allow you to simplify your
programming tasks,
1. Core OpenGL (GL): consists of hundreds of commands, which
begin with a prefix "gl"
o It is the Lowest level: vertex, matrix manipulation.
o The Core OpenGL models an object via a set of geometric
primitives such as point, line and polygon.
o e.g., glColor, glVertex, glTranslate, glRotate.
2. OpenGL Utility Library (GLU): built on-top of the core
OpenGL to provide important utilities (such as setting camera
view and projection) and more building models.
o Helper functions for shapes, transformations
o GLU commands start with a prefix "glu"
o e.g. gluLookAt, gluPerspective.
Cont..
3. OpenGL Utilities Toolkit (GLUT): OpenGL is
designed to be independent of the windowing
system or operating system.
o GLUT is needed to interact with the Operating System (such
as creating a window, handling key and mouse inputs);
o it also provides more building .
o Highest level: Window and interface management
o GLUT commands start with a prefix of "glut"
o e.g. glutCreatewindow, glutMouseFunc, glutInitWindowSize
OpenGL Implementations(header files)
• OpenGL is an API (think of as collection of .h
files):
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
• But glut.h includes gl.h, glu.h, and glx.h
automatically, so including all three files is
redundant.
• Libraries
– OpenGL defines numerous types for compatibility
– GLfloat, GLint, GLenum, etc.
GLUT Callback Functions
Routine to call when something happens
– window resize or redraw
– user input
– animation
“Register” callbacks with GLUT
glutDisplayFunc( display );
• called when pixels in the window need to be refreshed.
glutIdleFunc( idle );
• a callback function called when nothing else is going on.
Very useful for animations.
glutKeyboardFunc( keyboard );
• called when a key is struck on the keyboard
7
OPENGL COMMAND SYNTAX 1
• OpenGL commands use the prefix gl and initial capital
letters for each word making up the command name
– (recall glClearColor().
Imaging system
Synthetic camera (contd…)
• In image formation using optical systems, the image is
flipped relative to the object.
• In synthetic camera model this is avoided by introducing a
plane in front of the lens which is called the image plane.
• The angle of view of the camera poses a restriction on the
part of the object which can be viewed.
• This limitation is moved to the front of the camera by
placing a Clipping Window in the projection plane.
36
End of Chapter 3
37