Lecture 7
-
Upload
tobias-landry -
Category
Documents
-
view
28 -
download
2
description
Transcript of Lecture 7
![Page 1: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/1.jpg)
Lecture 7
Midterm Review
![Page 2: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/2.jpg)
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: http://www.nigels.com/glt/doc/gl_8h.h
tml
![Page 3: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/3.jpg)
Mesa 3D Mesa 3D is a free/open source
implementation of OpenGL.
This is a good source if you plan to see the implementation details of a function.
http://www.mesa3d.org
![Page 4: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/4.jpg)
Rendering Pipeline
![Page 5: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/5.jpg)
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.
![Page 6: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/6.jpg)
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.
![Page 7: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/7.jpg)
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.
![Page 8: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/8.jpg)
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)
![Page 9: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/9.jpg)
OpenGL Buffers
![Page 10: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/10.jpg)
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
![Page 11: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/11.jpg)
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)
![Page 12: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/12.jpg)
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.
![Page 13: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/13.jpg)
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
![Page 14: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/14.jpg)
Rotation and Translation
![Page 15: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/15.jpg)
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.
![Page 16: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/16.jpg)
ModelView,Projection,Viewport
ModelView: Rotation, Translation, Scale.
Projection: glFrustum, glOrtho, glPerspective
Viewport glViewport
![Page 17: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/17.jpg)
Perspective Projection
![Page 18: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/18.jpg)
Viewport
Defines how a rendered image should be displayed on a window.
![Page 19: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/19.jpg)
Sequence of Matrices
![Page 20: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/20.jpg)
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.
![Page 21: Lecture 7](https://reader031.fdocuments.net/reader031/viewer/2022012922/56813218550346895d9876d4/html5/thumbnails/21.jpg)
Matrix Stack
Pushing matrices into the stack Poping matrices from the stack Example: