I'm trying to create and element array buffer to draw two different shapes with a different number of vertices. I haven't been able to find any resources on this as they mostly show how to draw a single triangle or square separately.
Let's say i want to draw both at the same time, the square would have 6 indices while the triangle(just an example) would have 3 indices. But I'm not sure how to go about this. I've tried having two element array buffers or just reassigning it.
float vertice[] =
{
-0.5f, -0.5f, 0.0f, 0.5f, 0.3f, 0.0f,
0.5f, 0.5f, 0.0f, 0.5f, 0.3f, 0.0f,
0.5f, -0.5f, 0.0f, 0.5f, 0.3f, 0.0f,
-0.5f, 0.5f, 0.0f, 0.5f, 0.3f, 0.0f
};
float vertices2[] =
{
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f
};
int indice[] =
{
0, 1, 2,
0, 1, 3
};
int indice2[] =
{
0, 1, 3
};
VertexArray vao;
vao.Bind();
VertexBuffer vbo(vertice, sizeof(vertice), GL_STATIC_DRAW);
vbo.Bind();
IndexBuffer ibo(indice, sizeof(indice), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
vao.Unbind();
vbo.Unbind();
VertexArray vao2;
vao2.Bind();
VertexBuffer vbo2(vertices2, sizeof(vertices2), GL_STATIC_DRAW);
vbo2.Bind();
IndexBuffer ibo2(indice2, sizeof(indice2), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
vao2.Unbind();
vbo2.Unbind();
vao.Bind();
ibo.Bind();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
ibo.Unbind();
vao.Unbind();
vao2.Bind();
ibo2.Bind();
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
ibo2.Unbind();
vao2.Unbind();
If anyone has any resources or something where i can work out how to do this properly, that be very much appreciated.