iPhone 上的 OpenGL ES 2.0:GL_POINT_SMOOTH 使用 ES 2.0 绘制正方形,但适用于 ES 1.0
我正在尝试使用顶点缓冲区对象来绘制圆,并在 iPhone 上的 OpenGL ES 2.0 中启用 GL_POINT_SMOOTH 来绘制点。
我已经使用以下 ES 1.0 渲染代码在 iPhone 4 上成功绘制了圆圈:
glVertexPointer(2, GL_FLOAT, 0, circleVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_POINT_SMOOTH);
glPointSize(radius*2);
glDrawArrays(GL_POINTS, 0, 1);
我现在尝试使用设置 VBO 和此 ES 2.0 渲染代码来实现相同的效果:
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));
但是输出顶点非常明显是正方形,不是圆形。
我尝试减少上面的“glEnable”和相关调用来模拟第一个工作版本,但输出没有发生明显的变化;形状仍然是方形的。我还尝试将“glDrawElements”调用替换为:
glDrawArrays(GL_POINTS,0,numPoints);
..但同样没有任何变化。
在顶点着色器中设置点大小,并且着色器已成功编译并运行:
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;
}
有谁知道为什么用glDrawElements VBO版本不绘制圆?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是因为你启用了 GL_POINT_SPRITE_OES,它用于用点绘制矩形,这对于广告牌很有用(它比使用 4 个顶点绘制矩形更简单、更快)。
尝试删除 glEnable(GL_POINT_SPRITE_OES);它应该有效。
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.