110 likes | 130 Views
Some Notes on 3-D. Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003. Review: Culling. Recall that polygons have a front and back. We can cull (turn off rendering of) either or both of these. Do glEnable(GL_CULL_FACE);
E N D
Some Notes on 3-D Glenn G. ChappellCHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003
Review:Culling • Recall that polygons have a front and back. • We can cull (turn off rendering of) either or both of these. • Do glEnable(GL_CULL_FACE); • Then glCullFace(…); • Parameter is GL_FRONT, GL_BACK (default), or GL_FRONT_AND_BACK. • Parameter specifies which faces to turn off. • Culling back faces can be useful. • Objects are often closed: we cannot see the inside. • Thus, rendering back faces wastes time. CS 381
Review:OpenGL Geometry Pipeline [1/2] • Here is the OpenGL Geometry Rendering Pipeline as we know it so far. • Now we add some details. In particular, the following all go into the “vertex operations” section: • Model/view transformation. • Lighting. • Projection transformation. • Clipping. • View-frustum clipping, that is. • Viewport transformation. VertexOperations Rasterization FragmentOperations Vertex enters here To framebuffer Vertices(objectcoordinates) Vertices(windowcoordinates) Fragments Fragments CS 381
Review:OpenGL Geometry Pipeline [2/2] Model/view Transformation Lighting Projection Transformation Clipping(view-frustum) Viewport Transformation ObjectCoordinates WindowCoordinates WorldCoordinates EyeCoordinates VertexOperations Rasterization FragmentOperations Vertex enters here To framebuffer Vertices(objectcoord’s) Vertices(windowcoord’s) Fragments Fragments Convert vertex data to fragment data Depth test, etc. CS 381
Some Notes on 3-D:Three Principles for 3-D CG • All graphics is 2-D graphics. • If it looks good and runs fast, then it’s good enough.* • When choosing between two equally likely options, try one; if it doesn’t work, try the other. *Don’t try to claim this when doing scientific visualization(or when told to use a specific method on an assignment). CS 381
Some Notes on 3-D:Bitmap Text in 3-D • Bitmap text does not work well in a 3-D scene. • Transformations affect neither its size nor its orientation. • But translations move it. Why the seeming inconsistency? • You may want text anyway: documentation. • Translate to just behind the near plane. • This avoids problems with floating-point equality testing. • Turn off the depth test. • Do “glDisable(GL_DEPTH_TEST);”. • Re-enable at some other time. • Be consistent: What is the state of the depth test when a callback begins & ends? • Turn off lighting, if you are using it. • As above, turn it back on at some point, and be consistent. CS 381
Some Notes on 3-D:Transform’s for Multiple Objects • To draw many objects of the same general type: • Write a function that draws the object in “standard” position. • Centered at the origin, unrotated. • More generally: The point you put at the origin is the point you want to rotate/scale about. • Repeat: • Set up a transformation. • Call the function. • Try it! CS 381
Some Notes on 3-D:Transformation Order [1/2] • Transformations are performed in the reverse order from how they are given in the code. • Why? This makes hierarchical objects work right. • Think about it. • This is why we say (in the code) translate first, then rotate & scale. • Because we want scale & rotation to happen about the origin, before translations. • What happens if we do glRotate* then glTranslate*? • How can we rotate about a line that does not pass through the origin? • See next slide. CS 381
Some Notes on 3-D:Transformation Order [2/2] • How can we rotate about a line that does not pass through the origin? • Recall: To rotate about the x-axis, doglRotated(angle, 1.,0.,0.); • Suppose we want to rotate about the line 1 unit above (+y) this? • Solution: • Translate down (0, –1, 0). • Then rotate (as above). • Then translate back up (0, +1, 0). • In the code, the transformations need to be given in the reverse order:glTranslated(0., 1., 0.);glRotated(angle, 1.,0.,0.);glTranslated(0., -1., 0.); CS 381
Some Notes on 3-D:Lighting Preview [1/2] • When we do lighting, vertices need normal vectors (“normals”). • Do “glNormal3d(…);” just before your glVertex* call. • Normals need to be unit vectors! • The glVertex* command not only specifies a vertex; it also triggers the sending of data through the pipeline. • So any data that goes with the vertex needs to be specified before the glVertex* call. • The various glutSolid… functions all specify normals properly. • Lighting and material definitions are also needed. • See sample3d.cpp, on the web page. CS 381
Some Notes on 3-D:Lighting Preview [2/2] • Normals go through the model/view transformation, too. • Problem, if you use glScale*. • Normals get scaled. • So they might not be unit vectors, when they get to the lighting section of the pipeline. • Solution: If you do lighting and use glScale*, do “glEnable(GL_NORMALIZE);” • This forces normals to be unit vectors. • It will slow things down just a little. • This is only necessary if you use both lighting and scaling. CS 381