Normally, you'd use something like:
通常情况下,你会使用如下内容:
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);
It looks good in the iPhone simulator, but on the iPhone the lines get extremely thin and w/o any anti aliasing.
它在iPhone模拟器上看起来不错,但在iPhone上,线条变得非常细,而且没有任何抗锯齿。
How do you get AA on iPhone?
你如何在iPhone上得到AA ?
7 个解决方案
#1
59
One can achieve the effect of anti aliasing very cheaply using vertices with opacity 0. Here's an image example to explain:
使用不透明度为0的顶点可以很便宜地实现反锯齿效果。这里有一个图片例子来解释:
Comparison with AA:
与AA比较:
You can read a paper about this here:
你可以在这里读一篇关于这个的文章:
http://research.microsoft.com/en-us/um/people/hoppe/overdraw.pdf
http://research.microsoft.com/en-us/um/people/hoppe/overdraw.pdf
You could do something along this way:
你可以这样做:
// 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);
#2
25
Starting in iOS Version 4.0 you have an easy solution, it's now possible to use Antialiasing for the whole OpenGL ES scene with just a few lines of added code. (And nearly no performance loss, at least on the SGX GPU).
从iOS 4.0开始,你就有了一个简单的解决方案,现在可以只用几行添加的代码就可以在整个OpenGL ES场景中使用反锯齿。(而且几乎没有性能损失,至少在SGX GPU上是这样)。
For the code please read the following Apple Dev-Forum Thread. There are also some sample pictures how it looks for me on my blog.
有关代码,请阅读下面的Apple Dev-Forum线程。我的博客上也有一些我的照片。
#3
6
Using http://answers.oreilly.com/topic/1669-how-to-render-anti-aliased-lines-with-textures-in-ios-4/ as a starting point, I was able to get anti-aliased lines like these:
使用http://answers.oreilly.com/topic/1669- howto -to- to- to- to- to- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
They aren't perfect nor are they as nice as the ones that I had been drawing with Core Graphics, but they are pretty good. I am actually drawing same lines (vertices) twice - once with bigger texture and color, then with smaller texture and translucent white.
它们并不完美,也不像我用核心图形绘制的那样好看,但它们很好。我实际上是画了相同的线(顶点)两次——一次是纹理和颜色更大,然后是纹理更小和半透明的白色。
There are artifacts when lines overlap too tightly and alphas start to accumulate.
当线重叠太紧并且阿尔法开始累积时,就会产生伪影。
#4
4
One approach around this limitation is tessellating your lines into textured triangle strips (as seen here).
围绕这个限制的一种方法是将您的线镶嵌成有纹理的三角形带(如图所示)。
#5
3
The problem is that on the iPhone OpenGl renders to a frame buffer object rather than the main frame buffer and as I understand it FBO's don't support multisampling.
问题是,在iPhone OpenGl上,渲染到帧缓存对象而不是主帧缓存,据我所知,FBO不支持多采样。
There are various tricks that can be done, such as rendering to another FBO at twice the display size and then relying on texture filtering to smooth things out, not something that I've tried though so can't comment on how well this works.
有各种各样的方法可以完成,比如将显示尺寸的两倍呈现给另一个FBO,然后依靠纹理过滤来平滑输出,这不是我尝试过的,所以不能评论它的效果。
#6
2
I remember very specifically that I tried this and there is no simple way to do this using OpenGL on the iPhone. You can draw using CGPaths and a CGContextRef, but that will be significantly slower.
我非常特别地记得我尝试过这个在iPhone上用OpenGL做这个没有简单的方法。您可以使用CGPaths和cgcontext tref来绘制,但是这要慢得多。
#7
0
Put this in your render method and setUpFrame buffer... You will get anti-aliased appearance.
把这个放到渲染方法和setUpFrame缓冲区中…你会得到反锯齿的外观。
/*added*/
//[_context presentRenderbuffer:GL_RENDERBUFFER];
//Bind both MSAA and View FrameBuffers.
glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, msaaFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, framebuffer );
// Call a resolve to combine both buffers
glResolveMultisampleFramebufferAPPLE();
// Present final image to screen
glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderBuffer);
[_context presentRenderbuffer:GL_RENDERBUFFER];
/*added*/
#1
59
One can achieve the effect of anti aliasing very cheaply using vertices with opacity 0. Here's an image example to explain:
使用不透明度为0的顶点可以很便宜地实现反锯齿效果。这里有一个图片例子来解释:
Comparison with AA:
与AA比较:
You can read a paper about this here:
你可以在这里读一篇关于这个的文章:
http://research.microsoft.com/en-us/um/people/hoppe/overdraw.pdf
http://research.microsoft.com/en-us/um/people/hoppe/overdraw.pdf
You could do something along this way:
你可以这样做:
// 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);
#2
25
Starting in iOS Version 4.0 you have an easy solution, it's now possible to use Antialiasing for the whole OpenGL ES scene with just a few lines of added code. (And nearly no performance loss, at least on the SGX GPU).
从iOS 4.0开始,你就有了一个简单的解决方案,现在可以只用几行添加的代码就可以在整个OpenGL ES场景中使用反锯齿。(而且几乎没有性能损失,至少在SGX GPU上是这样)。
For the code please read the following Apple Dev-Forum Thread. There are also some sample pictures how it looks for me on my blog.
有关代码,请阅读下面的Apple Dev-Forum线程。我的博客上也有一些我的照片。
#3
6
Using http://answers.oreilly.com/topic/1669-how-to-render-anti-aliased-lines-with-textures-in-ios-4/ as a starting point, I was able to get anti-aliased lines like these:
使用http://answers.oreilly.com/topic/1669- howto -to- to- to- to- to- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
They aren't perfect nor are they as nice as the ones that I had been drawing with Core Graphics, but they are pretty good. I am actually drawing same lines (vertices) twice - once with bigger texture and color, then with smaller texture and translucent white.
它们并不完美,也不像我用核心图形绘制的那样好看,但它们很好。我实际上是画了相同的线(顶点)两次——一次是纹理和颜色更大,然后是纹理更小和半透明的白色。
There are artifacts when lines overlap too tightly and alphas start to accumulate.
当线重叠太紧并且阿尔法开始累积时,就会产生伪影。
#4
4
One approach around this limitation is tessellating your lines into textured triangle strips (as seen here).
围绕这个限制的一种方法是将您的线镶嵌成有纹理的三角形带(如图所示)。
#5
3
The problem is that on the iPhone OpenGl renders to a frame buffer object rather than the main frame buffer and as I understand it FBO's don't support multisampling.
问题是,在iPhone OpenGl上,渲染到帧缓存对象而不是主帧缓存,据我所知,FBO不支持多采样。
There are various tricks that can be done, such as rendering to another FBO at twice the display size and then relying on texture filtering to smooth things out, not something that I've tried though so can't comment on how well this works.
有各种各样的方法可以完成,比如将显示尺寸的两倍呈现给另一个FBO,然后依靠纹理过滤来平滑输出,这不是我尝试过的,所以不能评论它的效果。
#6
2
I remember very specifically that I tried this and there is no simple way to do this using OpenGL on the iPhone. You can draw using CGPaths and a CGContextRef, but that will be significantly slower.
我非常特别地记得我尝试过这个在iPhone上用OpenGL做这个没有简单的方法。您可以使用CGPaths和cgcontext tref来绘制,但是这要慢得多。
#7
0
Put this in your render method and setUpFrame buffer... You will get anti-aliased appearance.
把这个放到渲染方法和setUpFrame缓冲区中…你会得到反锯齿的外观。
/*added*/
//[_context presentRenderbuffer:GL_RENDERBUFFER];
//Bind both MSAA and View FrameBuffers.
glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, msaaFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, framebuffer );
// Call a resolve to combine both buffers
glResolveMultisampleFramebufferAPPLE();
// Present final image to screen
glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderBuffer);
[_context presentRenderbuffer:GL_RENDERBUFFER];
/*added*/