gpt4 book ai didi

c++ - OpenGL 只从顶点数组中绘制一些索引

转载 作者:行者123 更新时间:2023-11-30 03:48:56 26 4
gpt4 key购买 nike

我怎样才能在 OpenGL 中只从顶点数组中绘制选定的索引?

例如,我用一些变量 m_pointCloud 像点一样绘制顶点包含我的点云顶点(点):

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);

但我有一些std::vector<size_t> indices包含来自 m_pointCloud 的索引我想画的。这是怎么做到的?

最佳答案

代替 glDrawArrays,使用 glDrawElements .

例如:

std::vector<GLuint> indices;

// populate vertices

glDrawElements(GL_POINTS, indices.size(), GL_UNSIGNED_INT, reinterpret_cast<void*>(indices.data()));

另请注意,您不能将 size_t 用作索引类型,因为 OpenGL 仅允许 8、16 和 32 位索引。

关于c++ - OpenGL 只从顶点数组中绘制一些索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32911279/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com