OpenGL ES 2.0 with iPhone: GL_POINT_SMOOTH draws squares with ES 2.0 but works in ES 1.0

帅比萌擦擦* 提交于 2019-12-10 19:01:25

问题


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?


回答1:


Thats becouse you enabled GL_POINT_SPRITE_OES, it is used to draw rectangles with a points, which is useful for billboards (it is simpler and faster than using 4 vertices to draw a rectangle).

Try removing glEnable(GL_POINT_SPRITE_OES); and it should work.



来源:https://stackoverflow.com/questions/7234379/opengl-es-2-0-with-iphone-gl-point-smooth-draws-squares-with-es-2-0-but-works-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!