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 edges are severely jagged in Android Emulator. What is the solution?
http://code.google.com/p/gdc2011-android-opengl/ has sample code for multisampling.
Well the best way is to use Multisampling ( Antialiasing ). Since you use the emulator this is not an option for you. ( Multismapling supported in OpenGL ES 2.0 but the emulator does not support 2.0 ) According to the OpenGL specification, the device can ignore the glHint you set, so don't expect to much from it. The GL_DITHER is a way to 'fake' 24bit color depth from 16bit color depth basically it has nothing to do with the edges.
Altho there is an old method to 'fake' antialiasing, its a same that I never used so I cant tell you how, but you can find some hints on the web.
From OpenGL docs
Blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) is also useful for rendering antialiased points and lines in arbitrary order.
Polygon antialiasing is optimized using blend function (GL_SRC_ALPHA_SATURATE, GL_ONE) with polygons sorted from nearest to farthest.
You are turning on polygon smoothing using a "hint". A hint is just that a "hint" to the implementation that you want the polygon edges smoothed. The implementation is free to ignore it if it wants.
This is exactly what it is doing.
Furthermore it is highly likely that you simply can't turn on anti-aliasing on android devices because they are just not powerful enough to do it. This may be different between handsets but, again, you are setting a hint.
I just went through the same issues as you. I think what you're looking for is the following line of code:
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With