绘制元素后无法绘制数组
Cannot draw arrays after drawing elements
我有一个巨大的彩色表面(超过 130 万个索引)被绘制出来。此表面使用"彩色顶点"进行索引。每当我尝试在缓冲三角形(彩色顶点)之后绘制非缓冲三角形时,都不会显示非缓冲三角形。
如果我跳过绘制表面(缓冲三角形),则非缓冲三角形将按预期绘制。
绘制缓冲顶点:
// Bind array buffer
arrayBuffer->bind();
// Set position of vertices
int posLocation = program->attributeLocation("a_position");
program->enableAttributeArray(posLocation);
program->setAttributeBuffer(posLocation, GL_FLOAT, 0, 3, sizeof(ColoredVertex));
// Set color of vertices
int colorLocation = program->attributeLocation("a_color");
program->enableAttributeArray(colorLocation);
program->setAttributeBuffer(colorLocation, GL_FLOAT, sizeof(QVector3D), 3, sizeof(ColoredVertex));
(GLfloat) 0.0);
// Bind index buffer and draw triangles
indexBuffer->bind();
glDrawElements(GL_TRIANGLES, indicesCount(), GL_UNSIGNED_INT, 0);
绘制非缓冲顶点(面):
if (faces.size() == 0) {
qDebug("Tried to draw a textured block with no faces.");
return;
}
int posLocation = program->attributeLocation("a_position");
int texcoordLocation = program->attributeLocation("a_texcoord");
// Draw faces
QHashIterator<Block::Side, Face> iterator(faces);
while (iterator.hasNext()) {
Face face = iterator.next().value();
program->setAttributeArray(posLocation, face.coordinates.constData());
program->enableAttributeArray(posLocation);
program->setAttributeArray(texcoordLocation, face.textureCoordinates.constData());
program->enableAttributeArray(texcoordLocation);
glDrawArrays(GL_LINES, 0, 6);
}
该错误似乎是由于未正确禁用属性数组和释放缓冲区对象。以下代码按预期工作。
绘制缓冲顶点:
// Bind array buffer
arrayBuffer->bind();
int posLocation = program->attributeLocation("a_position");
int colorLocation = program->attributeLocation("a_color");
program->enableAttributeArray("a_position");
program->enableAttributeArray("a_color");
program->setAttributeBuffer(posLocation, GL_FLOAT, 0, 3, sizeof(ColoredVertex));
program->setAttributeBuffer(colorLocation, GL_FLOAT, sizeof(QVector3D), 3, sizeof(ColoredVertex));
// Bind index buffer and draw triangles
indexBuffer->bind();
glDrawElements(GL_TRIANGLES, indicesCount(), GL_UNSIGNED_INT, 0);
indexBuffer->release();
program->disableAttributeArray(posLocation);
program->disableAttributeArray(colorLocation);
arrayBuffer->release();
绘制非缓冲顶点(面):
if (faces.size() == 0) {
qDebug("Tried to draw a textured block with no faces.");
return;
}
int posLocation = program->attributeLocation("a_position");
int texcoordLocation = program->attributeLocation("a_texcoord");
program->enableAttributeArray(posLocation);
program->enableAttributeArray(posLocation);
program->enableAttributeArray(texcoordLocation);
program->enableAttributeArray(texcoordLocation);
// Draw faces
QHashIterator<Block::Side, Face> iterator(faces);
while (iterator.hasNext()) {
Face face = iterator.next().value();
program->setAttributeArray(posLocation, face.coordinates.constData());
program->setAttributeArray(texcoordLocation, face.textureCoordinates.constData());
glDrawArrays(GL_TRIANGLES, 0, face.coordinates.size());
}
program->disableAttributeArray(posLocation);
program->disableAttributeArray(texcoordLocation);
相关文章:
- 如何使用 bitblt 在屏幕上绘制由位图制作的数组?
- 尝试绘制存储在数组中的矩形,但只出现一个矩形?
- 将自定义可绘制对象存储在数组中会导致绘制时出现分割错误
- C++ 在给定像素数据数组的表单上绘制矩形
- 如何在 2d 数组中绘制 X?C++
- 使用 Win32 中的 HBITMAP 绘制一个二维数组,C++
- DirectX:从结构数组绘制多维数据集
- 绘制元素后无法绘制数组
- OpenGL 批处理:为什么我的绘制调用超出了数组缓冲区边界
- GBA C++:如何使用数组绘制多个动画像素
- 如何使用 WinAPI 将文本绘制到字节数组
- QOpenGLWidget 不绘制数组
- qwt:绘制一维数组
- 在DirectX 9中使用可扩展数组绘制三角形
- 如何快速绘制线条数组,以特殊形式给出
- OpenGL只从顶点数组中绘制一些索引
- 绘制数组
- 如何使用c++绘制一个多边形使用数组的3d点
- glDrawArrays奇怪地绘制数组
- 指示符,glDrawElements和/或其他绘制大顶点数组的方法