OpenGL CS 148: Summer 2016 Introduction of Graphics and Imaging - - PowerPoint PPT Presentation

opengl
SMART_READER_LITE
LIVE PREVIEW

OpenGL CS 148: Summer 2016 Introduction of Graphics and Imaging - - PowerPoint PPT Presentation

OpenGL CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain http://www.pling.org.uk/cs/cgv.html So Far: Theory of Rasterization 2 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) Zahid Hossain


slide-1
SLIDE 1

CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain

OpenGL

http://www.pling.org.uk/cs/cgv.html

slide-2
SLIDE 2

So Far: Theory of Rasterization

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 2

slide-3
SLIDE 3

Observation

  • Apply transformation
  • Barycentric Interpolation
  • Rasterize
  • Compute Light and Shading (More on it later)
  • Lookup Textures (More on it later)
  • And lot more ….

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 3

slide-4
SLIDE 4

Observation

  • Apply transformation
  • Barycentric Interpolation
  • Rasterize
  • Compute Light and Shading (More on it later)
  • Lookup Textures (More on it later)
  • And lot more ….

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4

To Millions of Triangles and Billions of Fragments

slide-5
SLIDE 5

Observation

  • Apply transformation
  • Barycentric Interpolation
  • Rasterize
  • Compute Light and Shading (More on it later)
  • Lookup Textures (More on it later)
  • And lot more ….

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 5

To Millions of Triangles and Billions of Fragments

SIMD (Single Instruction Multiple Data)

slide-6
SLIDE 6

Graphics Hardware

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 6

2560 cores! (upto 1733 MHz, 8GB Mem)

http://www.geforce.com/hardware/10series/geforce-gtx-1080

GTX 1080

slide-7
SLIDE 7

Advice

Leave implementation of low-level features to the experts.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 7

slide-8
SLIDE 8

Advice

Leave implementation of low-level features to the experts. Why ?

  • Abstract away hardware differences
  • Rasterization should be fast

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 8

slide-9
SLIDE 9

Introducing …

Industry Standard API for Computer Graphics (Cross Platform, since 1992)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 9

slide-10
SLIDE 10

Not the Only One

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 10

slide-11
SLIDE 11

Related APIs in the OpenGL Family

Google Maps Angry Birds by Rovio

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 11

slide-12
SLIDE 12

Related APIs in the OpenGL Family

Google Maps Angry Birds by Rovio

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 12

slide-13
SLIDE 13

OpenGL 1.x

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 13

slide-14
SLIDE 14

OpenGL 1.x: Why ?

  • Easy to learn!
  • Little code
  • Instructional

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 14

slide-15
SLIDE 15

Simple First Program

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 15

slide-16
SLIDE 16

What OpenGL Is Not

OpenGL is not a windowing system

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 16

slide-17
SLIDE 17

Introducing GLUT (GL Utility Toolkit)

  • Simple cross-platform windowing API
  • glutInitDisplay(),

glutInitWindowSize(..)

  • Bindings: C, C++, Fortran, Ada, …
  • Features:
  • Multiple windows, menus
  • Keyboard/mouse/other input
  • Assorted callbacks: idle, timers
  • Basic font support‘
  • glutSolidTeapot,

glutSolidSphere, glutSolidCube, …

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 17

slide-18
SLIDE 18

Introducing GLUT (GL Utility Toolkit)

  • Simple cross-platform windowing API
  • glutInitDisplay(),

glutInitWindowSize(..)

  • Bindings: C, C++, Fortran, Ada, …
  • Features:
  • Multiple windows, menus
  • Keyboard/mouse/other input
  • Assorted callbacks: idle, timers
  • Basic font support‘
  • glutSolidTeapot,

glutSolidSphere, glutSolidCube, …

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 18

Other options: glfw, SDL

slide-19
SLIDE 19

Introducing GLU (GL Utility)

  • High-level graphics commands
  • Not included in OpenGL ES
  • Some interesting features:
  • Mapping between world and screen coordinates
  • Texturing support
  • Tessellation and other geometric utilities
  • OpenGL error code lookup
  • More primitives: spheres, cylinders, disks, …
  • Camera support: gluLookAt,

