Presentation is loading. Please wait.

Presentation is loading. Please wait.

More OpenGL CS 551/645 - Introduction to Computer Graphics.

Similar presentations


Presentation on theme: "More OpenGL CS 551/645 - Introduction to Computer Graphics."— Presentation transcript:

1 More OpenGL CS 551/645 - Introduction to Computer Graphics

2 2 What’s New? Everyone getting class email? SGI accounts at Small Hall working – sgi-5.unixlab is misconfigured Program 1 deadline extended until Monday, September 18th, 2000 at midnight TA Office Hours: Tues (3:30 - 5:00) W (3:00 - 5:00) in Small Hall

3 3 Where are we in the book? Read OpenGL Guide, Chapters 1 - 3 Read Foley (CGP&P) Chapter 3

4 4 Unix Commands - Basics mkdir foo - make a directory rmdir foo - remove a directory cp foo bar - create a new file named bar that is a copy of foo mv foo bar - create a new file named bar that is a copy of foo and delete foo

5 5 Unix Commands - Basics ls - display the contents of the directory ls -l - display the ‘l’ong version of the directory cd foo - move from the current directory to the directory named foo cd.. - move up a directory cd../foo - move up and over to the foo directory

6 6 Unix Commands - Basics foo | bar - called ‘pipe’ a way to sequence commands. The output from foo is used as input by bar foo > bar - called a redirect. The output from foo is redirected to a file named bar. Useful for capturing output streams to a file foo < bar - the contents of file bar are used as input to foo

7 7 Unix Commands - Basics man foo - print out the manual pages for the command, foo tar - a way to convert a directory structure into a flat file tar - a way to unpack a flat file into a directory structure tar | tar - a way to copy a directory structure from one place to another

8 8 Unix Commands - Basics gzip - a way to compress foo. A new file named foo.gz will be created and foo will be deleted gunzip foo.gz - a way to uncompress foo.

