Search code examples
androidopengl-esantialiasingmultisampling

Issue with Android OpenGL Multisampling/Antialiasing


I'm working on an app for Android allows the user to tap the screen to draw colors. I've got all of the drawing code working nicely under OpenGL (testing on Android 4.0.4, Galaxy Nexus, though I'm trying to make this backward compatible as far as possible; my SDK targets API 14 but has a minSDK of 8).

The issue I've run into is with antialiasing; I want all my polygons and lines to be antialiased, but they're coming out jagged. I'm positive the Galaxy Nexus supports antialiasing (I've seen it in other apps), so I'm sure I'm doing something wrong.

I've been up and down Google for over an hour now, and through several StackOverflow Q/As, and I've found a few answers:

gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_ALPHA_BITS);
gl.glEnable(GL10.GL_MULTISAMPLE);
gl.glEnable(GL10.GL_SMOOTH);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);
gl.glHint(GL10.GL_POINT_SMOOTH_HINT, GL10.GL_NICEST);

I've added some or all of these lines in various orders, and to no effect. (These were added in onSurfaceCreated.)

gl.glEnable(GL10.GL_DITHER);

I think this one helped slightly... but that might be my mind playing tricks on me. Even when using it, though, there are still jagged lines to be found. (Also added in onSurfaceCreated.)

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

This one seems to be the most common answer. But when doing this, everything is drawn invisible; that is, when starting with a black background, everything is just black, always. (I know it's still being drawn due to the memory flushing messages in LogCat.) I've also tried this in combination with all the other methods above. (And this was added in onSurfaceCreated, as well.)

To recap: I'm using OpenGL on Android 4+ and no multisampling methods appear to be working; while most just have no effect, using glBlendFunc seems to break the rendering entirely.

So, I'm quite stumped. I'm open to any suggestions at all... they will surely help more than defenestrating my computer!

Thanks in advance to everyone patient enough to read this.


Solution

  • If you have not requested multisampling on EGL context, you can not turn it on with just the GL functions. See here how to do that: