Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法在绘制元素后绘制数组_C++_Qt_Opengl_Indexing - Fatal编程技术网

C++ 无法在绘制元素后绘制数组

C++ 无法在绘制元素后绘制数组,c++,qt,opengl,indexing,C++,Qt,Opengl,Indexing,我画了一个巨大的彩色表面(超过130万个索引)。此曲面使用“有色顶点”索引。每当我尝试在缓冲三角形(彩色顶点)之后绘制非缓冲三角形时,非缓冲三角形不会出现 如果我跳过绘制曲面(缓冲三角形),则非缓冲三角形将按其应有的方式绘制 绘制缓冲顶点: // Bind array buffer arrayBuffer->bind(); // Set position of vertices int posLocation = program->attributeLocation("a_posi

我画了一个巨大的彩色表面(超过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);
// 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(“尝试绘制没有面的纹理块”);
返回;
}
int posLocation=程序->属性位置(“a_位置”);
int texcoordLocation=程序->属性位置(“a_texcoord”);
//画脸
QHashIterator迭代器(面);
while(iterator.hasNext()){
Face=iterator.next().value();
program->setAttributeArray(posLocation,face.coordinates.constData());
program->enableAttributeArray(posLocation);
program->setAttributeArray(texcoordLocation,face.textureCoordinates.constData());
程序->启用属性阵列(texcoordLocation);
gldrawArray(GL_线,0,6);
}

该错误似乎是由于未正确禁用属性数组和释放缓冲区对象造成的。以下代码正常工作

绘制缓冲顶点:

// 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);
// 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(“尝试绘制没有面的纹理块”);
返回;
}
int posLocation=程序->属性位置(“a_位置”);
int texcoordLocation=程序->属性位置(“a_texcoord”);
program->enableAttributeArray(posLocation);
program->enableAttributeArray(posLocation);
程序->启用属性阵列(texcoordLocation);
程序->启用属性阵列(texcoordLocation);
//画脸
QHashIterator迭代器(面);
while(iterator.hasNext()){
Face=iterator.next().value();
program->setAttributeArray(posLocation,face.coordinates.constData());
program->setAttributeArray(texcoordLocation,face.textureCoordinates.constData());
gldrawArray(GL_三角形,0,face.coordinates.size());
}
程序->disableAttributeArray(posLocation);
程序->disableAttributeArray(texcoordLocation);

您是否曾经
disableAttributeArray(colorLocation)
?disableAttributeArray和释放缓冲区被遗忘,现在它正在工作。谢谢请随意添加您对我的代码的任何评论。我是OpenGL的新手(您可能已经意识到)