andengine 纹理质量问题

问题:

 

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 static 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);
}

解决方法:
方法一:

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.

方法二:

if someone is experiencing poor texture quality and banding for GLES2 here is the solution: just overridepreDraw() 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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值