Specifying Vertices
  • Examples:

  •  

     

    glVertex2s(2, 3); 
    glVertex3d(0.0, 0.0, 3.1415926535898);
    glVertex4f(2.3, 1.0, -2.2, 2.0); 
    GLdouble dvect[3] = {5.0, 9.0, 1992.0}; 
    glVertex3dv(dvect);
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Drawing  primitives
  • glBegin() / glEnd() pair surround glVertex() calls

  •  
      glBegin(GL_POLYGON);
         glVertex2f(0.0, 0.0);
         glVertex2f(0.0, 3.0);
         glVertex2f(4.0, 3.0);
         glVertex2f(6.0, 1.5);
         glVertex2f(4.0, 0.0);
      glEnd();

     
  •  Figure 2-6

  •  

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Primitive Specification
    GL_POINTS             individual points
    GL_LINES              pairs of vertices interpreted as 
                             individual segments
    GL_LINE_STRIP         series of connected line segments
    GL_LINE_LOOP          same as above, with a segment added 
                             between last and first vertices
    GL_TRIANGLES          triples of vertices interpreted as 
                             triangles
    GL_TRIANGLE_STRIP     linked strip of triangles
    GL_TRIANGLE_FAN       linked fan of triangles
    GL_QUADS              quadruples of vertices interpreted 
                             as four-sided polygons
    GL_QUAD_STRIP         linked strip of quadrilaterals
    GL_POLYGON            boundary of a simple, convex polygon
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Primitive Specification (cont)
  • Figure 2-7

  •  

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Vertex specification
     
  •  color/texture, etc. specifications reflect the current state of the OpenGL state machine.
  •  Vertices are only generated by a glVertex() call.

  • glBegin(GL_POINTS);
    glColor3f(0.0, 1.0, 0.0); /* green */
    glColor3f(1.0, 0.0, 0.0); /* red */
    glVertex(...);
    glColor3f(1.0, 1.0, 0.0); /* yellow */
    glColor3f(0.0, 0.0, 1.0); /* blue */
    glVertex(...);


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

State Management
  •  State variables specify OpenGL rendering qualities such as:
    • Color
    • Texture
    • Lighting
  •  Most states are turned off by default
  •  Turning on these variables can be expensive but can improve the image quality greatly
  •  State variables are changed with glEnable() or glDisable()
  •  Values can be queried by glGet() calls (p. 50)

  •  

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Displaying Points, Lines, and Polygons
  • By default:
    • Polygons are filled
    • Points are one-pixel
    • Lines are solid, one-pixel wide 

    •  
  • glPointSize() specifies the width of a point
    • If anitaliasing is enabled, a circular group of pixels is drawn
    • If antialiasing is disabled screen-aligned rectangular pixels are drawn (fractional pixels are rounded to integer values)

    •  

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Specifying line parameters
  • glLineWidth() specifies the width of lines

  • NOTE! With nonantialiased wide lines, the line width isn't measured perpendicular to the line. Instead, it's measured in the y direction if the absolute value of the slope is less than 1.0; otherwise, it's measured in
    the x direction. The rendering of an antialiased line is exactly equivalent to the rendering of a filled rectangle of the given width, centered on the exact line.
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Stippled Lines
  • Figure 2-8

  • To make stippled (dotted or dashed) lines, you use the command glLineStipple() to define the stipple pattern, and then you enable line stippling with glEnable().

    glLineStipple(1, 0x3F07);
    glEnable(GL_LINE_STIPPLE);

    void glLineStipple(GLint factor, GLushort pattern);

    Sets the current stippling pattern for lines. 

    The pattern argument is a 16-bit series of 0s and 1s, 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. 
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

Stippled Lines (cont)
  • Figure 2-9
  •  Beware!  The OpenGL state machine can be simplistic (i.e. stoopid)

  •