PDA

View Full Version : Rendering of multiple vertex array



JohnnyKPL
04-14-2015, 10:27 AM
Can I render multiple vertex array with the respective number of VAO/VBO/EBO at the same time? ... or I have to put all my vertex into one big array?

Here's a "pseudocode":



GLfloat Vertices[2][20] =
{
{
// 20 vertices
},
{
// 20 vertices
}
};

GLuint Elements[2][6] =
{
{
// 6 elements
},
{
// 6 elements
}
};

/* FIRST VERTICES */
GLuint vao1, vbo1, ebo1;
init(&vao1);
bind(vao1);

init(&vbo1);
bind(vbo1);
bind_data(vbo1, Vertices[0]);

init(&ebo1);
bind(ebo1);
bind_data(ebo1, Elements[0]);

/* SECOND VERTICES */
GLuint vao2, vbo2, ebo2;
init(&vao2);
bind(vao2);

init(&vbo2);
bind(vbo2);
bind_data(vbo2, Vertices[1]);

init(&ebo2);
bind(ebo2);
bind_data(ebo2, Elements[1]);

// glDrawElements... I can't use that!



And if I can, can you give me an example?

P.S: I started programming using openGL some day ago and I don't know very well those. I'm only 14 and I'm italian, so, if in this 'message' I maked some mistakes, please mind you.

Alfonse Reinheart
04-14-2015, 10:44 AM
// glDrawElements... I can't use that!

... why not?

You bind the VAO you want to render with, and then you render. When you want to render the other VAO, you bind it, then render. Generally speaking, that's what VAOs are for.

Alternatively, you can just put them all in the same buffers/VAOs like this:



GLfloat Vertices[] =
{
// 20 vertices
// 20 vertices
};

GLuint Elements[] =
{
// 6 elements
// 6 more elements.
};

And then you use the parameters to glDrawElementsBaseVertex (https://www.opengl.org/wiki/GLAPI/glDrawElementsBaseVertex) to select which set of indices to use. The BaseVertex version is needed because the two different sets of 6 indices are based on a zero-based array. However, the second set of 20 vertices, relative to the beginning of the single array, start after element 0. So you need to offset your element index by a fixed value. That's the BaseVertex parameter.

JohnnyKPL
04-15-2015, 06:41 AM
.


GLfloat Vertices[] =
{
// 20 vertices
// 20 vertices
};

GLuint Elements[] =
{
// 6 elements
// 6 more elements.
};

And then you use the parameters to glDrawElementsBaseVertex (https://www.opengl.org/wiki/GLAPI/glDrawElementsBaseVertex) to select which set of indices to use. The BaseVertex version is needed because the two different sets of 6 indices are based on a zero-based array. However, the second set of 20 vertices, relative to the beginning of the single array, start after element 0. So you need to offset your element index by a fixed value. That's the BaseVertex parameter.

Thank you that's very helpfull ;)