Top Banner
1 A first OpenGL program Brian Farrimond Robina Hetherington
34

1 A first OpenGL program Brian Farrimond Robina Hetherington.

Dec 13, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

1

A first OpenGL program

Brian Farrimond

Robina Hetherington

Page 2: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

2

Ex01

• Build and run Ex01

Page 3: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

3

Program structure

Three function program

Page 4: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

4

main

Page 5: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

5

main

•Always present•Uses RGB colours (Red, Green, Blue)

Page 6: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

6

main

Sets up the scene window

Page 7: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

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: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

8

main

Set up the graphical characteristics of the new window

Page 9: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

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: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

10

init

Set projection to be orthographic

Page 11: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

11

Projections

• Orthographic projection shows no perspective

Page 12: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

12

Orthographic projection

• glOrtho(left, right, bottom, top, near, far)

Page 13: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

13

main

Page 14: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

14

main

Name of the function that will draw the scene

Page 15: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

15

display

Page 16: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

16

display

Clear the window using the

background colour

Page 17: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

17

display

glColor3f(red, green, blue)

Min value: 0.0Max value: 1.0

Exercise: Make the rectangle yellow

Page 18: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

18

display

Draw the rectangle (polygon with four vertices)

Page 19: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

19

glVertex(x, y, z)

Page 20: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

20

glVertex(x, y, z)

Page 21: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

21

glVertex(x, y, z)

Page 22: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

22

glVertex(x, y, z)

Page 23: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

23

glVertex(x, y, z)

Page 24: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

24

glVertex(x, y, z) Vertices are in anticlockwise order

Page 25: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

25

glOrtho(left, right, bottom, top, near, far);glOrtho(0.0 , 1.0, 0.0, 1.0, -1.0, 1.0);

Page 26: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

26

glOrtho(left, right, bottom, top, near, far);glOrtho(-0.5, 1.0, 0.0, 1.5, -1.0, 1.0);

Page 27: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

27

The new projection

Page 28: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

28

main

How we manage animation and interaction

Page 29: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

29

OpenGL drawing primitives

Page 30: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

30

OpenGL drawing primitives

Page 31: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

31

OpenGL drawing primitives

Page 32: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

32

OpenGL drawing primitives

Page 33: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

33

OpenGL drawing primitives

Page 34: 1 A first OpenGL program Brian Farrimond Robina Hetherington.

34

OpenGL drawing primitives