Graphics / Reference / OpenGL draw calls
OpenGL draw calls
glDrawArrays submits a range of already prepared vertices for primitive processing. Its primitive mode determines whether consecutive vertices are grouped as independent lines or triangles.
glDrawArrays uses vertex data and attribute state that have already been prepared. Before calling it, the required vertex data has been uploaded to a buffer and the correct VAO must be bound.
glDrawArrays(GL_LINES, 0, vertexCount) starts at vertex index 0 and treats each consecutive pair of vertices as one independent line.
glDrawArrays(GL_TRIANGLES, 0, vertexCount) starts at vertex index 0 and treats each consecutive group of three vertices as one triangle.
Example draws:
glUniform3f(locColor, 0.8, 0.2, 0.2); glBindVertexArray(vaoTri); glDrawArrays(GL_TRIANGLES, 0, 3);
glUniform3f(locColor, 0.95, 0.9, 0.2); glBindVertexArray(vaoLine); glLineWidth(2.0); glDrawArrays(GL_LINES, 0, 2);
The first sequence draws one triangle from three vertices using the current red colour. The second draws one line from two vertices using the current yellow colour.
glLineWidth(2.0f) requests a wider rasterised line, but supported widths and resulting behaviour can depend on the driver and implementation.
Builds on
Read
- Read the chapter: OpenGL draw calls