The table below illustrates all seven currently supported modes that can be used in glDrawArrays and other similar functions when the current shader program consists only of a vertex shader and a fragment shader. (ADJACENCY versions of some of these and GL_PATCHES are also supported if the shader program includes a geometry shader or tessellation shader, respectively.)
The seven images in the top three rows of both columns represent all the different ways the same set of 14 points can be interpreted. The points are stored in the coordinate buffer in a left-to-right, top-to-bottom order.
The images in the first column of the table show the primitive as it would actually be rendered by the indicated glDrawArrays call. The black points that you see in the images in the second column of the table show the actual points in the VBO; the black edges in the second column highlight the actual triangles that get drawn.
As a side note, the OpenGL glPolygonMode function was used to augment the displays shown in the second column with the vertices and edges. Refer to the API description for that routine for details.
The triangle fan in the last image on the third row leads to an "interesting" evergreen tree-like appearance due to the way the triangles all overlap one another. Notice in the corresponding image in the second column how the black triangle edges intersect with one another, indicating that the triangles overlap. While "interesting", the triangle fan examples illustrated in the fourth row illustrate more typical uses of the GL_TRIANGLE_FAN primitive.
Notice also the two unused points in the GL_TRIANGLES figure. That primitive consumes points three at a time. If there are one or two extra points in the buffer when this primitive is rendered, it simply ignores them. In a similar manner, GL_LINES consumes points two at a time, so if there are an odd number of points in the buffer, the last one will be ignored.
Each image below was generated from glDrawArrays(mode, 0, nPoints); where: mode is indicated by the blue labels nPoints is 14 in top three rows; it is 5, 8, and 61 in the bottom row The same VBO is used for all images in the top three rows. | |
Result | Result augmented with edges and vertices |
---|---|
![]() |
![]() |