200 likes | 328 Views
Explore the ongoing debate on supported primitives in OpenGL API, including geometric and raster primitives with examples like GL_LINES and GL_POINTS. Learn about command formats and polygon types in OpenGL.
E N D
OpenGL Primitives • An ongoing debate about which primitives should be supported in an API. • OpenGL takes an intermediate position
Two classes of primitives • Geometric Primitives • Raster Primitives
GL_LINES glBegin(GL_LINES); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd( );
GL_POINTS glBegin(GL_POINTS); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd( );
glVertex* • #define GLfloat float • glVertex2i (GLint xi, GLint yi) • glVertex3f (GLfloat x, GLfloat y, GLfloat z )
glVertex* GLfloat vertex[3] glVertex3fv(vertex)
OpenGL Geometric Primitives • GL_POINTS • GL_LINES • GL_LINE_STRIP • GL_LINE_LOOP
P2 P1 P3 P4 P0 P5 GL_POINTS
P2 P1 P3 P4 P0 P5 GL_LINES
GL_LINES_STRIP P2 P1 P3 P4 P0 P5
GL_LINES_LOOP P2 P1 P3 P4 P0 P5
Polygon Types in OpenGL • GL_POLYGON • GL_TRIANGLES • GL_QUADS • GL_TRIANGLE_STRIP • GL_QUAD_STRIP • GL_TRIANGLE_FAN
GL_POLYGON P2 P1 P3 P4 P0 P5
GL_TRIANGLES P2 P1 P3 P4 P0 P5
P2 P1 P3 P4 P0 P5 GL_QUADS
Example 1 void drawRhombus( GLfloat color[] ) {glBegin( GL_QUADS ); glColor3fv( color ); glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 ); glVertex2f( 1.5, 1.118 ); glVertex2f( 0.5, 1.118 ); glEnd(); }
GLfloat red, greed, blue; Glfloat coords[3]; glBegin( primType ); for ( i = 0; i < nVerts; ++i ) { glColor3f( red, green, blue ); glVertex3fv( coords ); } glEnd(); Example 2