Title: Dr' Scott Schaefer
1Computer Graphics CPSC 441
2Staff
- Instructor
- Dr. Scott Schaefer
- HRBB 527B
- Office Hours W 1030am-1130am
- Th 200pm-300pm
- (or by appointment)
- TA
- Ruoguan Huang
- HRBB 525
- Office Hours T 200pm-400pm
- F 1000am-noon
3Why did you take this class?
4Games
5Movies
6Visualization
7Industrial Design
8What will you learn in this class?
- 2D Graphics
- Drawing lines, polygons
- Fractals
- 3D Graphics
- Transformations
- Lighting
- Ray Tracing
- Solid Modeling
- Splines/Subdivision
9What youre expected to know
- Programming Experience
- Assignments in C/C
- Simple Mathematics
- Graphics is mathematics made visible
10How much math?
- General geometry/linear algebra
- Matrices
- Multiplication, inversion, determinant
- Vectors
- Dot product, cross product, linear independence
11First Homework Assignment!
- Linear Algebra Test
- http//projects.cs.tamu.edu/keyser/LAtest/
- Complete before September 16, 2009
- Take as many times as you like
- Must get at least 90 correct
- Grade ActualGrade (exam 90 ? 1 0 )
12Other Assignments
- Simple Painting Program
- Polygon Drawing and Clipping
- Fractals and Iterated Affine Transformations
- 3D Rasterization and Hidden Surfaces
- Ray Tracing
13More on Assignments
- Turn in code via CSNET
- (get an account if you dont already have one)
- Due by 1159pm on day specified
- Code, solution file and Win32 executable
- Make your code readable (comment)
- You may discuss concepts, but coding is
individual (no team coding or web)
14Grading
- 55 Assignments
- 15 Midterm
- 25 Final
- 5 Course Evaluation
15Late Policy
- Penalty m number of minutes late
100
80
60
percentage penalty
40
20
1
2
3
4
days late
16Required Textbooks
17Suggested Reading
18Introduction to OpenGL
- What is OpenGL?
- Computer-graphics API (application programming
interface) - Developed by SGI in 1992
- Efficient, streaming interface
- 250 function calls for drawing 2D and 3D
graphics - Hardware independent
- Operating system independent
- Direct3D alternative API from Microsoft
19Introduction to OpenGL
- What OpenGL is NOT
- No commands for windowing
- No commands for obtaining user input
- No commands for anything except drawing on the
screen
20A Smidgen of OpenGL Code
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
21A Smidgen of OpenGL Code
Sets the color for clearing the screen
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
22A Smidgen of OpenGL Code
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
Clears the screen
23A Smidgen of OpenGL Code
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
Sets the current drawing color to white
24A Smidgen of OpenGL Code
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
Sets the window coordinates to (0,0,-1) (1,1,1)
25A Smidgen of OpenGL Code
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
Starts drawing a polygon
26A Smidgen of OpenGL Code
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
Specifies the vertices of the polygon
27A Smidgen of OpenGL Code
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
Ends the polygon
28A Smidgen of OpenGL Code
- include ltwhateverYouNeed.hgt
- Main()
- IntializeAWindowPlease()
- glClearColor (0.0, 0.0, 0.0, 0.0)
- glClear (GL_COLOR_BUFFER_BIT)
- glColor3f ( 1.0, 1.0, 1.0)
- glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
- glBegin (GL_POLYGON)
- glVertex3f (0.25, 0.25, 0.0)
- glVertex3f (0.75, 0.25, 0.0)
- glVertex3f (0.75, 0.75, 0.0)
- glVertex3f (0.25, 0.75, 0.0)
- glEnd()
- glFlush()
- UpdateTheWindowAndCheckForEvents()
Flushes all commands to ensure polygon is drawn
29OpenGL Command Formats
glVertex3fv( v )
Prefix
Initial capital letters
Number of components
Data Type
Vector
b - byte ub - unsigned byte s - short us -
unsigned short i - int ui - unsigned int f -
float d - double
omit v for scalar form glVertex2f( x, y )
2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w)
30OpenGL Geometric Primitives
- All geometric primitives are specified by vertices
31OpenGL Drawing Functions
- glBegin (GL_POINTS)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p3)
- glVertex2iv (p4)
- glVertex2iv (p5)
- glVertex2iv (p6)
- glEnd()
P5
P6
P1
P4
P2
P3
32OpenGL Drawing Functions
- glBegin (GL_LINES)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p3)
- glVertex2iv (p4)
- glVertex2iv (p5)
- glVertex2iv (p6)
- glEnd()
P5
P6
P1
P4
P2
P3
33OpenGL Drawing Functions
- glBegin (GL_LINE_STRIP)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p3)
- glVertex2iv (p4)
- glVertex2iv (p5)
- glVertex2iv (p6)
- glEnd()
P5
P6
P1
P4
P2
P3
34OpenGL Drawing Functions
- glBegin (GL_LINE_LOOP)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p3)
- glVertex2iv (p4)
- glVertex2iv (p5)
- glVertex2iv (p6)
- glEnd()
P5
P6
P1
P4
P2
P3
35OpenGL Drawing Functions
- glBegin (GL_POLYGON)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p3)
- glVertex2iv (p4)
- glVertex2iv (p5)
- glVertex2iv (p6)
- glEnd()
P5
P6
P1
P4
P2
P3
36OpenGL Drawing Functions
- glBegin (GL_TRIANGLES)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p6)
- glVertex2iv (p3)
- glVertex2iv (p4)
- glVertex2iv (p5)
- glEnd()
P5
P6
P1
P4
P2
P3
37OpenGL Drawing Functions
- glBegin (GL_TRIANGLES_STRIP)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p6)
- glVertex2iv (p3)
- glVertex2iv (p5)
- glVertex2iv (p4)
- glEnd()
P5
P6
P1
P4
P2
P3
38OpenGL Drawing Functions
- glBegin (GL_TRIANGLES_FAN)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p3)
- glVertex2iv (p4)
- glVertex2iv (p5)
- glVertex2iv (p6)
- glEnd()
P5
P6
P1
P4
P2
P3
39OpenGL Drawing Functions
- glBegin (GL_QUADS)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p3)
- glVertex2iv (p4)
- glVertex2iv (p5)
- glVertex2iv (p6)
- glVertex2iv (p7)
- glVertex2iv (p8)
- glEnd()
P8
P1
P4
P5
P2
P6
P3
P7
40OpenGL Drawing Functions
- glBegin (GL_QUADS_STRIP)
- glVertex2iv (p1)
- glVertex2iv (p2)
- glVertex2iv (p4)
- glVertex2iv (p3)
- glVertex2iv (p5)
- glVertex2iv (p6)
- glVertex2iv (p8)
- glVertex2iv (p7)
- glEnd()
P8
P1
P4
P5
P2
P6
P3
P7
41OpenGL-Related Libraries
- GLU (OpenGL Utility Library)
- - Part of OpenGL
- - Provides higher-level drawing routines such as
- Spheres, NURBS, tessellators, quadric shapes,
etc
42OpenGL-Related Libraries
- GLU (OpenGL Utility Library)
- - Part of OpenGL
- - Provides higher-level drawing routines such as
- Spheres, NURBS, tessellators, quadric shapes,
etc - GLUT (OpenGL Utility Toolkit)
- - perform system-level I/O with the host
operating system - - cross platform
- - portable windowing API
- - not officially part of OpenGL
43GLUT OpenGL Utility Toolkit
- Application Structure
- Configure and open window
- Initialize OpenGL state
- Register input callback functions
- render
- resize
- input keyboard, mouse, etc.
- Enter event processing loop
44Sample Program
- void main( int argc, char argv)
-
- glutInit (argc, argv)
- glutInitDisplayMode (GLUT_SINGLE GLUT_RGB )
- glutInitWindowSize (250, 250)
- glutInitWindowPosition (100, 100)
- glutCreateWindow ( "HELLO")
- init()
- glutDisplayFunc ( display )
- glutMainLoop()
/ OpenGL Initialization /
/ callback function /
45GLUT Callback Functions
- Routine to call when something happens
- window resized, user input, window needs drawing,
etc - Register callbacks with GLUT
- glutDisplayFunc( display )
- glutIdleFunc( idle )
- glutKeyboardFunc( keyboard )
- glutMouseFunc( mouse )
46Assignment 1 Simple OpenGL/GLUT Application
- Build a simple OpenGL/GLUT application
- Designed to get you started using OpenGL and
callbacks for interaction - Full description available on course webpage
- http//courses.cs.tamu.edu/schaefer/441_Fall2009