opengl - github pages › cs148 › assets › slides › 05-opengl.pdf · hierarchical modeling cs...

74
CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain OpenGL http://www.pling.org.uk/cs/cgv.html

Upload: others

Post on 04-Jul-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

CS 148: Summer 2016Introduction of Graphics and ImagingZahid Hossain

OpenGL

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

Page 2: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

SoFar:TheoryofRasterization

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

Page 3: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Observation

• Applytransformation• Barycentric Interpolation• Rasterize• ComputeLightandShading(Moreonitlater)• LookupTextures(Moreonitlater)• Andlotmore….

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

Page 4: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Observation

• Applytransformation• Barycentric Interpolation• Rasterize• ComputeLightandShading(Moreonitlater)• LookupTextures(Moreonitlater)• Andlotmore….

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

To Millions of Triangles

and Billions of Fragments

Page 5: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Observation

• Applytransformation• Barycentric Interpolation• Rasterize• ComputeLightandShading(Moreonitlater)• LookupTextures(Moreonitlater)• Andlotmore….

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)

Page 6: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

GraphicsHardware

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

GTX1080

Page 7: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Advice

Leaveimplementationoflow-levelfeaturestotheexperts.

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

Page 8: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Advice

Leaveimplementationoflow-levelfeaturestotheexperts.

Why?

• Abstractawayhardwaredifferences

• Rasterizationshouldbefast

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

Page 9: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Introducing…

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

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

Page 10: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

NottheOnlyOne

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

Page 11: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

RelatedAPIsintheOpenGLFamily

GoogleMaps

AngryBirdsbyRovio

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

Page 12: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

RelatedAPIsintheOpenGLFamily

GoogleMaps

AngryBirdsbyRovio

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

Page 13: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGL1.x

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

Page 14: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGL1.x:Why?

•Easytolearn!•Littlecode•Instructional

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

Page 15: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

SimpleFirstProgram

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

Page 16: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

WhatOpenGLIsNot

OpenGLisnotawindowingsystem

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

Page 17: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

IntroducingGLUT(GLUtilityToolkit)

• Simplecross-platformwindowingAPI• glutInitDisplay(), glutInitWindowSize(..)

• Bindings:C,C++,Fortran,Ada,…• Features:• Multiplewindows,menus• Keyboard/mouse/otherinput• Assortedcallbacks:idle,timers• Basicfontsupport‘• glutSolidTeapot, glutSolidSphere, glutSolidCube, …

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

Page 18: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

IntroducingGLUT(GLUtilityToolkit)

• Simplecross-platformwindowingAPI• glutInitDisplay(), glutInitWindowSize(..)

• Bindings:C,C++,Fortran,Ada,…• Features:• Multiplewindows,menus• Keyboard/mouse/otherinput• Assortedcallbacks:idle,timers• Basicfontsupport‘• glutSolidTeapot, glutSolidSphere, glutSolidCube, …

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

Other options: glfw, SDL

Page 19: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

IntroducingGLU(GLUtility)• High-levelgraphicscommands• Not includedinOpenGLES• Someinterestingfeatures:• Mappingbetweenworldandscreencoordinates• Texturingsupport• Tessellationandothergeometricutilities• OpenGLerrorcodelookup• Moreprimitives:spheres,cylinders,disks,…• Camerasupport:gluLookAt, gluOrtho2D, …

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

Page 20: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

SimpleFirstProgram

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

Projection Matrix !(GL_PROJECTION)

Page 21: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

SimpleFirstProgram

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

Camera and Model Matrices Combined !

(GL_MODELVIEW)

Page 22: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

gluLookAt(eye,at,up)

defines thecamera/viewingmatrix!

whereistheviewpoint?

whereisitpointed?

whichwayisup?

eyeat

up

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

Page 23: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

gluPerspective(fovy,aspect,near,far)

TheRedbook, fig.3-14(p.155)

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

Page 24: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

TransformationRecall

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

Page 25: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

TransformationRecall

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

NDC à Viewport Transformation à Final Image

Page 26: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

glViewport(x,y,width,height)

(x,y)atlowerleft

height

width

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

Page 27: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Primitive[prim-i-tiv]:

AsmallpieceofgeometrythatcanberenderedinOpenGL;e.g.triangles,lines,pointsetc.

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

Page 28: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGLPrimitiveTypes

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

Page 29: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGLPrimitives(Triangles)

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

1 2

3

4 5

6

Page 30: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGLPrimitives(TriangleStrip)

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

