问题描述
我正在尝试使用顶点缓冲区对象绘制圆,以在iPhone的OpenGL ES 2.0中启用GL_POINT_SMOOTH的情况下绘制点.
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.
我已经使用以下ES 1.0渲染代码在iPhone 4上成功绘制了圆圈:
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);
我现在正在尝试通过设置VBO以及此ES 2.0渲染代码来实现相同的效果:
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.
我已经尝试减少上述代码中的'glEnable'和相关调用,以模拟第一个工作版本,但是输出没有明显变化;形状仍然是正方形.我也尝试过将'glDrawElements'调用替换为:
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;
}
有人知道为什么用glDrawElements VBO版本没有画圆吗?
Does anyone know why circles aren't drawn with the glDrawElements VBO version?
推荐答案
那是因为您启用了GL_POINT_SPRITE_OES,它用于绘制带有点的矩形,这对于广告牌很有用(比使用4个顶点绘制更简单,更快捷)一个矩形).
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).
尝试删除glEnable(GL_POINT_SPRITE_OES);而且应该可以.
Try removing glEnable(GL_POINT_SPRITE_OES); and it should work.
这篇关于带有iPhone的OpenGL ES 2.0:GL_POINT_SMOOTH在ES 2.0中绘制正方形,但可在ES 1.0中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!