Android Andengine 纹理质量差

发布于 2024-12-07 16:58:36 字数 829 浏览 0 评论 0原文

问题:用 Andengine(wraps opengl) 编写的 Android 应用程序中的纹理质量很差,尤其是在以几种颜色显示为步骤的渐变上。真实和虚拟设备上都会出现问题

设置:默认纹理、全屏、本机分辨率、android 2.2。 我尝试强制使用 PixelFromat:

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    Window window = getWindow();
    window.setFormat(PixelFormat.RGBA_8888);
}

没有任何区别。

评论线: GLHelper.disableDither(pGL); 对纹理有一点帮助,但使粒子看起来很糟糕,所以猜测这不是问题的根源。

加载代码示例:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沉默的熊 2024-12-14 16:58:36

如果有人遇到 GLES2 的纹理质量和条带较差的情况,这里是解决方案:
只需重写 Sprite 的 preDraw() 并启用抖动,如下所示:

Sprite electricityOff = new Sprite(0, 0, mElectricityOffTextureRegion, getVertexBufferObjectManager()) {
    @Override
    protected void preDraw(GLState pGLState, Camera pCamera) {
        super.preDraw(pGLState, pCamera);
        pGLState.enableDither();
    }
};

关键元素是 pGLState.enableDither();
不需要需要任何其他内容,但如果您想确保表面和活动的 32 位渲染,您可以添加:

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

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);
}
紫罗兰の梦幻 2024-12-14 16:58:36

Andengine 似乎使用默认的 16 位渲染模式。要更改我所做的:

this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setEGLConfigChooser(8,8,8,8,0,0);//!!
mRenderSurfaceView.setRenderer(mEngine);
mRenderSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);//!!

onSetContentView 方法中。

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.

Oo萌小芽oO 2024-12-14 16:58:36

我遇到了同样的问题,通过启用抖动解决了

EngineOptions options;
//..........
options.getRenderOptions().setDithering(true);

I had the same issue, fixed by enabling Dithering

EngineOptions options;
//..........
options.getRenderOptions().setDithering(true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文