OpenGL: Introduction Yanci Zhang Game Programming Practice.

Slides:



Advertisements
Similar presentations
COMPUTER GRAPHICS SOFTWARE.
Advertisements

MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Viewing and Transformation
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
OpenGL (II). How to Draw a 3-D object on Screen?
Introduction to OpenGL Pipeline From Programmer View Tong-Yee Lee.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
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.
Further Programming for 3D applications CE Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Computer Graphics (fall 2009)
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Week 2 - Wednesday CS361.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Geometric transformations The Pipeline
2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
Computer Graphics Bing-Yu Chen National Taiwan University.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
Computer Graphics Zhen Jiang West Chester 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.
CS 445 / 645 Introduction to Computer Graphics Lecture 10 Camera Models Lecture 10 Camera Models.
Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.
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.
Computing & Information Sciences Kansas State University CG Basics 3 of 8: OpenGL Primer 1 CIS 636/736: (Introduction to) Computer Graphics CIS 636 Introduction.
2/19/04© University of Wisconsin, CS559 Spring 2004 Last Time Painterly rendering 2D Transformations –Transformations as coordinate system changes –Transformations.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Chap 3 Viewing and Transformation
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
GL transformations-models. x' = x+t x y' = y+t y z' = z+t z t x t y s x =s y =s z t z uniform nonuniform?!!?? x' = x·s x y' =
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.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL LAB III.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
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.
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics
CSCE 441 Computer Graphics 3-D Viewing
Programming with OpenGL Part 2: Complete Programs
OpenGL API 2D Graphic Primitives
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Projection in 3-D Glenn G. Chappell
Geometric Objects and Transformations (II)
Computer Graphics 3Practical Lesson
Presentation transcript:

OpenGL: Introduction Yanci Zhang Game Programming Practice

 Overview of OpenGL  OpenGL vs. Direct X  Rendering pipeline  Coordinate system Outline Game Programming Practice

 OpenGL = Open Graphics Library  Graphics rendering API  Produce high-quality color images composed of 3D geometric objects and images  Hardware independent  Cross platform What is OpenGL? Game Programming Practice

 Bases for many advanced data structures in game programming  Typical applications  Scene graph  State graph  Decision tree  Kd-tree, quad tree  … Basic Function Game Programming Practice

 Rendering basic primitives, like points, lines, triangles…  Matrix operations  Local illumination  Texture mapping  Pixel operations  … What Can OpenGL Do? Game Programming Practice

 Create windows  Handle window events  Response to user input  Scene management  … What Can Not OpenGL Do? Game Programming Practice

 OpenGL is only graphics library  DirectX handles graphics, audio, user input  Use OpenGL improperly, system does nothing   Use DirectX improperly, system does something beyond expectation  OpenGL vs. DirectX OpenGL vs. DirectX 1/2 Game Programming Practice

 OpenGL  Industry standard maintained by OpenGL Architectural Review Board (ARB)  Stable function interface  Cross platform  Very clean, easy to learn  DirectX  Microsoft’s product  Instable function interface  Only support Windows OpenGL vs. DirectX OpenGL vs. DirectX 2/2 Game Programming Practice

 Input: scene objects, lighting, camera  Most of the data is vertex list  Output: pixels stored in framebuffer  Question: how to convert 3D vertex list to 2D pixels?  OpenGL is designed to fulfill this task OpenGL Pipeline Game Programming Practice

 Main task: transformation and lighting  Transformation:  Model-View transformation: translation, rotation, scaling  Projection transformation: perspective, parallel  Lighting  Fixed-pipeline implements per-vertex lighting  Lighting is normally delayed to fragment processing in programmable pipeline Vertex Processing Game Programming Practice

 Assemble vertices into primitives  Lines/Curves  Triangles/Polygons/Surfaces Primitive Assembly Game Programming Practice

 Don’t render invisible objects  Clipping  Remove primitives outside of the camera’s view frustum  Backface culling  Remove triangles facing away from camera  Usually cuts down $ of triangles by about 50% Clipping and Culling Game Programming Practice

 Convert a primitive into a set of fragments  Each pixel has both RGB color and depth  Interpolate vertex color over fragments  Fragment might not correspond to pixels on screen:  Occluded fragments Rasterization Game Programming Practice

 Assemble fragments into final framebuffer  Hidden-surface removal:  Some fragments may occlude parts of others  Z-buffer sorts pixels by distance  Handle transparency  Other operations Fragment Processing Game Programming Practice

 Using vertex list to represent a set rendering primitives  14 primitives supported by OpenGL  Point: GL_POINTS  Line: GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP  Triangle: GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN  Polygon: GL_QUADS, GL_QUAD_STRIP, GL_POLYGON Rendering Primitives Game Programming Practice

 Polygons must obey following rules  Simple polygon  Convex polygon  Coplanar vertices  Triangle satisfies all the above rules  Most common rendering primitive Restriction on Polygons Game Programming Practice

