qua*_*ano 37 iphone opengl-es line antialiasing
通常,你会使用类似的东西:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glLineWidth(2.0f);
glVertexPointer(2, GL_FLOAT, 0, points);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_STRIP, 0, num_points);
glDisableClientState(GL_VERTEX_ARRAY);
Run Code Online (Sandbox Code Playgroud)
它在iPhone模拟器中看起来不错,但在iPhone上,线条变得非常薄,没有任何抗锯齿.
你如何在iPhone上获得AA?
qua*_*ano 59
使用不透明度为0的顶点可以非常便宜地实现抗锯齿效果.这是一个图像示例来解释:

与AA比较:

你可以在这里阅读一篇关于此的论文:
http://research.microsoft.com/en-us/um/people/hoppe/overdraw.pdf
你可以这样做:
// Colors is a pointer to unsigned bytes (4 per color).
// Should alternate in opacity.
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
glEnableClientState(GL_COLOR_ARRAY);
// points is a pointer to floats (2 per vertex)
glVertexPointer(2, GL_FLOAT, 0, points);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, points_count);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
Run Code Online (Sandbox Code Playgroud)
Ber*_*lor 25
从iOS 4.0开始,你有一个简单的解决方案,现在可以使用Antialiasing为整个OpenGL ES场景添加几行代码.(而且几乎没有性能损失,至少在SGX GPU上).
有关代码,请阅读以下Apple Dev-Forum主题.还有一些示例图片在我的博客上找我的样子.
使用http://answers.oreilly.com/topic/1669-how-to-render-anti-aliased-lines-with-textures-in-ios-4/作为起点,我得到了抗锯齿像这样的行:

它们并不完美,也不像我用Core Graphics绘制的那样漂亮,但它们非常好.我实际上绘制了两次相同的线(顶点) - 一次具有更大的纹理和颜色,然后具有更小的纹理和半透明的白色.
当线条重叠太紧并且alphas开始累积时会出现伪影.
| 归档时间: |
|
| 查看次数: |
43193 次 |
| 最近记录: |