-1

如何将两个顶点缓冲区绑定到不同的插槽(slot0 和 slot1),

我想要在 OpenGL(QT) 中这样的东西:

QGLBuffer VB0, VB1;

VB0.bind(0);
VB1.bind(1);

到目前为止我有这个:

verticesBuffer = new QGLBuffer(QGLBuffer::VertexBuffer);
verticesBuffer->create();
verticesBuffer->bind();
verticesBuffer->setUsagePattern(QGLBuffer::DynamicDraw);
verticesBuffer->allocate(vertices.constData(), _ANGLE_CNT * _RANGE_CNT * 6 * sizeof(QVector3D));
verticesBuffer->release();

colorsBuffer = new QGLBuffer(QGLBuffer::VertexBuffer);
colorsBuffer->create();
colorsBuffer->bind();
colorsBuffer->setUsagePattern(QGLBuffer::DynamicDraw);
colorsBuffer->allocate(_ANGLE_CNT * _RANGE_CNT * 6 * sizeof(float));
colorsBuffer->release();

您能否编写一个示例来解释我应该如何将这两个缓冲区绑定到插槽?

4

2 回答 2

-1

当人们不完全理解我的问题时,他们不会随意投反对票。我在另一个论坛上问了同样的问题,我得到了确切的答案。我的帐户已被这种愚蠢的投票方式封锁。所以,在这里我回答我自己的问题:

glGenVertexArrays(1, &VAO_ID);
glBindVertexArray(VAO_ID);

glBindBuffer(GL_ARRAY_BUFFER,buffer_0_id);
 glVertexAttribPointer(POSITION_0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
...


glBindBuffer(GL_ARRAY_BUFFER,buffer_1_id);
 glVertexAttribPointer(POSITION_1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
...

layout(location = POSITION_0) in  vec3  Position0;
layout(location = POSITION_1) in  vec3  Position1;
于 2013-06-27T09:49:41.730 回答
-2

更新:将此添加到初始化部分:

verticesSize = sizeof(vertices);
colorsSize   = sizeof(colors);

glGenBuffers(2, vbods);                       

glBindBuffer(GL_ARRAY_BUFFER, vbods[VERTEX]); 

glBufferData(GL_ARRAY_BUFFER,
             sizeof(vertices)+sizeof(colors),
             vertices, GL_STATIC_DRAW );

glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(colors), colors);

glEnableClientState(GL_VERTEX_ARRAY); 
glEnableClientState(GL_COLOR_ARRAY);  

这到渲染部分:

glBindBuffer(GL_ARRAY_BUFFER, vbods[VERTEX]);
glVertexPointer(2, QVector3D, 0, 0);   
glColorPointer(3, GL_FLOAT, 0, (GLvoid *) (ANGLE_COUNT * RANGE_COUNT * 6));    
于 2013-06-20T09:52:20.293 回答