David Luebke1/5/2016 CS 551 / 645: Introductory Computer Graphics David Luebke

Slides:



Advertisements
Similar presentations
Computer Graphics 2D & 3D Transformation.
Advertisements

02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
Graphics Pipeline.
2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
Based on slides created by Edward Angel
Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL and Projections
Further Programming for 3D applications CE Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and.
Sep 30, I3I3DG&VR CE00539-m Interactive 3D Graphics and Virtual Reality Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
OpenGL Tutorial Jason Lawrence COS426 Precept Notes 2/16/04.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
Development of Interactive 3D Virtual World Applications
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology 3D Engines and Scene Graphs Spring 2012.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 CSE 872 Advanced Computer Graphics Charles B. Owen (Instructor) – 1138 E. B., MW 12:30-1:50pm.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
COMP 175: Computer Graphics March 10, 2015
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Geometric transformations The Pipeline
Hank Childs, University of Oregon
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Lecture 9: Lighting and Shading 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Hank Childs, University of Oregon Nov. 14th, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 13: CW/CCW, constructing geometry.
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 4: Transformations 2
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Computer Viewing.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Computer Science Term 1, 2006 Tutorial 2 Assignment 3 – The Virtual World.
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
Project 5 Lamp Shader Fri, Nov 7, 2003 Due Mon, Nov 17, 2003.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
1/50 CS148: Introduction to Computer Graphics and Imaging Transforms CS148: Introduction to Computer Graphics and Imaging Transforms.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Hierarchical Modeling.
Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Chap 3 Viewing and Transformation
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
OpenGL LAB III.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
Viewing.
Hank Childs, University of Oregon
Computer Viewing.
Reference1. [OpenGL course slides by Rasmus Stenholt]
Computer Graphics 3Practical Lesson
Presentation transcript:

David Luebke1/5/2016 CS 551 / 645: Introductory Computer Graphics David Luebke

David Luebke1/5/2016 Recap: OpenGL l OpenGL provides an interface and implementation for interactive rendering. l It has become a standard because: –A standard was badly needed –OpenGL is pretty good –SGI promoted it and Microsoft (sorta) bought in l OpenGl is particularly tuned to hardware- accelerated transformation, lighting, texturing, and Z-buffering

David Luebke1/5/2016 Recap: OpenGL Conventions Functions in OpenGL start with gl (or glu ) l Function names indicate argument type/# –E.g., glColor3f() vs glColor3fv() vs glColor4ub() Geometry is specified as a list of vertices between glBegin() and glEnd() calls: glBegin(GL_POLYGON); glVertex3f(x1, y1, z1); glVertex3f(x2, y2, z2); glVertex3f(x3, y3, z3); glEnd();

David Luebke1/5/2016 Recap: Miscellaneous OpenGL l The vertices of the front side of a polygon are ordered counterclockwise You can draw multiple triangles between glBegin(GL_TRIANGLES) and glEnd() The GL_TRIANGLE_STRIP primitive reduces redundancy by sharing vertices: v0v0 v2v2 v1v1 v3v3 v4v4 v5v5

David Luebke1/5/2016 Miscellaneous OpenGL The GL_TRIANGLE_FAN primitive is another way to reduce vertex redundancy: v0v0 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6

David Luebke1/5/2016 Recap: OpenGL Lighting OpenGL binds our Phong lighting coefficients ( k a, k d, k s, n shiny ) into materials Calling glMaterialfv() sets a single attribute of the current material l Example: float green[] = {0, 1, 0, 1}; float white[] = {1, 1, 1, 1}; glMaterialfv(GL_FRONT, GL_DIFFUSE, green); glMaterialfv(GL_FRONT, GL_SPECULAR, white);

David Luebke1/5/2016 Recap: OpenGL Lighting OpenGL supports at least 8 lights, with parameters set by the glLight() call: float l_amb [] = {.1,.1,.1, 1.0}; float l_diff[] = {1, 0, 0, 1}; float l_spec[] = {1, 1, 1, 1}; float l_pos[] = {10, 100, 30, 0}; glLightfv(GL_LIGHT0, GL_AMBIENT, l_amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, l_diff); glLightfv(GL_LIGHT0, GL_SPECULAR, l_spec); glLightfv(GL_LIGHT0, GL_POSITION, l_pos); (the 4 th coordinate in l_pos is 0.0 for a directional light, 1.0 for a point light)

Errata: OpenGL Lighting l Recall the Phong lighting model: l OpenGL modifies this slightly: –Each light contributes separately to ambient term –Lights have a separate intensity for specular reflection (Why might this be useful?)

David Luebke1/5/2016 OpenGL: Lighting l Don’t forget to enable lighting and each light: glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); l Can set the lighting model too: –Intensity of the ambient light source –Whether to treat eye point as infinitely far away –Whether to perform lighting calculations for both sides of polygons –All these things have reasonable default values –man glLightModel for details

