libgdx中帧缓冲区的结果不明确 [英] Ambiguous results with Frame Buffers in libgdx

查看:79
本文介绍了libgdx中帧缓冲区的结果不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

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

Here is the code that is producing this result:

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

为什么帧缓冲区的宽度和高度与图像的宽度和高度相同(71 x 72),所以我让画在帧缓冲区上的心发生翻转并且比原始的帧小.

Why is it that I am getting the heart that I drew on the frame buffer to get flipped and be smaller than the original one though the frame buffer width and height are the same as that of the image (71 x 72).

推荐答案

要解决此问题,帧缓冲区的宽度和高度必须等于舞台的宽度和高度,如下所示:

To solve this, the frame buffer has to have a width and height equal to that of stage, like this:

fbo = new FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);

这篇关于libgdx中帧缓冲区的结果不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