Reputation: 3124
how can I only draw selected indices from vertex array in OpenGL?
For instance, I am drawing my vertices like points, with some variable m_pointCloud
containing my point cloud vertices (points):
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glPointSize(m_pointSize * point_scale);
glColorPointer(4, GL_UNSIGNED_BYTE,
static_cast<GLsizei>(sizeof(DensePoint)), &((*m_pointCloud)[0].r));
// glNormalPointer(GL_FLOAT,
// static_cast<GLsizei>(sizeof(DensePoint)), &((*m_pointCloud)[0].n_x));
glVertexPointer(3, GL_FLOAT,
static_cast<GLsizei>(sizeof(DensePoint)), &((*m_pointCloud)[0].x));
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(m_pointCloud->size()) - 1);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
But I have some std::vector<size_t> indices
containing the indices from m_pointCloud
that I want to draw. How is this done?
Upvotes: 1
Views: 979
Reputation:
Instead of glDrawArrays, use glDrawElements.
For example:
std::vector<GLuint> indices;
// populate vertices
glDrawElements(GL_POINTS, indices.size(), GL_UNSIGNED_INT, reinterpret_cast<void*>(indices.data()));
Note also that you cannot use size_t
as an index type as OpenGL only allows 8, 16 and 32-bit indices.
Upvotes: 3