gluOrtho2D, …

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 19

slide-20
SLIDE 20

Simple First Program

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 20

Projection Matrix ! (GL_PROJECTION)

slide-21
SLIDE 21

Simple First Program

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 21

Camera and Model Matrices Combined ! (GL_MODELVIEW)

slide-22
SLIDE 22

gluLookAt(eye, at, up)

defines the camera/viewing matrix! where is the viewpoint? where is it pointed? which way is up?

eye at up

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 22

slide-23
SLIDE 23

gluPerspective(fovy, aspect, near, far)

The Redbook, fig. 3-14 (p. 155)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 23

slide-24
SLIDE 24

Transformation Recall

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 24

slide-25
SLIDE 25

Transformation Recall

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 25

NDC à Viewport Transformation à Final Image

slide-26
SLIDE 26

glViewport(x, y, width, height)

(x, y) at lower left height width

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 26

slide-27
SLIDE 27

Primitive [prim-i-tiv]:

A small piece of geometry that can be rendered in OpenGL; e.g. triangles, lines, points etc.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 27

slide-28
SLIDE 28

OpenGL Primitive Types

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 28

http://www.opengl2go.net/wp-content/uploads/2015/10/gl-primitives-with-background.png

slide-29
SLIDE 29

OpenGL Primitives (Triangles)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 29

1 2 3 4 5 6

slide-30
SLIDE 30

OpenGL Primitives (Triangle Strip)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 30

1 2 3 4 5

slide-31
SLIDE 31

OpenGL Primitives (Triangle Strip)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 31

1 2 3 4 5

Immediate Mode (Deprecated)

slide-32
SLIDE 32

Color: glColor3f(red,green,blue)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 32

v1 v2 v3

slide-33
SLIDE 33

GL, GLU, and GLUT notations

gl... e.g., glColor3f(...) core OpenGL function glu... e.g., gluLookAt(...) OpenGL utility function, makes common tasks easier (defined in terms of gl... functions) glut... e.g., glutSolidTeapot(...) GLUT functions

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 33

slide-34
SLIDE 34

GL, GLU, and GLUT notations

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 34

glVertex3f(...)

...3f takes 3 floats ...3d takes 3 doubles ...3i takes 3 integers ...2f takes 2 floats ...4f takes 4 floats (etc)

slide-35
SLIDE 35

Composing Transformations

glLoadMatrixf(A); glMultMatrixf(B); glMultMatrixf(C);

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 35

slide-36
SLIDE 36

Convenience Functions

  • glTranslatef(tx, ty, tz)
  • glRotatef(degrees, x, y, z)
  • glScalef(sx, sy, sz)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 36

slide-37
SLIDE 37

Hierarchical Modeling

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 37 translate(0,4) drawTorso() pushMatrix() translate(1.5,0) rotateX(leftHipRotate) drawThigh() pushMatrix() translate(0,-2) rotateX(leftKneeRotate) drawLeg() ... popMatrix() popMatrix() pushMatrix() translate(-1.5,0) rotateX(rightHipRotate) // Draw the right side ... ...

x y

CurrentMatrix = translate(0,4) translate(1.5,0) rotateX(leftHipRotate) translate(0,-2) rotate(leftKneeRotate) Matrix Stack

translate(0,4) translate(0,4) translate(1.5,0) rotateX(leftHipRotate)

slide-38
SLIDE 38

OpenGL Matrix Stack

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 38

slide-39
SLIDE 39

OpenGL 1.x Pipeline (Simplified)

http://upload.wikimedia.org/wikipedia/commons/b/bb/Pipeline_OpenGL_%28en%29.png

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 39

slide-40
SLIDE 40

OpenGL 1.x Pipeline (Unsimplified)

http://www.opengl.org/documentation/specs/version1.1/state.pdf

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 40

slide-41
SLIDE 41

OpenGL 1.x Pipeline (Unsimplified)

http://www.opengl.org/documentation/specs/version1.1/state.pdf

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 41

slide-42
SLIDE 42

Pieces of the Pipeline

Stores “subroutines”

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 42

