什么可能导致只有一半的纹理在Android游戏中绘制?

时间:2015-01-07 12:17:11

标签: android opengl-es libgdx opengl-es-2.0 framebuffer

我已经收到了几位用户的报告(来自85000次下载),问题如下图所示。毫无疑问,它已经发生了几次,但它确实很少见。

我无法重现问题,并且不相信它是特定于设备的,因为有些用户似乎在报告问题的相同设备型号上完全愉快地玩游戏。

首先将字母绘制到帧缓冲区上,以便从圆形背景中构建它们,并在顶部绘制字符。然后复制它们并创建一个新纹理。

背景也是从帧缓冲区中的多个组件放在一起并被复制以创建纹理,所以我不太清楚为什么当字母没有时它看起来效果很好。使用相同的FrameBuffer和相同的SpriteBatch实例绘制背景。

它看起来像什么

Incorrect

应该是什么样子

Correct

创建图片的方法

private static Texture getTextureUsingGpu(String letter, Bubble.BubbleType bubbleType) {
    if (!enabled)
        return null;

    StrokeFontHelper font = Assets.strokeFont;
    font.setSettings(Fonts.BUBBLE_TEXT_SETTINGS);

    TextureRegion tx = getBlockImage(letter, bubbleType);
    FrameBuffer fb = TextureLoader.getFrameBuffer();
    fb.begin();

    Gdx.gl20.glClearColor(0.0f, 0.0f, 0.0f, 1);
    // Make sure everything is really really clear! Trying to fix graphics glitches on some phones
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | GL20.GL_STENCIL_BUFFER_BIT | GL20.GL_SUBPIXEL_BITS);

    float width = tx.getRegionWidth();
    float height = tx.getRegionHeight();

    TextureLoader.sb.begin();

    tx.flip(false, !tx.isFlipY());

    TextureLoader.sb.disableBlending();
    TextureLoader.sb.draw(tx, 0, 0);
    TextureLoader.sb.enableBlending();

    // Removed character drawing code to make it more readable

    TextureLoader.sb.end();

    Pixmap pm = ScreenUtils.getFrameBufferPixmap(0, 0, (int) width,
            (int) height);

    PixmapTextureData data = new PixmapTextureData(pm, Format.RGBA8888,
            false, false, true);
    Texture result = new Texture(data);
    result.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    cacheTexture(letter, result, pm);

    fb.end();
    return result;
}

public static FrameBuffer getFrameBuffer() {
    if (frameBuffer == null || frameBuffer.getWidth() != Gdx.graphics.getWidth() || frameBuffer.getHeight() != Gdx.graphics.getHeight()) {
        if (frameBuffer != null)
            frameBuffer.dispose();
        // Create the highest quality frame buffer we can get away with

        try {
            frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
        } catch (Exception e) {
            try {
                frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
            } catch (Exception e2) {
                frameBuffer = new FrameBuffer(Pixmap.Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
            }
        }

        // Set up the camera correctly for the frame buffer
        camera = new OrthographicCamera(frameBuffer.getWidth(), frameBuffer.getHeight());
        camera.position.set(frameBuffer.getWidth() * 0.5f, frameBuffer.getHeight() * 0.5f, 0);
        camera.update();
        sb.setProjectionMatrix(camera.combined);
    }

    return frameBuffer;
}

修改 我已经做了一些摆弄这个并且有一个非常有帮助的用户,他一直在为我测试版本。这就是我建立的。 如果我使用ShapeRenderer而不是SpriteBatch,那么我可以按预期绘制整个区域。 几乎可以肯定的是,我使用SpriteBatch将纹理绘制到FrameBuffer,以解决问题。它只是没有绘制到纹理的下半部分。将FreameBuffer上的内容正确复制到像素图中。

另一个编辑我有一个用户报告的新视觉故障。我不知道这是否会对问题有所了解。

enter image description here

0 个答案:

没有答案