Slide 1AdminDemoModeling: The CameraSlide 5Introducing OpenGLOpenGL Design GoalsOpenGL: ConventionsSlide 9OpenGL: Simple UseSlide 11Slide 12OpenGL: Perspective ProjectionSlide 14Slide 15OpenGL: LightingSlide 17OpenGL: Specifying ViewpointOpenGL: Specifying GeometryOpenGL: More ExamplesOpenGL: Front/Back RenderingOpenGL: Drawing TrianglesOpenGL: Triangle StripsOpenGL: Modeling TransformsOpenGL: Matrix ManipulationSlide 26OpenGL: Specifying ColorOpenGL: Specifying NormalsMore OpenGLCS 445: Introduction to Computer GraphicsDavid LuebkeUniversity of VirginiaOpenGL TransformationsAdminCall rollForums signup – do it NOW pleaseDemoAnimusicModeling: The CameraFinally: need a model of the virtual camera–Can be very sophisticatedField of view, depth of field, distortion, chromatic aberration…–Interactive graphics (OpenGL):Camera pose: position & orientationCaptured in viewing transform (i.e., modelview matrix)Pinhole camera modelField of viewAspect ratioNear & far clipping planesModeling: The CameraCamera parameters (FOV, etc) are encapsulated in a projection matrix–Homogeneous coordinates 4x4 matrix!–See OpenGL Appendix F for the matrixThe projection matrix premultiplies the viewing matrix, which premultiplies the modeling matrices–Actually, OpenGL lumps viewing and modeling transforms into modelview matrixIntroducing OpenGLRecall the rendering pipeline:–Transform geometry (object world, world eye)–Calculate surface lighting–Apply perspective projection (eye screen)–Clip to the view frustum–Perform visible-surface processingImplementing all this is a lot of work (as you’ll find)OpenGL provides a standard implementation –So why study the basics?OpenGL 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 was promoted by SGI (& Microsoft, half-heartedly), is now promoted/supported by NVIDIA, ATI, etc.–It doesn’t change every year (like DirectX, it’s main competitor)Good and badOpenGL: ConventionsFunctions in OpenGL start with gl–Most functions just gl (e.g., glColor()) –Functions starting with glu are utility functions (e.g., gluLookAt())Note that GLU functions can always be composed entirely from core GL functions–Functions starting with glut are from the GLUT library, built on top of OpenGL and WGL (Windows) or X (Linux) for window management, mouse and keyboard events, etc.Created and distributed as an entirely different libraryOpenGL: 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 floatsOpenGL: Simple UseOpen a window and attach OpenGL to itSet projection parameters (e.g., field of view)Setup lighting, if anyMain rendering loop–Set camera pose with gluLookAt() Camera position specified in world coordinates–Render polygons of modelUse modeling matrices to transform vertices in world coordinatesOpenGL: Simple UseOpen a window and attach OpenGL to it–FLTK/GLUT (assignment 0)Set projection parameters (e.g., field of view)Setup lighting, if anyMain rendering loop–Set camera pose with gluLookAt() Camera position specified in world coordinates–Render polygons of modelUse modeling matrices to transform vertices in world coordinatesOpenGL: Simple UseOpen a window and attach OpenGL to itSet projection parameters (e.g., field of view)Setup lighting, if anyMain rendering loop–Set camera pose with gluLookAt() Camera position specified in world coordinates–Render polygons of modelUse modeling matrices to transform vertices in world coordinatesOpenGL: Perspective ProjectionTypically, we use a perspective projection–Distant objects appear smaller than near objects –Vanishing point at center of screen–Defined by a view frustum (draw it)Other projections: orthographic, isometricOpenGL: Perspective ProjectionIn OpenGL: –Projections implemented by projection matrix–gluPerspective() creates a perspective projection matrix:glMatrixMode(GL_PROJECTION);glLoadIdentity(); gluPerspective(vfov, aspect, near, far);Parameters to gluPerspective():–vfov: vertical field of view–aspect: window width/height–near, far: distance to near & far clipping planesMore on these in a bitOpenGL: Simple UseOpen a window and attach OpenGL to itSet projection parameters (e.g., field of view)Setup lighting, if anyMain rendering loop–Set camera pose with gluLookAt() Camera position specified in world coordinates–Render polygons of modelUse modeling matrices to transform vertices in world coordinatesOpenGL: LightingSimplest option: change the current color between polygons or vertices–glColor() sets the current colorOr OpenGL provides a simple lighting model:–Set parameters for light(s)Intensity, position, direction & falloff (if applicable) –Set material parameters to describe how light reflects from the surfaceWon’t go into details now; check the red book if interestedOpenGL: Simple UseOpen a window and attach OpenGL to itSet projection parameters (e.g., field of view)Setup lighting, if anyMain rendering loop–Set camera pose with gluLookAt() Camera position specified in world coordinates–Render polygons of modelUse modeling matrices to transform vertices in world coordinatesOpenGL: Specifying ViewpointglMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);–eye[XYZ]: camera position in world coordinates–look[XYZ]: a point centered in camera’s view–up[XYZ]: a vector defining the camera’s verticalCreates a matrix that transforms points in world coordinates to camera coordinates–Camera at origin–Looking down -Z axis –Up vector aligned with Y axis (actually Y-Z plane)More on these in a bitOpenGL:
View Full Document