230 likes | 246 Views
Computer Graphics: Programming, Problem Solving, and Visual Communication. Steve Cunningham California State University Stanislaus and Grinnell College PowerPoint Instructor’s Resource. Implementing Modeling in OpenGL. Going from concepts to images. Modeling Topics. Specifying geometry
E N D
Computer Graphics:Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College PowerPoint Instructor’s Resource
Implementing Modeling in OpenGL Going from concepts to images
Modeling Topics • Specifying geometry • GLU and GLUT tools • Transformations • Transformation Stack • Drawing text • Inverting the eyepoint transformation • Display lists
Specifying Geometry • General model isglBegin(grouping_mode); vertex listglEnd(); • The grouping mode identifies how the vertices are to be used • The vertices in the vertex list can be done manually or by computation
Specifying Geometry (2) • There are many different grouping modes that OpenGL recognizes • Simple modes: • GL_POINTS • GL_LINES • GL_TRIANGLES • GL_QUADS • GL_POLYGON
Specifying Geometry (3) • Geometry compression modes: • GL_LINE_STRIP • GL_TRIANGLE_STRIP • GL_TRIANGLE_FAN • GL_QUAD_STRIP
Specifying Geometry (4) • Some details of OpenGL geometry: • All OpenGL polygons are assumed to be convex • Polygons use vertices as if they were from a triangle fan • Quad strips use vertices as if they were for triangle strips, so the order is different from GL_QUADS
Specifying Geometry (5) • The vertex list can use vertices of many different types • The vertex data type is specified in the the particular glVertex* function name • glVertex[2|3][i|f|d]{v} • There are additional options, but they are not often used
Specifying Geometry (6) • As you specify the geometry with the vertices, you can specify other data for each vertex (e.g. appearance data) • glColor*(…) • glNormal*(…) • glTexCoord*(…) • Vertices can be given individually or as vertex arrays, reducing function calls
Triangle fan used to create a cone Triangle strips used to create a surface (one strip shown) Some Sample OpenGL Objects
Appearance Information • Simple OpenGL drawing uses edges that are one pixel wide and are not antialiased • You can specify point sizes and line width • You can antialias points, lines, and polygon edges • glEnable(type) as appropriate • glHint(type, value)
Clipping • Besides the automatic clipping on the view volume, you can specify other clipping by defining clip planes • Clip planes are defined by the coordinates in the plane equation glClipPlane(number,plane) • Clip planes may be enabled or disabled as your program runs
GLU Quadric Objects • The GLU utilities include a number of useful objects • gluSphere • gluCylinder • gluDisk • All require that you first create a general GLUquadric pointer: GLUquadric* gluNewQuadric(void)
GLU Quadric Objects (2) • GLU quadric objects are created by invoking a function that uses the GLUquadric* value • The function also defines granularity and size • You can select whether the object is solid or wireframe • You can specify if you want to have normals or texture coordinates generated automatically
Cone Sphere Cube Torus Dodecahedron Icosahedron Octahedron Tetrahedron Teapot GLUT Objects GLUT provides a number of additional graphical objects you can use easily Each of these can be either wireframe or solid
Transformations in OpenGL • Rotation glRotatef(angle, x, y, z) • Translation glTranslatef(tx, ty, tz) • Scaling glScalef(sx, sy, sz) • Individually these are simple, but they can be composed to create complex transformations
Transformation Stacks • You can create a stack for any of the standard OpenGL transformations • The modelview transformation stack is critically important to manage the scene graph glMatrixMode(GL_MODELVIEW); glPushMatrix(); … glPopMatrix();
Text in OpenGL • Text is handled by a GLUT function that writes a character at a time in the font (usually bitmapped) you choose glutBitmapCharacter(font, char) • Text you create this way is simply placed on the screen and cannot be selected
Inverting the Eyepoints • We saw that it can be useful to move the eyepoint in your model • Of course, you could call glutLookAt(…) with new viewing data each time you redraw the scene • The viewing data uses raw coordinates, though, and this could be difficult to calculate with many eye motions
Inverting the Eyepoint (2) • The eyepoint motion will probably be set by using simple transformations • If these simple transformations areT1*T2*T3* … *TNthen their inverse is TN-1*…*T3-1*T2-1*T1-1 and each of the inverses is simple
Inverting the Eyepoint (3) • In order to make the eyepoint placement easy, you can simply apply the needed inverse transformations at the top of the scene graph (at the beginning of the display function) and then use the default view
Creating Display Lists • Display lists are OpenGL’s way to compile geometry • This lets the system work on geometry that has been optimized, making it faster to draw complex objects glNewList(i); … glEndList(); • You can then use this geometry with glCallList(i);