LibGDX - 绘制到FrameBuffer不起作用 [英] LibGDX - Drawing to a FrameBuffer does not work

查看:300
本文介绍了LibGDX - 绘制到FrameBuffer不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试制作自定义按钮,我需要将按钮背景的不同部分组合在一起。要做到这一点,我认为使用FrameBuffer会起作用,但它没有给出可行的结果。因此,我尝试通过编写一个简单的测试方法来测试我的FrameBuffer绘图方法,该方法返回在每次render()调用时绘制到显示的纹理。这个方法在这里(请注意,它是一种测试方法,因此可能稍微优化一下):

So I'm trying to make custom buttons, for which I need to combine different parts of the button background. To do this I figured using a FrameBuffer would work, however it did not give viable results. Therefore I attempted to test my FrameBuffer drawing method, by writing a simple test method, which returns a texture that is drawn to the display at every render() call. This method is here (note that it is a test method, so it may be a little poorly optimized):

    private Texture test()
{
    BitmapFont f = ReverseBlade.fontTitle;
    f.setColor(Color.LIGHT_GRAY);

    FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, (int)f.getBounds("Hi").width, (int)f.getBounds("Hi").height, false);
    Batch b = ReverseBlade.batch;
    OrthographicCamera c = new OrthographicCamera(fbo.getWidth(), fbo.getHeight());

    c.setToOrtho(false);
    c.update();
    b.setProjectionMatrix(c.combined);

    fbo.begin();
    b.begin();

    f.draw(b, "Hi", 0, 0);

    b.end();
    fbo.end();

    Texture t = fbo.getColorBufferTexture();

    fbo.dispose();

    b.setProjectionMatrix(ReverseBlade.camera.combined);

    return t;
}

但是,不会显示任何内容。屏幕很暗......我试过没有相机和我不能再记得的其他多种变化。我做错了什么?

However, nothing is displayed. The screen is dark... I have tried without the camera and multiple other variations that I can no longer remember. What am I doing wrong?

半解决方案
我最不得不做的是为一个新的Matrix4对象FrameBuffer是这样的:

Half Solution What I ended up having to do is to make a new Matrix4 object for the FrameBuffer like this:

Matrix4 m = new Matrix4();
m.setToOrtho2D(0, 0, fbo.getWidth(), fbo.getHeight());
batch.setProjectionMatrix(m);

然而,这使得绘制的所有内容都颠倒过来,如下所示:

However, this makes everything that is drawn be upside down, like this:

推荐答案

因此,按照我在Half Solution中添加的内容,我所要做的就是使用FBo中的纹理创建一个新的Sprite对象并调用flip(false,true)!

So following what I added with the Half Solution, all I had to do was create a new Sprite object with the texture from the FBo and call flip(false, true)!

这篇关于LibGDX - 绘制到FrameBuffer不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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