jorgus117

02-21-2016, 02:28 AM

I tried to create program in which I would draw multiple polygons here is fragment of what I have done:

GLuint VertexArrayID;

exampleof drawing triangle(I have more polygons, like circle, and so on..)

if (figure == RECTANGLE)

{

data[0][0] = px1; data[0][1] = py1;

data[1][0] = px2; data[1][1] = py1;

data[2][0] = px2; data[2][1] = py2;

data[3][0] = px1; data[3][1] = py2;

vertex_count = 4;

}

if (vertex_count > 0)

{

glGenBuffers(3, VertexArrayID);

glBindBuffer(GL_ARRAY_BUFFER, VertexArrayID[0]);

glBufferData(GL_ARRAY_BUFFER, 2 * sizeof(float), data, GL_STATIC_DRAW);

//GLfloat* data = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);

glVertexPointer(2, GL_FLOAT, 0, NULL);

glEnableClientState(GL_VERTEX_ARRAY);

glDrawArrays(GL_TRIANGLE_FAN, 0, vertex_count);

glDisableClientState(GL_VERTEX_ARRAY);

}

Now the point is that I want to: 1) create polygon 2) save this polygon ob buffer 3) create other polygon 4) save that polygon 5) and so..

I know that here I create N buffers:

glGenBuffers(N, VertexArrayID);

But I need to know how to save each polygon on each buffer, and then show it all on screen. I tried do use glBufferSubData, glMapBuffer, I have read many tutorials, but still I don't know how to do that.

GLuint VertexArrayID;

exampleof drawing triangle(I have more polygons, like circle, and so on..)

if (figure == RECTANGLE)

{

data[0][0] = px1; data[0][1] = py1;

data[1][0] = px2; data[1][1] = py1;

data[2][0] = px2; data[2][1] = py2;

data[3][0] = px1; data[3][1] = py2;

vertex_count = 4;

}

if (vertex_count > 0)

{

glGenBuffers(3, VertexArrayID);

glBindBuffer(GL_ARRAY_BUFFER, VertexArrayID[0]);

glBufferData(GL_ARRAY_BUFFER, 2 * sizeof(float), data, GL_STATIC_DRAW);

//GLfloat* data = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);

glVertexPointer(2, GL_FLOAT, 0, NULL);

glEnableClientState(GL_VERTEX_ARRAY);

glDrawArrays(GL_TRIANGLE_FAN, 0, vertex_count);

glDisableClientState(GL_VERTEX_ARRAY);

}

Now the point is that I want to: 1) create polygon 2) save this polygon ob buffer 3) create other polygon 4) save that polygon 5) and so..

I know that here I create N buffers:

glGenBuffers(N, VertexArrayID);

But I need to know how to save each polygon on each buffer, and then show it all on screen. I tried do use glBufferSubData, glMapBuffer, I have read many tutorials, but still I don't know how to do that.