How to get rid of Jagged edges in Android OpenGL ES?

I have the following code:

public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); gl.glShadeModel(GL10.GL_SMOOTH); gl.glClearDepthf(1.0f); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glDepthFunc(GL10.GL_LEQUAL); //gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST); } public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); 

But still, the ribs are very jagged in Android Emulator. What is the solution?

+4
source share
5 answers

Well, the best way is to use multisampling (smoothing). Since you are using an emulator, this is not an option for you. (Multismapling is supported in OpenGL ES 2.0, but the emulator does not support 2.0) According to the OpenGL specification, the device may ignore the glHint you installed, so do not expect much from it. GL_DITHER is a way to "fake" 24-bit color depths from 16-bit color depths, basically it has nothing to do with edges.

Altho there is an old method of "fake" anti-aliasing, it is the same that I never used, so I can not tell you how to do this, but you can find some tips on the Internet.

From OpenGL Docs

The blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) is also useful for rendering smooth points and lines in random order.

Polygon smoothing is optimized using the blend function (GL_SRC_ALPHA_SATURATE, GL_ONE) with polygons sorted from nearest to farthest.

+4
source

http://code.google.com/p/gdc2011-android-opengl/ contains sample code for multisampling.

+11
source

You enable polygon anti-aliasing using the β€œtooltip”. A tooltip is just a β€œhint” of an implementation in which you want the edges of the polygon to be smoothed. An implementation may ignore her if she wants to.

This is exactly what he does.

In addition, it is very likely that you simply cannot enable anti-aliasing on Android devices because they are simply not powerful enough to do this. This may be different between the handsets, but, again, you set the prompt.

+1
source

I just went through the same problems as you. I think you are looking for the following line of code:

 gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 
+1
source
  • Try the device. I do not trust the emulator for problems with the visual / graphical interface.
  • Try gl.glEnable(GL10.GL_DITHER); . I am not sure if it is enabled by default. In addition: it makes drawing slower.
0
source

Source: https://habr.com/ru/post/1338867/


All Articles