Specifying Vertex 1/2 Game Programming Practice

 How to convert 3D objects to 2D image?  Just like taking a photograph! Camera Analogy 1/2 camera tripod model viewing volume Game Programming Practice

 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 Camera Analogy 2/2 Game Programming Practice

 Steps in Forming an Image  Specify geometry (world coordinates)  Specify camera (camera coordinates)  Project (clip coordinates)  Map to viewport (screen coordinates)  Each step uses transformations  Every transformation is equivalent to a change in coordinate systems Coord. Sys. and Transformations Game Programming Practice

Coord. Sys. and Transformations Object Coordinates World Coordinates Camera Coordinates Clip Coordinates Screen Coordinates Model Transformation World Transformation Project Transformation Viewport Transformation Game Programming Practice

Affine Transformations 1/2  Definition  Using a single matrix multiplication to represent affine transformation by using augmented matrix and augmented vector Game Programming Practice

 Preserving geometry  lines, polygons, quadrics  Affine = line preserving  Rotation, translation, scaling  Projection  Concatenation (composition) Affine Transformations 2/2 Game Programming Practice

 Each vertex is a column vector  w is usually 1.0  ( x,y,z,w ) = ( ax,ay,az,aw )  If w is not 1.0, we can recover x,y,z by division by w  Only perspective transformation change w  All operations are matrix multiplications  Directions can be represented with w = 0.0 Homogeneous Coordinates Game Programming Practice

 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 3D Transformations Game Programming Practice

 Two ways  Specify matrices (glLoadMatrix, glMultMatrix)  Specify operation (glRotate, glOrtho)  Obtain the desired matrix by a sequence of simple transformations that can be concatenated together Specifying Transformations Game Programming Practice

 Manage the matrices  OpenGL provides matrix stacks for each type of transformation  Specify current matrix stack glMatrixMode( GL_MODELVIEW / GL_PROJECTION / GL_TEXTURE )  Operations on matrix stack  glLoadIdentity():  glLoadIdentity(): replaces the current matrix with the identity matrix  glPushMatrix():  glPushMatrix(): pushes the current matrix stack down by one, duplicating the current matrix  glPopMatrix():  glPopMatrix(): pops the current matrix stack, replacing the current matrix with the one below it on the stack  glMultMatrix():  glMultMatrix(): multiply the current matrix by input matrix Matrix Stack Game Programming Practice

 Object coordinates to world coordinates  Call glMatrixModel(GL_MODELVIEW) first !  Move object glTranslate{fd}( x, y, z ) glTranslate{fd}( x, y, z )  Rotate object around arbitrary axis (x,y,z) glRotate{fd}( angle, x, y, z ) glRotate{fd}( angle, x, y, z )  Stretch or shrink object glScale{fd}( x, y, z ) glScale{fd}( x, y, z ) Modeling Transformations 1/3 Game Programming Practice

 Different transform order may produce different results  Rotate then translate  Translate then rotate Modeling Transformations 2/3 Game Programming Practice

 Steps  Suppose the current matrix is C  Specify a model transform matrix M 1 by:  glMultMatrix()  glRotate(), glTranslate()…  Use CM 1 to replace the current matrix on the top of matrix stack  Specify another model transform matrix M 2  Now the current matrix is CM 1 M 2  Transform vertex v : v’ = CM 1 M 2 v  You must specify the transform in reverse order! Modeling Transformations 3/3 Game Programming Practice

 World coordinates to camera coordinates  Position the camera/eye in the scene  Place the tripod down and aim camera gluLookAt(eye x, eye y, eye z, aim x, aim y, aim z, up x, up y, up z )  Multiplies itself onto the current matrix  up vector determines unique orientation Viewing Transformations tripod Game Programming Practice

 Camera coordinates to clip coordinates  Perspective projection gluPerspective( fovy, aspect, zNear, zFar ) glFrustum( left, right, bottom, top, zNear, zFar )  Feature: objects in the distance appear smaller than objects close by Projection Transformation 1/2 Game Programming Practice

 Orthographic parallel projection glOrtho( left, right, bottom, top, zNear, zFar ) gluOrtho2D( left, right, bottom, top )  Feature: ignores perspective effect to allow accurate measurements Projection Transformation 2/2 Game Programming Practice

 Viewport  Usually same as window size  Viewport aspect ratio should be same as projection transformation or resulting image may be distorted glViewport( x, y, width, height ) glViewport( x, y, width, height ) Viewport Transformation Game Programming Practice

 Why only one ModelView matrix stack instead of two separated Model and View matrix stacks?  Moving camera = Moving every object in the world towards a stationary camera  Viewing transformations = Several modeling transformations Viewing and Modeling Game Programming Practice

 Important: OpenGL performs matrices multiplication in reverse order if multiple transforms are applied to a vertex  Viewing transform comes first before modeling transform in your code  If you want to rotate then translate an object, put glTranslatef() first then glRotatef() Transform Order Game Programming Practice