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
Observation • Apply transformation • Barycentric Interpolation • Rasterize • Compute Light and Shading (More on it later) • Lookup Textures (More on it later) • And lot more …. 3 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Observation To Millions of Triangles • Apply transformation and • Barycentric Interpolation Billions of Fragments • Rasterize • Compute Light and Shading (More on it later) • Lookup Textures (More on it later) • And lot more …. 4 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Observation To Millions of Triangles • Apply transformation and • Barycentric Interpolation Billions of Fragments • Rasterize • Compute Light and Shading (More on it later) • Lookup Textures (More on it later) • And lot more …. SIMD (Single Instruction Multiple Data) 5 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Graphics Hardware GTX 1080 2560 cores! (upto 1733 MHz, 8GB Mem) http://www.geforce.com/hardware/10series/geforce-gtx-1080 6 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Advice Leave implementation of low-level features to the experts. 7 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Advice Leave implementation of low-level features to the experts. Why ? • Abstract away hardware differences • Rasterization should be fast 8 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Introducing … Industry Standard API for Computer Graphics (Cross Platform, since 1992) 9 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Not the Only One 10 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Related APIs in the OpenGL Family Angry Birds by Rovio Google Maps 11 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Related APIs in the OpenGL Family Angry Birds by Rovio Google Maps 12 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL 1.x 13 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL 1.x: Why ? • Easy to learn! • Little code • Instructional 14 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Simple First Program 15 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
What OpenGL Is Not OpenGL is not a windowing system 16 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
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, … 17 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
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, … Other options: glfw, SDL 18 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
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, … 19 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Simple First Program Projection Matrix ! (GL_PROJECTION) 20 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Simple First Program Camera and Model Matrices Combined ! (GL_MODELVIEW) 21 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
gluLookAt(eye, at, up) where is the viewpoint? which way is up? where is it pointed? up eye at defines the camera/viewing matrix! 22 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
gluPerspective(fovy, aspect, near, far) The Redbook, fig. 3-14 (p. 155) 23 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Transformation Recall 24 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Transformation Recall NDC à Viewport Transformation à Final Image 25 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
glViewport(x, y, width, height) width height (x, y) at lower left 26 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Primitive [prim-i-tiv]: A small piece of geometry that can be rendered in OpenGL; e.g. triangles, lines, points etc. 27 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL Primitive Types http://www.opengl2go.net/wp-content/uploads/2015/10/gl-primitives-with-background.png 28 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL Primitives (Triangles) 3 6 5 1 2 4 29 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL Primitives (Triangle Strip) 2 4 5 1 3 30 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL Primitives (Triangle Strip) 2 4 5 1 3 Immediate Mode (Deprecated) 31 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Color: glColor3f(red,green,blue) v 1 v 3 v 2 32 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
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 33 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
GL, GLU, and GLUT notations glVertex3f(...) ...3f takes 3 floats ...3d takes 3 doubles ...3i takes 3 integers ...2f takes 2 floats ...4f takes 4 floats (etc) 34 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Composing Transformations glLoadMatrixf(A); glMultMatrixf(B); glMultMatrixf(C); 35 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Convenience Functions • glTranslatef(tx, ty, tz) • glRotatef(degrees, x, y, z) • glScalef(sx, sy, sz) 36 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Hierarchical Modeling translate(0,4) drawTorso() pushMatrix() translate(1.5,0) rotateX(leftHipRotate) drawThigh() pushMatrix() translate(0,-2) rotateX(leftKneeRotate) drawLeg() ... popMatrix() popMatrix() pushMatrix() y translate(0,4) translate(1.5,0) rotateX(leftHipRotate) translate(-1.5,0) rotateX(rightHipRotate) translate(0,4) // Draw the right side x Matrix Stack ... ... CurrentMatrix = translate(0,4) translate(1.5,0) rotateX(leftHipRotate) translate(0,-2) rotate(leftKneeRotate) 37 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL Matrix Stack 38 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL 1.x Pipeline (Simplified) http://upload.wikimedia.org/wikipedia/commons/b/bb/Pipeline_OpenGL_%28en%29.png 39 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL 1.x Pipeline (Unsimplified) http://www.opengl.org/documentation/specs/version1.1/state.pdf 40 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
OpenGL 1.x Pipeline (Unsimplified) http://www.opengl.org/documentation/specs/version1.1/state.pdf 41 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Pieces of the Pipeline Stores “subroutines” GLuint boxList; boxList = glGenLists(1); glNewList(boxList, GL_COMPILE); // draw box glEndList(boxList); … glCallList(boxList); 42 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Pieces of the Pipeline Stores “subroutines” 43 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Pieces of the Pipeline Construct geometric objects 44 CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain
Recommend
More recommend