Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anti-aliasing filled shapes in libgdx

I've been looking everywhere for a way to anti-alias edges of filled shapes drawn with ShapeRenderer (ie. ShapeType.Filled) but can't find anything about this.

Lines works well with Gdx.gl.glEnable(GL10.GL_LINE_SMOOTH) but nothing I've tried works with filled shapes. So, does anyone have any suggestions?

like image 718
fredrol Avatar asked Aug 12 '13 11:08

fredrol


2 Answers

maybe this link will help: MULTI SAMPLING ANTI-ALASING IN LIBGDX ON ANDROID

in general you have to enable multisampling to have edges of filled shapes smooth.

http://www.opengl.org/wiki/Multisampling

like image 172
fen Avatar answered Sep 20 '22 00:09

fen


I've found the anti-aliasing support in OpenGL to be lacking (as actual support depends on optional hardware support), especially for the basic polygon primitives. There are two solutions that I've found to work:

First, you can get reasonable multi-sampling when using textures. So, maybe render your polygon to a FrameBuffer object, and then copy that to the screen. There are still a bunch of caveats, see http://www.saschahlusiak.de/2012/10/opengl-antialiasing-in-android-with-transparent-textures/ for more details.

Second, render your filled shape with a shader that anti-aliases, as in this question: Drawing Antialiased circle using Shaders. If your filled primitive shape is complicated, this can be quite a bit of work. See https://code.google.com/p/libgdx/wiki/OpenGLShader for how to use a shader with Libgdx. This option only works with OpenGL ES 2.0, too.

like image 37
P.T. Avatar answered Sep 18 '22 00:09

P.T.