Reputation: 913
For an assignment I need to write a program that on the first click will draw a point, on the second click will draw a line and on the third click will make the triangle. All of this is done in OpenGL.
I don't need any code, but as I'm brand new to all of this I'm having a difficult time understanding how to send this to the GPU with glDrawArrays(), as the function takes in a mode
. I know I want to keep appending the points to an array - but as the mode keeps changing (GL_POINTS, GL_LINE_LOOP, GL_TRIANGLES) I don't know how to store it.
Any and all conceptual help would be really appreciated.
Upvotes: 1
Views: 616
Reputation: 63481
You said you don't want code, but honestly I could try and give a fluffy explanation with lots of words, or I could just explain it concisely in code.
Let's say you have N vertices in your vertex buffer. It seems like you want something like this:
int num_extra_verts = N % 3;
int num_tri_verts = N - num_extra_verts;
// Draw triangles
if (num_tri_verts > 0)
glDrawArrays(GL_TRIANGLES, 0, num_tri_verts);
// Draw point or line
if (num_extra_verts == 1)
glDrawArrays(GL_POINTS, num_tri_verts, 1);
else if (num_extra_verts == 2)
glDrawArrays(GL_LINES, num_tri_verts, 2); // GL_LINE_LOOP not needed for single line
Provided you keep adding new points to the end of your vertex buffer, this will draw all the triangles created so far, plus any single point or line for the most recent not-yet-whole-triangle.
Upvotes: 1