Lecture 7 Midterm Review
OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture mipmaps from a base image, draw quadric surfaces and NURBS. glut: OpenGL Utility Toolkit library. A system independent windowing system. Hierarchical view of libraries:
Mesa 3D Mesa 3D is a free/open source implementation of OpenGL. Mesa 3D This is a good source if you plan to see the implementation details of a function.
Rendering Pipeline
Evaluators Deriving vertices from basis functions Vertices can be used to represent a surface Per-Vertex Operations Converts vertices into primitives i.e. line, polygon, etc. Does mathematical operations, i.e. transformation, rotation, projection, etc.
Rendering Pipeline Rasterization: Conversion of geometric and pixel data into fragments. Each fragment corresponds to a pixel in frame buffer. When creating models, many parameters have to be considered, e.g. shading model, color, point size, etc.
Fragment Operations Before a fragment be placed in frame buffer, the following can be controlled: Texture Mapping Fog calculations Alpha Test, depth buffer test Blending, masking, etc.
GLUT Window Initialization What is Buffer? Clearing the Window glClearColor(R, G, B, A) glClearColor(GL_COLOR_BUFFER_BIT) glClearDepth() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
OpenGL Buffers
Event Driven Programming Definition. A programming where the primary activity is reaction to the receipt of event. Applications: GUI, HCI Ingredients: Events: Can be from any source, human input, e.g. mouse or other sensors. Event Dispatcher: Assigns events to event handlers. Event Handler
Event Processing in GLUT Initial Setup: Initializing Display Modes, e.g. Color mode, Single/Double Buffer, etc. Entering GLUT event processing loop void glutMainLoop (void)
Display Function The display function of current window When is it called? If the normal plane of a window needs to be redisplayed as a result of window damage. GLUT determines this based on redisplay state of a window. When a user requests. How is it called? Implicitly: By GLUT, e.g. when the window system reports a region of the window's normal plane is undefined (for example, damaged by another window moving or being initially shown) Explicitly: Using glutPostRedisplay function.
Double Buffering Using Two buffers Front Buffer Back Buffer Is specified in initialization step glutInitDisplayMode (GLUT_DOUBLE) Replace glFlush() with glSwapBuffers() Increases the performance It’s NOT free, you have to pay: memory
Rotation and Translation
Camera Rotation Example: If we want to move a camera along a circular path and about any one of axes, we use rotation matrix corresponding to that axis. Then, by increasing the angle from [0…360], we calculate the new location of the camera.
ModelView,Projection,Viewport ModelView: Rotation, Translation, Scale. Projection: glFrustum, glOrtho, glPerspective Viewport glViewport
Perspective Projection
Viewport Defines how a rendered image should be displayed on a window.
Sequence of Matrices
Camera Properties: Position, Direction, UpVector Attention: Using gluLookAt affects the ModelView Matrix It is usually placed at the beginning of the display function It is usually placed after glLoadIdentity(GL_MODELVIEW) Be careful when placing it in a loop.
Matrix Stack Pushing matrices into the stack Poping matrices from the stack Example: