开发者

iPhone OpenGL ES draw nice lines

In my iPhone applica开发者_JAVA百科tion, many lines are drawn. Alas, some of them are neither vertical nor horizontal, meaning that they have jagged edges.

Enabling GL_LINE_SMOOTH seems to have no effect. Multisample antialiasing as described in Apple's documentation works, but I can't imagine that it's impossible to make nicer looking lines. With the antialiasing the line becomes smooth but the color is distorted along sections of the line.

Using OpenGL, how can you draw a line that looks like a line drawn by Quartz-2D, with a smooth border, consistent color, and variable width?

(To be clear, GL_LINE_WIDTH works perfectly, so variable width is not currently an issue.)


This is a common problem in 3D graphics. Most graphics cards are usually more concerned about fill rate and speed than visual quality in their basic geometry rendering. They use the Bresenham algorithm to draw lines and polygons, which does not support anti aliasing.

Opting for speed rather than visual quality is actually quite reasonable for a 3D API, since most of the visual detail eventually arises from the use of textures (which are interpolated) rather than from the geometry.

My suggestion would be to activate multi-sampling, or doing FSAA by hand using the accumulation buffer (if that's available under OpenGL ES). Or you could try to draw multiple lines with some transparency jittered around the intended coordinates.


In addition to what Fabian said, it may be that you just have to enable alpha blending for line smooth to show an effect, by calling

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