Unformatted text preview:

OpenGL Open Graphics Library Introduction to OpenGL Part II CS 351 50 Graphics API Application Programming Interface Software library Layer between programmer and graphics hardware and other software Several hundred procedures and functions What is OpenGL Configurable state machine Input is 2D or 3D data Output is framebuffer Modify state to modify functionality How do I render a geometric primitive To Framebuffer OpenGL primitives A group of one or more vertices Vertex defines A point An endpoint of an edge A corner of a polygon where two edges meet 1 OpenGL Rendering OpenGL Primitives Data consists of Positional coordinates Colors Normals Texture Coordinates Each vertex is processed Points Triangle Lines Polygon Quad Quad strip independely In order In the same way Triangle strip OpenGL drawing To draw a primitive call glBegin glEnd encloses a list of vertices and their attributes Coordinates of a primitive are given counter clockwise order Triangle Fan Function calls to draw a primitive glBegin GL POINTS glVertex3f 0 0f 0 0f 0 0f glEnd 2 Draw a triangle Draws a triangle with different colors at each vertex glBegin GL TRIANGLES glColor3f 1 0f 0 0f 0 0f pure red glVertex3f 0 0f 1 0f 0 0f glBegin GL TRIANGLES glVertex3f 0 0f 1 0f 0 0f glVertex3f 1 0f 1 0f 0 0f glVertex3f 1 0f 1 0f 0 0f glEnd glColor3f 0 0f 1 0f 0 0f pure green glVertex3f 1 0f 1 0f 0 0f glColor3f 0 0f 0 0f 1 0f pure blue glVertex3f 1 0f 1 0f 0 0f glEnd Types of rendering Wireframe Display only lines and curves No filled objects Flat Shading Compute a single color for each polygon Fill the polygon with that constant color Types of rendering Smooth Gouraud shading Interpolate vertex colors across polygon Vertex colors can be specified explicitly or computed using lighting calculations Texture Mapping Modify color of each pixel with colors from an image 1991 Pixar Shutterbug Example http www siggraph org education curriculum projects slide sets slides91 91 01 2 htm 3 How are these options configured What is the OpenGL Pipeline Process thru which OpenGL processes data Geometric data and pixel data processed separately Functions glEnable glDisable glCullMode glPolygonMode glLightModel etc Geometry subject to per vertex operations Pixel data subject to per pix operations Both share the same final step Rasterization and per fragement ops fragment is general term for pixel or vertex OpenGL Pipeline Images Pixels Geomety Primitive Operations Pixel Operations Scan Conversion Fragment Operations Understanding Pipeline is important Framebuffer Vertices OpenGL Pipeline Helps design algorithms Helps find bottlenecks Which parts are supported by hardware Texture Memory 4 Pixel Primitives Provide a way of manipulating rectangles of pixels glDrawPixels glReadPixels glCopyPixels move pixel rectangles to and from the framebuffer glBitmap takes a binary image and renders the current color in framebuffer positions corresponding to 1s in image useful for drawing fonts glRasterPos defines where pixels go in the framebuffer Hidden Surface Removal When seeing up your window specify a depth buffer glutInitDisplayMode GLUT DEPTH Hidden Surface Removal When we draw a fragment record the z distance to the eye in the depth buffer If the z stored in the depth buffer is greater than the z for the fragment about to be drawn draw it Otherwise the fragment is behind something that has already been drawn so throw it away Demos Shapes Nate Robin s Tutors Ctrl and mouse to change primitive When clearing make sure to glClear GL DEPTH BUFFER BIT glEnable GL DEPTH TEST Set the depth test comparison operation glDepthFunc GL LESS this is the default don t really need to specify 5 OpenGL Color Models RGBA color Red Green Blue Alpha Separate channel for each 8 bits channel 16 million colors Indexed Color Small number of colors accessed by indices into a color look up table 8 bits 256 colors Viewing in OpenGL Viewing consists of two parts Object positioning model view transformation matrix View projection projection transformation matrix OpenGL support both perspective and orthographic viewing transformations OpenGL camera is always at the origin pointing in the z direction Transformations move objects relative to camera OpenGL Transparency Use the fourth component alpha of RGBA color Alpha 0 is fully transparent Alpha 1 is fully opaque Objects are composited as they are rendered Example C alpha Cs 1 alpha Cf Cs is the color of the incoming fragment Cf is the color already in the framebuffer ModelView Matrix Positions objects in world coordinates Usually formed by concatenating simple transformations glRotate theta x y z glTranslate x y z glScale x y z Order is important 6 Modeling Transformations glTranslatef 0 0f 0 0f 10 0f glRotatef 45 0f 0 0f 1 0f 0 0f glBegin GL TRIANGLES glColor3f 1 0f 0 0f 0 0f pure red glVertex3f 0 0f 1 0f 0 0f Viewing in OpenGL Orthographic projection Boundaries of the parallel viewing volume Objects are clipped to specified viewing cube glOrtho left right bottom top front back Perspective Projection glColor3f 0 0f 1 0f 0 0f pure green glVertex3f 1 0f 1 0f 0 0f glColor3f 0 0f 0 0f 1 0f pure blue glVertex3f 1 0f 1 0f 0 0f glEnd Positioning the Camera Use gluLookAt to specify Eye location Look at point up vector gluLookAt 10 10 10 1 2 3 0 0 1 Eye is 10 10 10 Look at point is 1 2 3 Up is 0 0 1 Usually done in GL PROJECTION matrix and combined with perspective matrix glFrustum gluPerspective Clipping volume is a frustum Make sure near and far clipping planes aren t too far apart Make sure near plane isn t too close to eye Complete Viewing Example Projection first glMatrixMode GL PROJECCTION glLoadIdentity gluPerspective 60 1 1 100 gluLookAt 10 10 10 1 2 3 0 0 1 Now object transformations glMatrixMode GL MODELVIEW glLoad Identity glTranslate 1 1 1 glRotatef 90 1 0 0 DrawObject 7 Matrix Stacks OpenGL has multiple matrix stacks glPushMatrix pushes a copy of the top fo the stack matrix glPopMatrix throws away the top of the stack Very useful for hierachically defined figures Column versus row order OpenGL uses column C uses row We will use column Demo http www cs princeton edu min cs426 jar transform html From OpenGL maual pg 103 of Programmers 1 1 If you are programming in C and declare a matrix as m 4 4 then the element m i j is in the ith column and jth row of the OpenGL transformation matrix This is the reverse of the standard C convention in which m i j is in row i and column j To avoid confusion you should declare your matrices as m


View Full Document

NU EECS 351 - Introduction to OpenGL Part II

Download Introduction to OpenGL Part II
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to OpenGL Part II and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to OpenGL Part II 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?