Antialiased lines

Monkey Forums/Monkey Programming/Antialiased lines

JIM(Posted 2011) [#1]
Hi!

Is there any way to enable AntiAliased lines in GLFW/Android/iOS?

My game wouldn't suffer performance-wise from this and I'd much rather have it on to keep the graphics smooth. The game looks great in HTML5 where the lines are antialiased, but suffers from slightly annoying artifacts on the other targets.


Chaduke(Posted 2011) [#2]
I tried a few tests with GLFW and iOS. I was able to get smooth lines with GLFW by opening main.cpp in the build folder, and adding the following lines to the DrawLine function:

glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);


I put them right before the two AddVertex calls. I'm not an expert with OpenGL so I couldn't tell how it would impact your game, but it worked with a simple example drawing a few default white lines on a black background.

As far as iOS goes, it seems that hardware AA is not supported, but there are a number of articles on how to get it working with different methods. I may spend some time researching this because it does seem to make a nice difference on the examples I saw.


JIM(Posted 2011) [#3]
Wow, I can't believe I haven't tried that. I was too sleepy it seems. I opened the file and when I saw those "AddVertex" I thought GL calls wouldn't work :)

Thanks!

Also, having a freshly woken up brain, I think I might be able to hack an antialiased line by drawing a textured quad with alpha instead of a line, and let the filtering do its job. It's most likely to be slower, so if it works, I'll just use it where AA is a pain (like you said iOS might be).


Chaduke(Posted 2011) [#4]
Here's the link in the Apple developer docs, there's a part in there on how to enable multisampling on iOS:

http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/WorkingwithEAGLContexts/WorkingwithEAGLContexts.html

Apparently you have to setup a second framebuffer, draw all your pixels to it including a number of samples per pixel, then transfer that to an identical sized buffer that "resolves" the samples.

I haven't looked closely yet at the rendering code Monkey creates for iOS. Seems like it could potentially be a bit of work. There's probably a good reason why it wasn't added as an option.


JIM(Posted 2011) [#5]
Well, I ran a test with using an image instead of a line. Turns out it works like a charm :)

It should be slower, but my game still runs smooth with it.
Since other means seem to be complicated, I think I'll just use this technique on all targets except HTML5.

I posted the code if anyone is interested: http://monkeycoder.co.nz/Community/posts.php?topic=987