First Draw Call
Last updated
Last updated
For a simple draw call we need at least one VAO setup correct and one Shader Program. There are multiple functions in OpenGL to draw. One and maybe the easiest of them is glDrawArrays:
The 1. parameter can be one of the folowwing GL enums:
The 2. is an offset of the number of to draw primitives.
The 3. parameter tells how many elements you want to use to draw the primitive. This parameter can be confusing. For example, if you want to draw 1 triangle you might think that you pass here 1, but what you have to pass here is the number of elements that shapes the triangle. So for one triangle you have to pass at least the value 3 (3 vertex points = 1 Triangle). If you would want to draw 2 triangles you have to pass the value of 6. Easy right :D? This number of course depends which mode you selected, in short which type of primitive you want to draw. If you have points then yes you pass the number of points you want to draw. If you want to draw 2 points, use pass the value 2 here.
Before we can use the any of the draw functions of OpenGL we have to bind a VAO we like to reference and the same for a shader program. Binding a VAO is easy and is done with glBindVertexArray. For our example we would use:
Next is we need to tell OpenGL which Shader Program to use. We do that with glUseProgram. Using our simple example this would look like this:
Now we are ready to use one of the draw calls.
glDrawArrays
Parameters
Type
Description
1
GLenum mode
The primitive type we like to render.
2
GLint first
Offset inside the BO we like to use. This is not in bytes, it is more in elements within the BO itself.
3
GLsizei count
The number of elements to use within the BO to draw the primitive. Better explanation see below :D.
Mode
Description
GL_POINTS
GL_PATCHES
GL_LINE_STRIP
GL_LINE_LOOP
GL_LINE_STRIP_ADJACENCY
GL_LINES_ADJACENCY
GL_LINE_STRIP
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
GL_TRIANGLES
GL_TRIANGLE_STRIP_ADJACENCY
GL_TRIANGLES_ADJACENCY