The problem: poor texture quality in android app written with Andengine(wraps opengl), especially on gradients which appear as steps in few colours. Problem occurs on real and virtual device
Settings: default texture, fullscreen, native resolution, android 2.2. I have tried to enforce PixelFromat with:
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
Haven't made any difference.
Commenting line:
GLHelper.disableDither(pGL);
helped a little with textures, but made particles look bad, so a guess it is not the source of problem.
Example loading code:
public stat开发者_如何学运维ic void loadResources(StreamgameActivity game) {
magnetTexture = new BitmapTextureAtlas(512, 512, TextureOptions.BILINEAR);
magnetTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromAsset(magnetTexture, game,"bateria128CMatte_none.png", 0, 0);
game.getEngine().getTextureManager().loadTexture(magnetTexture);
}
If someone is experiencing poor texture quality and banding for GLES2 here is the solution:
just override preDraw()
of your Sprite and enable dithering like this:
Sprite electricityOff = new Sprite(0, 0, mElectricityOffTextureRegion, getVertexBufferObjectManager()) {
@Override
protected void preDraw(GLState pGLState, Camera pCamera) {
super.preDraw(pGLState, pCamera);
pGLState.enableDither();
}
};
Key element is pGLState.enableDither();
.
You will not need anything else but in case you want to ensure 32bit rendering for the surface and activity you can add:
@Override
protected void onSetContentView() {
mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 24, 0);
mRenderSurfaceView.setRenderer(mEngine, this);
mRenderSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
this.setContentView(mRenderSurfaceView, BaseGameActivity.createSurfaceViewLayoutParams());
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
Andengine seems to use be default 16bit rendering mode. To change that I have done:
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setEGLConfigChooser(8,8,8,8,0,0);//!!
mRenderSurfaceView.setRenderer(mEngine);
mRenderSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);//!!
in onSetContentView
method.
I had the same issue, fixed by enabling Dithering
EngineOptions options;
//..........
options.getRenderOptions().setDithering(true);
精彩评论