1

2

3

4

5

Page 31: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGLPrimitives(TriangleStrip)

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

1

2

3

4

5

Immediate Mode(Deprecated)

Page 32: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Color:glColor3f(red,green,blue)

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

v1

v2

v3

Page 33: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

GL,GLU,andGLUTnotationsgl...

e.g.,glColor3f(...)coreOpenGLfunction

glu...e.g.,gluLookAt(...)

OpenGLutilityfunction,makescommontaskseasier(defined intermsofgl...functions)

glut...e.g.,glutSolidTeapot(...)

GLUTfunctions

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

Page 34: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

GL,GLU,andGLUTnotations

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

glVertex3f(...)...3f takes3floats...3d takes3doubles...3i takes3integers

...2f takes2floats

...4f takes4floats(etc)

Page 35: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

ComposingTransformationsglLoadMatrixf(A);glMultMatrixf(B);glMultMatrixf(C);

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

Page 36: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

ConvenienceFunctions

• 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

Page 37: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

HierarchicalModeling

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)

MatrixStack

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

Page 38: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGLMatrixStack

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

Page 39: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGL1.xPipeline(Simplified)

http://upload.wikimedia.org/wikipedia/commons/b/bb/Pipeline_OpenGL_%28en%29.pngCS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 39

Page 40: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGL1.xPipeline(Unsimplified)

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

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

Page 41: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGL1.xPipeline(Unsimplified)

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

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

Page 42: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

PiecesofthePipeline

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 boxglEndList(boxList);…glCallList(boxList);

Page 43: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

PiecesofthePipeline

Stores“subroutines”

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

Page 44: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

PiecesofthePipeline

Constructgeometricobjects

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

Page 45: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

PiecesofthePipeline

Changegeometry

Storeprimitiveshapes

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

Page 46: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

PiecesofthePipeline

Changegeometry

Storeprimitiveshapes

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

Includes Clipping

Page 47: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

PiecesofthePipeline

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

Page 48: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Fragment[frag-muhnt]:

Thedatanecessarytogenerateasinglepixel’sworthofaprimitive.

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

Page 49: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

PiecesofthePipeline

Modifyandcombineper-pixel

information

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

Page 50: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

PiecesofthePipeline

Prepareimagetobedisplayed

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

Page 51: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGLStateMachine

ChangeStateDrawDraw

ChangeStateDraw

ChangeStateChangeState

Draw

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

Page 52: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGLStateMachine

glColor3f(…)

glEnable(…)

glLineStipple(…)

glGetFloatv(…)

glIsEnabled(…)

glGetLineStipple(…)

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

SetState GetState

Page 53: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OpenGLStateMachine

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

SetState GetState

Page 54: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OUT OF DATE.

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

Page 55: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

OUT OF DATE.

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

Page 56: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting

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

Page 57: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Normal

Avectorperpendiculartoasurface;constantoveraplane

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

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

Page 58: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

SpecifyingNormals

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

1

2

3

1

2

3

Page 59: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting

• DiffuseTerm

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

Page 60: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting

• SpecularTerm

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

Camera

Page 61: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting

• SpecularTerm

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

Camera

Page 62: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting

• SpecularTerm

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

Camera

AmbientLight

Page 63: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting

• SpecularTerm

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

Camera

AmbientLight

Page 64: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting

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

EnableaLight

Setupmaterial

Page 65: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting

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

EnableaLight

Setupmaterial

Note: w=0 is directional light

glutSolidTeapot specifies the normal in this case

Page 66: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

VertexLighting: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

Page 67: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Vertex&IndexBuffers

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

Page 68: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Vertex/IndexBuffer

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

8 vertices only

Page 69: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Vertex/IndexBuffer

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

Drawing with triangles: 36 vertices!

8 vertices only

Page 70: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Vertex/IndexBuffer

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

Page 71: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

Vertex/IndexBuffer

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

Page 72: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

NextGenerationAPIs

• Vulkan (NextgenOpenGL)• DirectX12(Microsoft)• Metal(Apple)

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

Page 73: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

NextGenerationAPIs

• Vulkan (NextgenOpenGL)• DirectX12(Microsoft)• Metal(Apple)

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

Page 74: OpenGL - GitHub Pages › cs148 › assets › slides › 05-OpenGL.pdf · Hierarchical Modeling CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain

CS 148: Summer 2016Introduction of Graphics and ImagingZahid Hossain

OpenGL

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