Intro to Open GL Vertices and Drawing Geb
Intro to Open. GL: Vertices and Drawing Geb Thomas (Adapted from Open. GL Programming Guide)
Learning Objectives Learn how to define vertices Learn how to draw polygons, lines, and points Learn how to define and use surface normals
Points and Lines Points n n One vertex per point You can control the size and color of a point Lines n n Lines are line segments (they have a beginning and an end). You can control with width and the stipple
Polygons can have n vertices All the vertices should be in the same plane. The polygon should be convex
Vertices void gl. Vertex{234}{sifd}[v](TYPEcoords); Specifies a vertex for use in describing a geometric object. You can supply up to four coordinates (x, y, z, w) for a particular vertex or as few as two (x, y) by selecting the appropriate version of the command. If you use a version that doesn't explicitly specify z or w, z is understood to be 0 and w is understood to be 1. Calls to gl. Vertex*() are only effective between a gl. Begin() and gl. End() pair.
Vertex Examples gl. Vertex 2 s(2, 3); gl. Vertex 3 d(0. 0, 3. 1415926535898); gl. Vertex 4 f(2. 3, 1. 0, -2. 2, 2. 0); GLdouble dvect[3] = {5. 0, 9. 0, 1992. 0}; gl. Vertex 3 dv(dvect);
Drawing Primitives gl. Begin(GL_POLYGON); n n n gl. Vertex 2 f(0. 0, 0. 0); gl. Vertex 2 f(0. 0, 3. 0); gl. Vertex 2 f(4. 0, 3. 0); gl. Vertex 2 f(6. 0, 1. 5); gl. Vertex 2 f(4. 0, 0. 0); gl. End();
Primitives, Illustrated
Drawing Details void gl. Point. Size(GLfloat size); Sets the width in pixels for rendered points; size must be greater than 0. 0 and by default is 1. 0. void gl. Line. Width(GLfloat width); Sets the width in pixels for rendered lines; width must be greater than 0. 0 and by default is 1. 0.
Line Stipple void gl. Line. Stipple(GLint factor, GLushort pattern); w Sets the current stippling pattern for lines. The pattern argument is a 16 -bit series of 0 s and 1 s, and it's repeated as necessary to stipple a given line. A 1 indicates that drawing occurs, and 0 that it does not, on a pixel-by-pixel basis, beginning with the low-order bit of the pattern. The pattern can be stretched out by using factor, which multiplies each subseries of consecutive 1 s and 0 s. Thus, if three consecutive 1 s appear in the pattern, they're stretched to six if factor is 2. factor is clamped to lie between 1 and 255. Line stippling must be enabled by passing GL_LINE_STIPPLE to gl. Enable(); it's disabled by passing the same argument to gl. Disable().
Line Stipple Example gl. Line. Stipple(1, 0 x 3 F 07); gl. Enable(GL_LINE_STIPPLE);
Polygon Filling void gl. Polygon. Mode(GLenum face, GLenum mode); w Controls the drawing mode for a polygon's front and back faces. The parameter face can be GL_FRONT_AND_BACK, GL_FRONT, or GL_BACK; mode can be GL_POINT, GL_LINE, or GL_FILL to indicate whether the polygon should be drawn as points, outlined, or filled. By default, both the front and back faces are drawn filled.
Polygon Culling void gl. Front. Face(GLenum mode); w Controls how front-facing polygons are determined. By default, mode is GL_CCW, which corresponds to a counterclockwise orientation of the ordered vertices of a projected polygon in window coordinates. If mode is GL_CW, faces with a clockwise orientation are considered front-facing. void gl. Cull. Face(GLenum mode); w Indicates which polygons should be discarded (culled) before they're converted to screen coordinates. The mode is either GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK to indicate front-facing, back-facing, or all polygons. To take effect, culling must be enabled using gl. Enable() with GL_CULL_FACE; it can be disabled with gl. Disable() and the same argument.
Polygon Normals A normal vector sets the current normal for the subsequent vertices. gl. Begin (GL_POLYGON); gl. Normal 3 fv(n 0); gl. Vertex 3 fv(v 0); gl. Normal 3 fv(n 1); gl. Vertex 3 fv(v 1); gl. Normal 3 fv(n 2); gl. Vertex 3 fv(v 2); gl. Normal 3 fv(n 3); gl. Vertex 3 fv(v 3); gl. End();
Learning Objectives Learn how to define vertices Learn how to draw polygons, lines, and points Learn how to define and use surface normals
- Slides: 15