1 a first opengl program brian farrimond robina hetherington

34
1 A first OpenGL program Brian Farrimond Robina Hetherington

Upload: george-henderson

Post on 13-Dec-2015

221 views

Category:

Documents


1 download

TRANSCRIPT

1

A first OpenGL program

Brian Farrimond

Robina Hetherington

2

Ex01

• Build and run Ex01

3

Program structure

Three function program

4

main

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)

13

main

14

main

Name of the function that will draw the scene

15

display

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