Computer Graphics Bing-Yu Chen National Taiwan University.

Slides:



Advertisements
Similar presentations
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Advertisements

Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Based on slides created by Edward Angel
Viewing and Transformation
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
Introduction to OpenGL Pipeline From Programmer View Tong-Yee Lee.
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to 3D viewing 3D is just like taking a photograph!
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
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.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Computer Graphics Bing-Yu Chen National Taiwan University.
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.
Computer Graphics I, Fall 2010 OpenGL Transformations.
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.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
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.
Computing & Information Sciences Kansas State University CG Basics 3 of 8: OpenGL Primer 1 CIS 636/736: (Introduction to) Computer Graphics CIS 636 Introduction.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Introduction to Computer Graphics: Viewing Transformations Rama C
Chap 3 Viewing and Transformation
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
OpenGL LAB III.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
School of Computer Science
OpenGL Transformations
Camera Position (5.6) we specify the position and orientation of the camera to determine what will be seen. use gluLookAt (eye x, y, z, at x, y, z, up.
OpenGL Transformations
Computer Graphics OpenGL Transformations
Reference1. [OpenGL course slides by Rasmus Stenholt]
Advanced Graphics Algorithms Ying Zhu Georgia State University
An Interactive Introduction to OpenGL Programming
An Interactive Introduction to OpenGL Programming
Lecture 08 and 09 View & Projection
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Computer Graphics, KKU. Lecture 13
Type of View Perspective View COP(Center of Plane) Diminution of size
Transformations in OpenGL
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
OpenGL Transformations
OpenGL Transformations
An Interactive Introduction to OpenGL Programming
Presentation transcript:

Computer Graphics Bing-Yu Chen National Taiwan University

Introduction to OpenGL  General OpenGL Introduction  An Example OpenGL Program  Drawing with OpenGL  Transformations  Animation and Depth Buffering  Lighting  Evaluation and NURBS  Texture Mapping  Advanced OpenGL Topics  Imaging modified from Dave Shreiner, Ed Angel, and Vicki Shreiner. An Interactive Introduction to OpenGL Programming. ACM SIGGRAPH 2001 Conference Course Notes #54. & ACM SIGGRAPH 2004 Conference Course Notes #29.

Transformations in OpenGL  Modeling  Viewing orient camera projection  Animation  Map to screen

Camera Analogy  3D is just like taking a photograph (lots of photographs!) camera tripod model viewing volume

Camera Analogy & Transformations  Projection transformations adjust the lens of the camera  Viewing transformations tripod – define position and orientation of the viewing volume in the world  Modeling transformations moving the model  Viewport transformations enlarge or reduce the physical photograph

Coordinate Systems & Transformations  Steps in Forming an Image specify geometry (world coordinates) specify camera (camera coordinates) project (window coordinates) map to viewport (screen coordinates)  Each step uses transformations  Every transformation is equivalent to a change in coordinate systems (frames)

Affine Transformations  Want transformations which preserve geometry lines, polygons, quadrics  Affine = line preserving Rotation, translation, scaling Projection Concatenation (composition)

Homogeneous Coordinates  each vertex is a column vector  w is usually 1.0  all operations are matrix multiplications  directions (directed line segments) can be represented with w = 0.0

3D Transformations  A vertex is transformed by 4 x 4 matrices all affine operations are matrix multiplications all matrices are stored column-major in OpenGL matrices are always post-multiplied product of matrix and vector is

OpenGL Matrices  In OpenGL matrices are part of the state  Three types Model-View ( GL_MODEL_VIEW ) Projection ( GL_PROJECTION ) Texture ( GL_TEXTURE ) Color ( GL_COLOR )  Single set of functions for manipulation  Select which to manipulated by glMatrixMode(GL_MODEL_VIEW); glMatrixMode(GL_PROJECTION);

Matrix Operations  Specify Current Matrix Stack glMatrixMode( GL_MODELVIEW, GL_PROJECTION, etc )  Matrix operations glLoadIdentity(); glLoadMatrix(); glLoadTransposeMatrix(); glMultiMatrix(); glMultTransposematrix(); glRotate(); glTranslate(); glScale(); glGet*v();  Matrix or Stack Operations glPushMatrix() glPopMatrix()

vertexvertex Modelview Matrix Projection Matrix Perspective Division Viewport Transform Modelview Projection object eye clip normalized device window  other calculations here material  color shade model (flat) polygon rendering mode polygon culling clipping Transformation Pipeline CPU DL Poly. Per Vertex Per Vertex Raster Frag FB Pixel Texture

Modeling Transformations  Move object glTranslate{fd}( x, y, z )  Rotate object around arbitrary axis glRotate{fd}( angle, x, y, z ) angle is in degrees  Dilate (stretch or shrink) or mirror object glScale{fd}( x, y, z )

Fall 2009 revised14 Examples glRotate (30, 0, 0, 1); glTranslate (10, 0, 0); glRotate (30, 0, 0, 1);

Viewing Transformations  OpenGL combines modeling and viewing transformation as MODELVIEW_MATRIX  Moving camera == moving the whole world according to the camera gluLookAt( eyex, eyey, eyez, aimx, aimy, aimz, upx, upy, upz )

s -f gluLookAt (eye, center, up) LTLT Equivalent to: Change of Basis L

Projection Transformation  Perspective projection glFrustum( left, right, bottom, top, zNear, zFar ) gluPerspective( fovy, aspect, zNear, zFar )

Projection Transformation  Orthographic parallel projection glOrtho( left, right, bottom, top, zNear, zFar ) gluOrtho2D( left, right, bottom, top )

Viewport Transformation  Viewport glViewport( x, y, width, height )

Matrix Stacks  In many situations we want to save transformation matrices for use later Traversing hierarchical data structures Avoiding state changes when executing display lists  OpenGL maintains stacks for each type of matrix Access present type (as set by glMatrixMode) by  glPushMatrix()  glPopMatrix()

Fall 2009 revised21 Example 11 22 33 Link at default pos Link1: Rotate(z, 1 ); draw Link2: Rotate(z, 1 ); Translate(h,0,0) Rotate(z, 2 ); draw Link3: Rotate(z, 1 ); Translate(h,0,0) Rotate(z, 2 ); Translate(h,0,0) Rotate(z, 3 ); draw

Fall 2009 revised22 Link1: Rotate(z, 1 ) draw Link1: Rotate(z, 1 ) draw Link2: Rotate(z, 1 ) Translate(h,0,0) Rotate(z, 2 ) draw Link2: Rotate(z, 1 ) Translate(h,0,0) Rotate(z, 2 ) draw Link3: Rotate(z, 1 ) Translate(h,0,0) Rotate(z, 2 ) Translate(h,0,0) Rotate(z, 3 ) draw Link3: Rotate(z, 1 ) Translate(h,0,0) Rotate(z, 2 ) Translate(h,0,0) Rotate(z, 3 ) draw PushMatrix Rotate(z, 1 ) draw // link1 Translate(h,0,0) Rotate(z, 2 ) draw // link2 Translate(h,0,0) Rotate(z, 3 ) draw // link3 PopMatrix PushMatrix Rotate(z, 1 ) draw // link1 Translate(h,0,0) Rotate(z, 2 ) draw // link2 Translate(h,0,0) Rotate(z, 3 ) draw // link3 PopMatrix

Reading Back Matrices  Can also access matrices (and other parts of the state) by enquiry (query) functions glGetIntegerv glGetFloatv glGetBooleanv glGetDoublev glIsEnabled  For matrices, we use as double m[16]; glGetFloatv(GL_MODELVIEW, m);

Projection is left handed  Projection transformations (gluPerspective, glOrtho) are left handed think of zNear and zFar as distance from view point  Everything else is right handed, including the vertexes to be rendered x x y y z+ left handedright handed

Reversing Coordinate Projection  Screen space back to world space glGetIntegerv( GL_VIEWPORT, GLint viewport[4] ) glGetDoublev( GL_MODELVIEW_MATRIX, GLdouble mvmatrix[16] ) glGetDoublev( GL_PROJECTION_MATRIX, GLdouble projmatrix[16] ) gluUnProject( GLdouble winx, winy, winz, mvmatrix[16], projmatrix[16], GLint viewport[4], GLdouble *objx, *objy, *objz )

Animation and Depth Buffering  Discuss double buffering and animation  Discuss hidden surface removal using the depth buffer

Double Buffering Front Buffer Back Buffer Display CPU DL Poly. Per Vertex Per Vertex Raster Frag FB Pixel Texture

Animation Using Double Buffering  Request a double buffered color buffer glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );  Clear color buffer glClear( GL_COLOR_BUFFER_BIT );  Render scene  Request swap of front and back buffers glutSwapBuffers();  Repeat steps for animation

Depth Buffering and Hidden Surface Removal Color Buffer Depth Buffer Display

Depth Buffering Using OpenGL  Request a depth buffer glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );  Enable depth buffering glEnable( GL_DEPTH_TEST );  Clear color and depth buffers glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );  Render scene  Swap color buffers