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