1
在iPhone上提供的OpenGL ES中繪製一個簡單的圓有三種主要方法。它們都基於一個簡單的算法(VBO版本如下)。如何用iPhone繪製反鋸齒圓OpenGL ES
void circleBufferData(GLenum target, float radius, GLsizei count, GLenum usage) {
const int segments = count - 2;
const float coefficient = 2.0f * (float) M_PI/segments;
float *vertices = new float[2 * (segments + 2)];
vertices[0] = 0;
vertices[1] = 0;
for (int i = 0; i <= segments; ++i) {
float radians = i * coefficient;
float j = radius * cosf(radians);
float k = radius * sinf(radians);
vertices[(i + 1) * 2] = j;
vertices[(i + 1) * 2 + 1] = k;
}
glBufferData(target, sizeof(float) * 2 * (segments + 2), vertices, usage);
glVertexPointer(2, GL_FLOAT, 0, 0);
delete[] vertices;
}
我知道繪製一個簡單的圓的三種方法是使用glDrawArray從應用程序所持有的頂點數組中;使用來自頂點緩衝區的glDrawArray;並通過在初始化時繪製紋理並在請求渲染時繪製紋理。前兩種方法我相當熟悉(儘管我無法使抗鋸齒工作)。最後一個選項涉及哪些代碼(我對整個OpenGL非常新,所以詳細解釋會非常有用)?哪個效率最高?
在生產代碼,scoped_array將代替明確的刪除[] – ScootyPuff 2010-08-31 13:51:26