Opengl 如何将数据从一个VBO使用到另一个VBO

Opengl 如何将数据从一个VBO使用到另一个VBO,opengl,Opengl,我想在不同的Y位置创建两个圆 目前,我正在为它们创建两个单独的VAO缓冲区 // Create data for Top Cap dataCaps.push_back(0.0f); dataCaps.push_back(height / 2.0f); // only this value will change in the nextcircle dataCaps.push_back(0.0); // Normal dataCaps.push_back(0

我想在不同的Y位置创建两个圆

目前,我正在为它们创建两个单独的VAO缓冲区

// Create data for Top Cap
    dataCaps.push_back(0.0f);
    dataCaps.push_back(height / 2.0f); // only this value will change in the nextcircle
    dataCaps.push_back(0.0);
    // Normal
    dataCaps.push_back(0.0f);
    dataCaps.push_back(1.0f);
    dataCaps.push_back(0.0f);
    // Texture Coord
    dataCaps.push_back(0.5f);
    dataCaps.push_back(0.5f);

    for (int i = 0; i < iSegments + 1; i++)
    {
        float angle = 2.0f * M_PI * i / iSegments;
        // vertex data
        float x, y, z, tx, ty, tz;
        x = cos(angle)  * radius;
        y = sin(angle)  * radius;
        z = height / 2.0f;
        tx = cos(angle) + 0.5f;
        ty = sin(angle) + 0.5f;
        dataCaps.push_back(x);
        dataCaps.push_back(z );
        dataCaps.push_back(y);
        dataCaps.push_back(0.0f);
        dataCaps.push_back(1.0f);
        dataCaps.push_back(0.0f);
        dataCaps.push_back(tx);
        dataCaps.push_back(ty);
    }
//为顶盖创建数据
dataCaps.向后推(0.0f);
dataCaps.向后推(高度/2.0f);//在下一个循环中,只有此值会更改
dataCaps.push_back(0.0);
//正常的
dataCaps.向后推(0.0f);
dataCaps.向后推(1.0f);
dataCaps.向后推(0.0f);
//纹理坐标
dataCaps.推回(0.5f);
dataCaps.推回(0.5f);
对于(int i=0;i
我有非常相同的数据,在VAO的下一个VBO中只有很少的值发生变化


我是否可以使用当前VBO中的现有数据并更改一些值来创建下一个圆,而不是为下一个圆的VBO创建新数据?

您没有对渲染管道的设置说太多(您使用的是可编程着色器还是传统的固定功能管道?)。在任何情况下,您可能已经对顶点应用了某种模型视图变换。看起来您可以很容易地将
高度/2.0f
转换合并到那里。在遗留管道中,您可以将其添加到
GL\u MODELVIEW
矩阵中(有关遗留转换的常见问题,请参阅)。在现代OpenGL中,您可以通过某种方式(例如,作为统一的方式)将移位传递到顶点着色器,并将其添加到那里的顶点坐标。

p.S.我忽略了“glsl”-标记。对不起。因此,将移位传递给顶点着色器(如果它将移动两个以上的圆,则可以使用纹理而不是均匀纹理)。这可能也是一个很好的例子,可以开始研究实例渲染(glDrawArraysInstanced和friends)。