Graphics Systems and OpenGLCool Video GamesRendering 3D ScenesThe Rendering PipelineRendering: TransformationsThe Rendering Pipeline: 3-DPowerPoint PresentationSlide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Introducing OpenGLSlide 17OpenGL Design GoalsOpenGL: ConventionsSlide 20Slide 21OpenGL Matrix StacksSlide 23Slide 24Slide 25OpenGL: BasicsOpenGL: main()main(): Open a windowmain(): Setup Camera Parametersmain(): Register Callback Functionsmain(): Initiate main rendering loopCallback: Display_Func()Slide 33Slide 34Slide 35draw_paddle(void)Callback: keyboard_func()Callback: move_ball()Callback: mouseFunc, motionFuncSlide 40Graphics Systemsand OpenGLCS 445/645Introduction to Computer Graphics2Cool Video Gameshttp://www.stanford.edu/~mazzella/university/cs248/pacman/pacman.htmhttp://www.liquid.se/pong.html3Rendering 3D ScenesTransformIlluminateTransformClipProjectRasterizeModel & CameraModel & CameraParametersParametersRendering PipelineRendering PipelineFramebufferFramebufferDisplayDisplay4The Rendering PipelineTransformIlluminateTransformClipProjectRasterizeModel & CameraModel & CameraParametersParametersRendering PipelineRendering PipelineFramebufferFramebufferDisplayDisplay5Rendering: TransformationsSo far, discussion has been in screen spaceBut model is stored in model space(a.k.a. object space or world space)Three sets of geometric transformations:–Modeling transforms–Viewing transforms–Projection transforms6The Rendering Pipeline: 3-DResult:Result:• All vertices of scene in shared 3-D “world” coordinate All vertices of scene in shared 3-D “world” coordinate systemsystem• Vertices shaded according to lighting modelVertices shaded according to lighting model• Scene vertices in 3-D “view” or “camera” coordinate Scene vertices in 3-D “view” or “camera” coordinate systemsystem• Exactly those vertices & portions of polygons in view Exactly those vertices & portions of polygons in view frustumfrustum• 2-D screen coordinates of clipped vertices2-D screen coordinates of clipped verticesScene graphObject geometryLightingCalculationsClippingModelingTransformsViewingTransformProjectionTransform7The Rendering Pipeline: 3-DModelingTransformsScene graphObject geometryLightingCalculationsViewingTransformClippingProjectionTransformResult:Result:• All vertices of scene in shared 3-D “world” coordinate All vertices of scene in shared 3-D “world” coordinate systemsystem8Rendering: TransformationsModeling transforms–Size, place, scale, and rotate objects and parts of the model w.r.t. each other–Object coordinates world coordinatesZXYXZY9ModelingTransformsScene graphObject geometryLightingCalculationsViewingTransformClippingProjectionTransformResult:Result:• Scene vertices in 3-D “view” or “camera” coordinate Scene vertices in 3-D “view” or “camera” coordinate systemsystemThe Rendering Pipeline: 3-D10Rendering: TransformationsViewing transform–Rotate & translate the world to lie directly in front of the cameraTypically place camera at originTypically looking down -Z axis–World coordinates view coordinates11ModelingTransformsScene graphObject geometryLightingCalculationsViewingTransformClippingProjectionTransformResult:Result:• 2-D screen coordinates of clipped vertices2-D screen coordinates of clipped verticesThe Rendering Pipeline: 3-D12Rendering: TransformationsProjection transform–Apply perspective foreshorteningDistant = small: the pinhole camera model–View coordinates screen coordinates13Perspective CameraOrthographic CameraRendering: Transformations14Rendering: TransformationsAll these transformations involve shifting coordinate systems (i.e., basis sets)That’s what matrices do…Represent coordinates as vectors, transforms as matricesMultiply matrices = concatenate transforms!YXYXcossinsincos15Rendering: TransformationsExample: Rotate point [1,0]T by 90 degrees CCW (Counter-clockwise)10''010110''01)90cos()90sin()90sin()90cos(''yxyxyxxy(1,0)x(0,1)y16Introducing OpenGLmid-level, device-independent, portable graphics subroutine packagedeveloped primarily by SGI2D/3D graphics, lower-level primitives (polygons)does not include low-level I/O managementbasis for higher-level libraries/toolkits17Introducing OpenGLRecall the rendering pipeline:–Transform geometry (object world, world eye)–Apply perspective projection (eye screen)–Clip to the view frustum–Perform visible-surface processing (Z-buffer)–Calculate surface lightingImplementing all this is a lot of work OpenGL provides a standard implementation –So why study the basics?18OpenGL Design GoalsSGI’s design goals for OpenGL:–High-performance (hardware-accelerated) graphics API–Some hardware independence –Natural, terse API with some built-in extensibilityOpenGL has become a standard because:–It doesn’t try to do too muchOnly renders the image, doesn’t manage windows, etc.No high-level animation, modeling, sound (!), etc.–It does enoughUseful rendering effects + high performance–It is promoted by SGI (& Microsoft, half-heartedly)19OpenGL: ConventionsFunctions in OpenGL start with gl–Most functions just gl (e.g., glColor()) –Functions starting with glu are utility functions (e.g., gluLookAt())–Functions starting with glx are for interfacing with the X Windows system (e.g., in gfx.c)20OpenGL: ConventionsFunction names indicate argument type and number–Functions ending with f take floats–Functions ending with i take ints–Functions ending with b take bytes–Functions ending with ub take unsigned bytes–Functions that end with v take an array.Examples–glColor3f() takes 3 floats–glColor4fv() takes an array of 4 floats21OpenGL: ConventionsVariables written in CAPITAL letters–Example: GLUT_SINGLE, GLUT_RGB–usually constants–use the bitwise or command (x | y) to combine constants22OpenGL Matrix StacksOpenGL basically just renders vertices–Vertices can be grouped to form polygons–Polygons can be grouped to form shapes (solids)Each glVertex rendered by OpenGL is transformed by the top matrix on the MODELVIEW matrix stack–As
View Full Document