David Luebke1/5/2016 OpenGL: Display Lists l OpenGL can “compile” a series of rendering commands into a display list... glNewList(1, GL_COMPILE); glBegin(GL_TRIANGLES); glVertex3fv(v0); /* draw lots of triangles… */ glVertex3fv(v2); glEnd(); glEndList(); l …which can be rendered with a single call: glCallList(1);

David Luebke1/5/2016 OpenGL: Display Lists l Display lists can contain: –Geometry –Color, material, and texture specifications –Matrix transforms (up shortly) –Other display lists! l Display lists are not only handy, they usually increase performance –Why might OpenGL be able to render a series of commands faster if they have been compiled into a display list?

David Luebke1/5/2016 OpenGL: Matrix Manipulation OpenGL keeps two matrices that vertices are multiplied by upon calling glVertex() –The modelview matrix combines all modeling transforms and the viewing transform –The projection matrix performs the projection (usually a perspective projection) –Various commands affect the current matrix –You need to specify which matrix is current: E.g., glMatrixMode(GL_MODELVIEW) or glMatrixMode(GL_PROJECTION) –glLoadIdentity() replaces the contents of the current matrix with the identity matrix

David Luebke1/5/2016 OpenGL: Modeling Transforms l Some OpenGL commands generate transformation matrices: glTranslatef(Tx, Ty, Tz); glRotatef(angleDegrees, Ax, Ay, Az); glScalef(Sx, Sy, Sz); l The resulting matrix concatenates to the right of the current matrix

David Luebke1/5/2016 OpenGL: Modeling Transforms l Example: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(…); glRotatef(…); l Result: the modelview matrix is set to: I T R == T R which then multiplies all following vertices –Thus transformations appearing last in the program have the first effect on the geometry

David Luebke1/5/2016 OpenGL: Viewing Transforms l Viewing transforms are treated the same way Ex: gluLookAt() computes a lookat matrix and concatenates it with the current matrix: gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); –Again, this matrix postmultiplies the current matrix –Should gluLookAt() be called first or last?

David Luebke1/5/2016 OpenGL: Projection Transforms l The projection matrix is generally used for the perspective projection matrix –Why do you suppose OpenGL separates the modelview and projection matrices? gluPerspective() creates a projection matrix similarly to the call in assignment 6 gluPerspective(double FOVy, double aspect, double near, double far); –FOVy: field of view (°) in the y vertical (y) direction aspect: viewport width (y) divided by height (x)

David Luebke1/5/2016 The Scene Graph l Recall the concept of instancing, or using the same geometry for multiple objects –Example: 4 wheels on car –How might we use display lists for instancing? n Compile geometry (say a car tire, centered about the origin) into a display list n Set up matrices: viewing transform + modeling transform(s) to put origin at front left corner of car n Call display list for tire n Set up matrices, this time putting origin at front right of car n Call display list for tire [Etc…] –Why is this inefficient?

David Luebke1/5/2016 The Scene Graph l Answer: because many objects in a scene typically share multiple transformations l The scene graph captures transformations and object-object relationships in a DAG: Robot BodyHead ArmTrunkLegEyeMouth Objects Instancing (i.e, a matrix) Legend World

David Luebke1/5/2016 The Scene Graph l Traverse the scene graph in depth-first order, concatenating and undoing transforms: –For example, to render the robot: n Apply robot  head matrix u Apply head  mouth matrix –Render mouth u Un-apply head  mouth matrix u Apply head  left eye matrix –Render eye u Un-apply head  left eye matrix u Apply head  right eye matrix –Render eye u Un-apply head  right eye matrix n Un-apply robot  head matrix n Apply robot  body matrix How should we implement this “un-apply” business?

David Luebke1/5/2016 The Scene Graph in OpenGL l OpenGL maintains a matrix stack of modeling and viewing transformations: ArmTrunk Leg EyeMouth HeadBody Robot Foot Matrix Stack Visited Unvisited Active

David Luebke1/5/2016 OpenGL: The Matrix Stack The user can save the current transformation matrix by pushing it onto the stack with glPushMatrix() The user can later restore the most recently pushed matrix with glPopMatrix() These commands really only make sense when in GL_MODELVIEW matrix mode

David Luebke1/5/2016 OpenGL: Matrix Stack Example glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(…); // save translation matrix: glPushMatrix(); glRotatef(…); // render something translated & rotated: glCallList(foo); // restore pushed matrix, undoing rotation: glPopMatrix(); // render something else, no rotation: glCallList(bar);

David Luebke1/5/2016 Coming Up: l Animation: smooth (flicker-free) motion using double buffering l More OpenGL tricks –Backface culling –Gouraud shading –Computing vertex normals