Page 1
1
A first OpenGL program
Brian Farrimond
Robina Hetherington
Page 2
2
Ex01
• Build and run Ex01
Page 3
3
Program structure
Three function program
Page 5
5
main
•Always present•Uses RGB colours (Red, Green, Blue)
Page 6
6
main
Sets up the scene window
Page 7
7
Window exercises
• Double the size of the window height and width• Make the window start at the top left corner of
the screen• Change the window title to “2D OpenGL”
Page 8
8
main
Set up the graphical characteristics of the new window
Page 9
9
initSet the background colour:•red•green•blue•alpha (transparency)
Min value: 0.0Max value: 1.0
Exercise:
Set the background colour to red
Page 10
10
init
Set projection to be orthographic
Page 11
11
Projections
• Orthographic projection shows no perspective
Page 12
12
Orthographic projection
• glOrtho(left, right, bottom, top, near, far)
Page 14
14
main
Name of the function that will draw the scene
Page 16
16
display
Clear the window using the
background colour
Page 17
17
display
glColor3f(red, green, blue)
Min value: 0.0Max value: 1.0
Exercise: Make the rectangle yellow
Page 18
18
display
Draw the rectangle (polygon with four vertices)
Page 19
19
glVertex(x, y, z)
Page 20
20
glVertex(x, y, z)
Page 21
21
glVertex(x, y, z)
Page 22
22
glVertex(x, y, z)
Page 23
23
glVertex(x, y, z)
Page 24
24
glVertex(x, y, z) Vertices are in anticlockwise order
Page 25
25
glOrtho(left, right, bottom, top, near, far);glOrtho(0.0 , 1.0, 0.0, 1.0, -1.0, 1.0);
Page 26
26
glOrtho(left, right, bottom, top, near, far);glOrtho(-0.5, 1.0, 0.0, 1.5, -1.0, 1.0);
Page 27
27
The new projection
Page 28
28
main
How we manage animation and interaction
Page 29
29
OpenGL drawing primitives
Page 30
30
OpenGL drawing primitives
Page 31
31
OpenGL drawing primitives
Page 32
32
OpenGL drawing primitives
Page 33
33
OpenGL drawing primitives
Page 34
34
OpenGL drawing primitives