3

I'm trying to draw circles by using a Vertex Buffer Object to draw points with GL_POINT_SMOOTH enabled in OpenGL ES 2.0 on iPhone.

I've used the following ES 1.0 rendering code to draw circles successfully on iPhone 4:

glVertexPointer(2, GL_FLOAT, 0, circleVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_POINT_SMOOTH);
glPointSize(radius*2);
glDrawArrays(GL_POINTS, 0, 1);

I'm now trying to achieve the same effect using a set-up VBO followed by this ES 2.0 rendering code:

glEnable(GL_BLEND); 
glEnable(GL_POINT_SPRITE_OES);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glDrawElements(GL_POINTS, numPoints, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));

However the output vertices are very clearly square, not circular.

I've tried reducing the 'glEnable' and related calls in the above to emulate the first, working version but no visible change in output occurs; the shapes are still square. I've also tried replacing the 'glDrawElements' call with:

    glDrawArrays(GL_POINTS,0,numPoints);

..but again there's no change.

The point size is set in the vertex shader, and the shader is successfully compiled and run:

uniform mediump mat4 projMx;

attribute vec2 a_position;      
attribute vec4 a_color;     
attribute float a_radius;       
varying vec4 v_color;
void main()
{
    vec4 position = vec4(a_position.x,a_position.y,1.0,1.0);
    gl_Position = projMx * position;
    gl_PointSize = a_radius*2.0;
    v_color = a_color;
}

Does anyone know why circles aren't drawn with the glDrawElements VBO version?

4

1 に答える 1

1

これは、GL_POINT_SPRITE_OESを有効にしたため、ポイントを使用して長方形を描画するために使用されます。これは、ビルボードに役立ちます(4つの頂点を使用して長方形を描画するよりも簡単で高速です)。

glEnable(GL_POINT_SPRITE_OES);を削除してみてください。そしてそれは動作するはずです。

于 2011-09-12T06:23:25.100 に答える