1
votes

This is the super simple version of the question I posted earlier (Which I think is too complicated)

How do I draw a Line in OpenGL ES 2.0 Using as a reference a stroke on the Touch Screen?

For example If i draw a square with my finger on the screen, i want it to be drawn on the screen with OpenGL.

I have tried researching a lot but no luck so far.

(I only now how to draw objects which already have fixed vertex arrays, no idea of how to draw one with constantly changing array nor how to implement it)

1

1 Answers

1
votes

You should use vertex buffer objects (VBOs) as the backing OpenGL structure for your vertex data. Then, the gesture must be converted to a series of positions (I don't know how that happens on your platform). These positions must then be pushed to the VBO with glBufferSubData if the existing VBO is large enough or glBufferData if the existing VBO is too small.

Using VBOs to draw lines or any other OpenGL shape is easy and many tutorials exist to accomplish it.

update

Based on your other question, you seem to be almost there! You already create VBOs like I mentioned but they are probably not large enough. The current size is sizeof(Vertices) as specified in glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

You need to change the size given to glBufferData to something large enough to hold all the original vertices + those added later. You should also use GL_STREAM as the last argument (read up on the function).

To add a new vertex, use something like this :

glBufferSubData(GL_ARRAY_BUFFER, current_nb_vertices*3*sizeof(float), nb_vertices_to_add, newVertices);
current_nb_vertices += nb_vertices_to_add;
//...
// drawing lines
glDrawArrays(GL_LINE_STRIP, 0, current_nb_vertices);

You don't need the indices in the element array to draw lines.