如何在ES2.0中使用VBO绘制一个圆

我正在尝试在Linux环境下开发ES 2.0应用程序。 我的目标GPU是富士通rubyMB86298。 为了优化性能,我决定使用VBO概念。 我对维也纳国际组织是很新的。 我使用VBO渲染基本原始像trinagle和四边形,我没有顶点。 为了使用VBO渲染皇冠,我计算了所有的顶点(大于200)。 现在我发现将这200个顶点的数据发送给VBO是很困难的。我不能手动input所有的顶点数据并将其存储在一个数组中,并将其传递给VBO。 有没有办法将每个for循环的顶点数据(用于冠的顶点计算)发送到VBO? 任何人都可以使用VBO共享在ES 2.0中绘制弧形或圆形的代码片段吗?

以下是一些用于渲染圆的代码段。 我没有编译或运行此代码,所以有可能(有希望轻微)错别字。

为了准备VBO,这将做一次:

// Number of segments the circle is divided into. const unsigned DIV_COUNT = 32; // Will use a triangle fan rooted at the origin to draw the circle. So one additional // point is needed for the origin, and another one because the first point is repeated // as the last one to close the circle. GLfloat* coordA = new GLfloat[(DIV_COUNT + 2) * 2]; // Origin. unsigned coordIdx = 0; coordA[coordIdx++] = 0.0f; coordA[coordIdx++] = 0.0f; // Calculate angle increment from point to point, and its cos/sin. float angInc = 2.0f * M_PI / static_cast<float>(DIV_COUNT); float cosInc = cos(angInc); float sinInc = sin(angInc); // Start with vector (1.0f, 0.0f), ... coordA[coordIdx++] = 1.0f; coordA[coordIdx++] = 0.0f; // ... and then rotate it by angInc for each point. float xc = 1.0f; float yc = 0.0f; for (unsigned iDiv = 1; iDiv < DIV_COUNT; ++iDiv) { float xcNew = cosInc * xc - sinInc * yc; yc = sinInc * xc + cosInc * yc; xc = xcNew; coordA[coordIdx++] = xc; coordA[coordIdx++] = yc; } // Repeat first point as last point to close circle. coordA[coordIdx++] = 1.0f; coordA[coordIdx++] = 0.0f; GLuint vboId = 0; glGenBuffers(1, &circVboId); glBindBuffer(GL_ARRAY_BUFFER, circVboId); glBufferData(GL_ARRAY_BUFFER, (DIV_COUNT + 2) * 2 * sizeof(GLfloat), coordA, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); delete[] coordA; 

然后用posLoc绘制位置的顶点属性的位置:

 glBindBuffer(GL_ARRAY_BUFFER, circVboId); glVertexAttribPointer(posLoc, 2, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(posLoc); glDrawArrays(GL_TRIANGLE_FAN, 0, DIV_COUNT + 2); glBindBuffer(GL_ARRAY_BUFFER, 0);