8

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?

fredrol
  • 109
  • 3
  • 7

3 Answers3

7

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

fen
  • 9,835
  • 5
  • 34
  • 57
  • 4
    This is way lower level than you should need to go if you're using libGDX. They've gone out of their way to abstract away all this stuff. Why reinvent the wheel here? – Scuba Steve Jan 02 '14 at 06:24
3

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.

Community
  • 1
  • 1
P.T.
  • 24,557
  • 7
  • 64
  • 95
3

Have you tried following hints?

Gdx.gl.glEnable(GL10.GL_LINE_SMOOTH);
Gdx.gl.glEnable(GL10.GL_POINT_SMOOTH);
Gdx.gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);
Gdx.gl.glHint(GL10.GL_POINT_SMOOTH_HINT, GL10.GL_NICEST);
Wizche
  • 893
  • 13
  • 32
  • 1
    Unfortunately, the constants you mentioned don't seem to be in the latest version of libGDX. https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/GL20.java – Travis May 25 '14 at 03:46
  • Yep, they are only available if you use OpenGL ES 1.0, not 2.0 – Wizche May 25 '14 at 12:36