9 9 Setup Hints Things complicated because of unification between blue.unix and sgi.unixlab –.xinitrc,.profile,.login,.kshrc may all be incorrectly configured for another kind of computer – Unfortunately there isn’t a quick fix – One solution is to create a subdir and move all the dot files to the subdir (so they won’t be executed when you log on the SGI. This will screw up other logins, though.

10 10 Makefile -I refers to the include path. Compiler looks in all these directories for.h files -L refers to the library path. Compiler looks in all these directories for the required libraries -l refers to the required libraries

11 11 Creating Geometry All geometry composed of vertices (points) ‘Primitive type’ defines the shape they describe Example vertices: glVertex (x, y, z, w) – glVertex2d - z coordinate is set to 0.0 – glVertex3d - w coordinate is set to 1.0 – glVertex4d - all coordinates specified (rarely done)

12 12 Primitive Types GL_POINTS GL_LINE{S | _STRIP | _LOOP} GL_TRIANGLE{S | _STRIP | _FAN} GL_QUAD{S | _STRIP} GL_POLYGON OpenGL Programming Guide, page 45

13 13 GL_POLYGON List of vertices defines polygon edges Polygon must be convex

14 14 Non-planar Polygons Imagine polygon with non-planar vertices Some perspectives will be rendered as concave polygons These concave polygons may not rasterize correctly

15 15 Generating Primitives Primitive defined within glBegin() and glEnd() Very few GL commands can be executed within these two GL calls Any amount of computation can be performed glBegin (GL_LINE_LOOP); for (j=0; j<10; j++) { angle = 2*M_PI*j/10; glVertex2f (cos(angle), sin(angle); } glEnd();

16 16 glColor() Color is a GL state variable Vertices are colored according to current value glBegin (GL_POINTS) glColor3f (0.0, 1.0, 0.0); glColor3f (1.0, 0.0, 0.0); glVertex (); glColor3f (1.0, 1.0, 0.0); glColor3f (0.0, 0.0, 1.0); glVertex (); glEnd();

17 17 Polygon Rendering Options Rendered as points, lines, or filled Front and back faces can be rendered separately using glPolygonMode( ) glPolygonStipple( ) overlays a MacPaint-style overlay on the polygon glEdgeFlag specifies polygon edges that can be drawn in line mode Normal vectors: normalized is better, but glEnable (GL_NORMALIZE) will guarantee it

18 18 Polygonalization Hints Keep orientations (windings) consistent Best to use triangles (guaranteed planar) Keep polygon number to minimum Put more polygons on silhouettes Avoid T-intersections to avoid cracks Use exact say coordinates for closing loops AA B B CC BADOK

19 19 Viewing with GL Camera Analogy – Set up your tripod and point the camera Viewing Transformation – Move objects from world into camera scene Modeling Transformation – Choose a camera lens and adjust zoom Projection Transformation – Determine size of photograph Viewport Transformation

20 20 Useful Transformation Commands glMatrixMode (GL_MODELVIEW, GL_PROJECTION, or GL_TEXTURE) – Specify which matrix subsequent transformation commands will effect glLoadIdentity ( ) – Sets the currently modified matrix to identity

21 21 Useful Transformation Commands glLoadMatrix ( ) – explicitly load the parameter into the currently modified matrix glMultMatrix ( ) – explicitly multiply the currently modified matrix by the parameter matrix and store the results in the modified matrix Argument is vector of 16 values. Vector specifies matrix column by column, left to right.

22 22 Useful Transformation Commands Warning about declaring matrices in C – matrix m[4][4] can be accesses as m[ i ] [ j ], but this accesses the i th column and the j th row of the OpenGL transformation matrix – Because C convention is opposite the OpenGL convention, m[16] is recommended declaration

23 23 Modeling Transformations glTranslate (x, y, z) – Multiplies the current matrix by a matrix that moves the object by the given x-, y-, and z-values glRotate (theta, x, y, z) – Multiplies the current matrix by a matrix that rotates the object in a counterclockwise direction about the ray from the origin through the point (x, y, z)

24 24 Modeling Transformations glScale (x, y, z) – Multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object along the axes.

25 25 Viewing Transformations Default camera: y is up, look down -z axis glTranslate and glRotate change view gluLookAt ( ) uses these two commands to change the view

26 26 Projection Transformations First, execute – glMatrixMode (GL_PROJECTION); – glLoadIdentity ( ); glFrustum (…) – defines position of viewing frustum and near and far clipping planes – note, frustum need not be symmetric gluPerspective (…) – specifies frustum, but limited to symmetric ones

27 27 Viewing Transformations First, execute – glLoadMatrixMode (GL_ORTHO); – glLoadIdentity( ); glOrtho (…) – defines position of viewing frustum and near and far clipping planes gluOrtho2D (…) – projects a 2D image to a 2D screen

28 28 Viewport Transformation glViewport (x, y, width, height) – defines the lower-left corner of the viewport and the size of the viewport glDepthRange ( ) – depth, distance from camera, is stored with the (x, y) position of each rendered vertex – this function clamps the range of depth values stored in the depth buffer

29 29 Troubleshooting the ‘Black Screen’ Object color different from background? Object within the (near, far) clipping planes? – Try (0.001, 100000.0) to check Don’t make near clipping plane too small – depth buffer accuracy will degrade Camera pointing towards the object? Double-check origins for rotations

30 30 Manipulating Matrix Stacks Observation: Certain model transformations are shared among many models We want to avoid continuously reloading the same sequence of transformations glPushMatrix ( ) – push all matrices in current stack down one level and copy topmost matrix of stack glPopMatrix ( ) – pop the top matrix off the stack

31 31 Matrix Manipulation - Example Drawing a car with wheels and lugnuts draw_wheel( ); for (j=0; j<5; j++) { glPushMatrix (); glRotatef(72.0*j, 0.0, 0.0, 1.0); glTranslatef (3.0, 0.0, 0.0); draw_bolt ( ); glPopMatrix ( );

32 32 Add Matrices to Projection Stack Additional Clipping Planes – glClipPlane (ID, eqn) Six additional clipping planes can be added ID (0…5) corresponds to each plane eqn points to 4 parameters of plane: Ax + By + Cz + D = 0 – glEnable ( GL_CLIP_PLANEi ) Enables clipping plane – glDisable ( GL_CLIP_PLANEi) Disables clipping plane

33 33 Reversing Transformations Where in 3-space is the user’s mouse point? – We’ve used transformations to transform 3D to 2D – How about 2D to 3D? gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, worldx, worldy, worldz); – You provide everything but world coordinates

34 34 gluUnproject ( ) Computes the line from center of projection to mouse point Then computes the x-, y-, z-value of the line at some ‘depth’ in the world If depth is set to near clipping plane, the returned (x, y, z) is a point on the clipping plane


Download ppt "More OpenGL CS 551/645 - Introduction to Computer Graphics."

Similar presentations


Ads by Google