csc 307 1.0 graphics programming · opengl • standard specification defining a cross-language,...
TRANSCRIPT
CSC 307 1.0
Graphics Programming
Budditha Hettige
Department of Statistics and Computer Science
Graphics Programming
2 Budditha Hettige
Common Uses for Computer
Graphics
• Applications for real-time 3D graphics range from
interactive games and simulations to data visualization
for scientific, medical, or business uses
– Military flight simulators
– Computer-aided design (CAD)
– Architectural or civil planning
– Scientific visualization
– Entertainment
3 Budditha Hettige
Movies
Budditha Hettige 4
Simulation
Budditha Hettige 6
CAD-CAM & Design
Budditha Hettige 7
Architecture
Budditha Hettige 8
Virtual Reality
Budditha Hettige 9
Visualization
Budditha Hettige 10
Medical Imaging
Budditha Hettige 11
Graphics System
12
User Program User Program IO Devices IO Devices
Graphics API
Graphics System
Graphics System
Budditha Hettige
Graphics Designing
13 Budditha Hettige
Graphics: Conceptual Model
Real Object
Real Object
Human Eye
Human Eye
Display Device
Graphics System
Synthetic Model
Synthetic Camera
Real Light
Synthetic Light Source
Budditha Hettige 14
OpenGL
• Standard specification defining a cross-language, cross-
platform API
• Is not a programming language
• Writing applications that produce 2D and 3D computer
graphics
• A software interface to graphics hardware
• Designed and optimized for the display and
manipulation of 3D graphics
• Developed by Silicon Graphics Inc. (SGI) in 1992
15 Budditha Hettige
OpenGL-Graphics rendering API
• Rendering API
– High-quality color images composed of geometric
and image primitives
– Window system independent
– Operating system independent
• OpenGL Pipeline
16 Budditha Hettige
OpenGL Architecture
17
Display List
Polynomial Evaluator
Per Vertex Operations & Primitive Assembly
Rasterization Per Fragment Operations
Frame Buffer
Texture Memory
CPU
Pixel Operations
Budditha Hettige
Software & Hardware Interfaces
18
Software Interface Hardware Interface
Budditha Hettige
OpenGL and Related APIs
19
GLUT
GLU
GL
GLX, AGL or WGL
X, Win32, Mac O/S
software and/or hardware
application program
OpenGL Motif widget or similar
Budditha Hettige
Related APIs
• AGL, GLX, WGL – glue between OpenGL and windowing systems
• GLU (OpenGL Utility Library) – part of OpenGL
– NURBS, tessellators, quadric shapes, etc.
• GLUT (OpenGL Utility Toolkit) – portable windowing API
– not officially part of OpenGL
• Initial header inclusions (for Windows) – #include<windows.h>
– #include<gl/gl.h>
– #include<gl/glu.h>
– #include <GL/glut.h>
20 Budditha Hettige
Function-Naming Conventions
• All OpenGL functions take the following
format <Library prefix><Root command><Optional argument
count><Optional argument type>
21 Budditha Hettige
OpenGL data types
22 Budditha Hettige
2D Coordinates
23 Budditha Hettige
Coordinate Clipping
24 Budditha Hettige
Viewports • Mapping Drawing Coordinates to Window
Coordinates
25
viewport defined as twice the size of the clipping area
Budditha Hettige
Viewports
26
viewport that matches the clipping area
Budditha Hettige
OpenGL 3-D coordinates
• Right-handed system
• From point of view of camera looking out into scene:
+X right, -X left
+Y up, -Y down
+Z behind camera, -Z in front
• Positive rotations are counterclockwise around axis of rotation
27 Budditha Hettige
28
OpenGL Geometric Primitives
GL_QUAD_STRIP
GL_POLYGON
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
GL_POINTS GL_LINES
GL_LINE_LOOP GL_LINE_STRIP
GL_TRIANGLES
GL_QUADS
Primitives are one- or two-dimensional entities or surfaces such as points, lines, and polygons
Budditha Hettige
The Vertex—A Position in Space
• Each corner of the any primitive is called a
vertex. Ex: three-dimensional cube consists of
six two dimensional squares, each placed on a
separate face
29 Budditha Hettige
Projections: Getting 3D to 2D
• Orthographic Projections
• Perspective Projections
30 Budditha Hettige
RGB Color Space
Green (1,0,0)
Blue (0,0,1)
Red (1,0,0)
Yellow (1,1,0)
Magenta (1,0,1)
Blk
Cyan (0,1,1)
White (1,1,1)
G
B
R
Image: Pixel maps to color
Budditha Hettige 31
Common Composite Colors
32 Budditha Hettige