libgdx中帧缓冲区的结果不明确

Raf*_*fay 2 opengl fbo opengl-es framebuffer libgdx

我在libgdx中使用FrameBuffer类得到以下奇怪的结果.

在此输入图像描述

以下是产生此结果的代码:

// This is the rendering code
@Override
public void render(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    stage.act();
    stage.draw();

    fbo.begin();
    batch.begin();
    batch.draw(heart, 0, 0);
    batch.end();
    fbo.end();  

    test = new Image(fbo.getColorBufferTexture());
    test.setPosition(256, 256);
    stage.addActor(test);
}

//This is the initialization code
@Override
public void show() {
    stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    atlas = Assets.getAtlas();
    batch = new SpriteBatch();

    background = new Image(atlas.findRegion("background"));     
    background.setFillParent(true); 
    heart = atlas.findRegion("fluttering");
    fbo = new FrameBuffer(Pixmap.Format.RGBA8888, heart.getRegionWidth(), heart.getRegionHeight(), false);

    stage.addActor(background);
    Image temp = new Image(new TextureRegion(heart));
    stage.addActor(temp);
}
Run Code Online (Sandbox Code Playgroud)

为什么说我得到我的帧缓冲提请心脏得到翻转,并比原来的小,虽然帧缓冲区的宽度和高度都是相同的图像(71 X 72)的.

Daa*_*ren 6

您的SpriteBatch使用了错误的投影矩阵.由于您要渲染到自定义大小的FrameBuffer,因此您必须手动设置一个.

projectionMatrix = new Matrix4();
projectionMatrix.setToOrtho2D(0, 0, heart.getRegionWidth(), heart.getRegionHeight());
batch.setProjectionMatrix(projectionMatrix);
Run Code Online (Sandbox Code Playgroud)