Porting bgn/end Commands

IRIS GL uses the begin/end paradigm but has a different function for each graphics primitive. For example, you probably use bgnpolygon and endpolygon to draw polygons, and bgnline and endline to draw lines. In OpenGL, you use the glBegin/glEnd structure for both. In OpenGL you draw most geometric objects by enclosing a series of functions that specify vertices, normals, textures, and colors between pairs of glBegin and glEnd calls. For example:

void glBegin( GLenum mode) ; 
   /* vertex list, colors, normals, textures, materials */ 
void glEnd( void ); 
 

The glBegin function takes a single parameter that specifies the drawing mode, and thus the primitive. Here's an OpenGL code sample that draws a polygon and then a line:

glBegin( GL_POLYGON ) ; 
   glVertex2f(20.0, 10.0); 
   glVertex2f(10.0, 30.0); 
   glVertex2f(20.0, 50.0); 
   glVertex2f(40.0, 50.0); 
   glVertex2f(50.0, 30.0); 
   glVertex2f(40.0, 10.0); 
glEnd(); 
glBegin( GL_LINES ) ; 
   glVertex2i(100,100); 
   glVertex2i(500,500); 
glEnd(); 
 

With OpenGL, you draw different geometric objects by specifying different parameters for glBegin. The following table lists the OpenGL glBegin parameters that correspond to equivalent IRIS GL functions.

IRIS GL Function Value of glBegin Mode Meaning
bgnpoint GL_POINTS Individual points.
bgnline GL_LINE_STRIP Series of connected line segments.
bgnclosedline GL_LINE_LOOP Series of connected line segments, with a segment added between first and last vertices.
GL_LINES Pairs of vertices interpreted as individual line segments.
bgnpolygon GL_POLYGON Boundary of a simple convex polygon.
GL_TRIANGLES Triples of vertices interpreted as triangles.
bgntmesh GL_TRIANGLE_STRIP Linked strips of triangles.
GL_TRIANGLE_FAN Linked fans of triangles.
GL_QUADS Quadruples of vertices interpreted as quadrilaterals.
bgnqstrip GL_QUAD_STRIP Linked strips of quadrilaterals.

For a detailed discussion of the differences between triangle meshes, strips, and fans, see Porting Triangles.

There is no limit to the number of vertices you can specify between a glBegin/glEnd pair.

In addition to specifying vertices inside a glBegin/glEnd pair, you can specify a current normal, current texture coordinates, and a current color. The following table lists the commands valid inside a glBegin/glEnd pair.

IRIS GL Function OpenGL Function Meaning
v2, v3, v4 glVertex Set vertex coordinates.
RGBcolor, cpack glColor Set current color.
color glIndex Set current color index.
n3f glNormal Set normal vector coordinates.
glEvalCoord Evaluate enabled one- and two-dimensional maps.
callobj glCallList, glCallLists Execute display list(s).
t2 glTexCoord Set texture coordinates.
glEdgeFlag Control drawing edges.
lmbind glMaterial Set material properties.

Note If you use any OpenGL function other than those listed in the preceding table inside a glBegin/glEnd pair, you'll get unpredictable results, or possibly an error.