GLuint boxList; boxList = glGenLists(1); glNewList(boxList, GL_COMPILE); // draw box glEndList(boxList); … glCallList(boxList);

slide-43
SLIDE 43

Pieces of the Pipeline

Stores “subroutines”

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 43

slide-44
SLIDE 44

Pieces of the Pipeline

Construct geometric objects

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 44

slide-45
SLIDE 45

Pieces of the Pipeline

Change geometry Store primitive shapes

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 45

slide-46
SLIDE 46

Pieces of the Pipeline

Change geometry Store primitive shapes

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 46

Includes Clipping

slide-47
SLIDE 47

Pieces of the Pipeline

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 47

slide-48
SLIDE 48

Fragment [frag-muhnt]:

The data necessary to generate a single pixel’s worth

  • f a primitive.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 48

slide-49
SLIDE 49

Pieces of the Pipeline

Modify and combine per-pixel information

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 49

slide-50
SLIDE 50

Pieces of the Pipeline

Prepare image to be displayed

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 50

slide-51
SLIDE 51

OpenGL State Machine

Change State Draw Draw Change State Draw Change State Change State Draw

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 51

slide-52
SLIDE 52

OpenGL State Machine

glColor3f(…) glEnable(…) glLineStipple(…) glGetFloatv(…) glIsEnabled(…) glGetLineStipple(…)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 52

Set State Get State

slide-53
SLIDE 53

OpenGL State Machine

glColor3f(…) glEnable(…) glLineStipple(…) glGetFloatv(…) glIsEnabled(…) glGetLineStipple(…)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 53

Efficiently managing state changes is a major implementation challenge

Set State Get State

slide-54
SLIDE 54

OUT OF DATE.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 54

slide-55
SLIDE 55

OUT OF DATE.

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 55

slide-56
SLIDE 56

Vertex Lighting

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 56

slide-57
SLIDE 57

Normal

A vector perpendicular to a surface; constant over a plane

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 57

https://en.wikipedia.org/wiki/Normal_(geometry)

slide-58
SLIDE 58

Specifying Normals

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 58

1 2 3 1 2 3

slide-59
SLIDE 59

Vertex Lighting

  • Diffuse Term

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 59

slide-60
SLIDE 60

Vertex Lighting

  • Specular Term

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 60

Camera

slide-61
SLIDE 61

Vertex Lighting

  • Specular Term

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 61

Camera

slide-62
SLIDE 62

Vertex Lighting

  • Specular Term

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 62

Camera Ambient Light

slide-63
SLIDE 63

Vertex Lighting

  • Specular Term

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 63

Camera Ambient Light

slide-64
SLIDE 64

Vertex Lighting

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 64

Enable a Light Setup material

slide-65
SLIDE 65

Vertex Lighting

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 65

Enable a Light Setup material

Note: w=0 is directional light glutSolidTeapot specifies the normal in this case

slide-66
SLIDE 66

Vertex Lighting: Types

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 66

http://www.computing.northampton.ac.uk/~gary/csy3019/images3d/lightSources.gif

slide-67
SLIDE 67

Vertex & Index Buffers

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 67

slide-68
SLIDE 68

Vertex/Index Buffer

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 68

8 vertices only

slide-69
SLIDE 69

Vertex/Index Buffer

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 69

Drawing with triangles: 36 vertices!

8 vertices only

slide-70
SLIDE 70

Vertex/Index Buffer

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 70

8 vertices only

Vertices = { v0,v1,.. V7 } Indices = { 0,1,2, 0,2,3, 1,5,6, 1,6,2 …... } v0 v1 v2 v3 v5 v6 v7

slide-71
SLIDE 71

Vertex/Index Buffer

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 71

slide-72
SLIDE 72

Next Generation APIs

  • Vulkan (Nextgen OpenGL)
  • DirectX 12 (Microsoft)
  • Metal (Apple)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 72

slide-73
SLIDE 73

Next Generation APIs

  • Vulkan (Nextgen OpenGL)
  • DirectX 12 (Microsoft)
  • Metal (Apple)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 73

slide-74
SLIDE 74

CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain

OpenGL

http://www.pling.org.uk/cs/cgv.html