libgdx SpriteBatch 渲染到纹理 [英] libgdx SpriteBatch render to texture

查看:25
本文介绍了libgdx SpriteBatch 渲染到纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 libGdx(Android/Desktop 的 Java 引擎)中使用 SpriteBatch 渲染到纹理?如果有,怎么做?

Is it possible to render to texture using SpriteBatch in libGdx (Java engine for Android/Desktop)? If so, how do it?

基本上,我想将所有内容渲染到 512 x 256 纹理的 320 x 240 区域,然后缩放区域以适应屏幕(在横向模式下).通过这种方式,我想消除在独立缩放 Alpha 混合纹理时发生的伪影.如果有任何其他方法可以删除此类工件,请指出:)

Basically I want to render everything to 320 x 240 region of 512 x 256 texture and than scale region to fit screen (in landscape mode). This way I want to eliminate artifacts which happen when I scale alpha blended textures independently. If there is any other way to remove such artifacts, please point them out :)

有没有关于 libGdx 的在线文档?

And is there any online documentation for libGdx?

推荐答案

这个片段是在 LibGDX 论坛上给我的,它完美地工作.

This snippet was given to me on the LibGDX forum and it works flawlessly.

private float m_fboScaler = 1.5f;
private boolean m_fboEnabled = true;
private FrameBuffer m_fbo = null;
private TextureRegion m_fboRegion = null;

public void render(SpriteBatch spriteBatch)
{
    int width = Gdx.graphics.getWidth();
    int height = Gdx.graphics.getHeight();

    if(m_fboEnabled)      // enable or disable the supersampling
    {                  
        if(m_fbo == null)
        {
            // m_fboScaler increase or decrease the antialiasing quality

            m_fbo = new FrameBuffer(Format.RGB565, (int)(width * m_fboScaler), (int)(height * m_fboScaler), false);
            m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
            m_fboRegion.flip(false, true);
        }

        m_fbo.begin();
    }

    // this is the main render function
    my_render_impl();

    if(m_fbo != null)
    {
        m_fbo.end();

        spriteBatch.begin();         
        spriteBatch.draw(m_fboRegion, 0, 0, width, height);               
        spriteBatch.end();
    }   
}

这篇关于libgdx SpriteBatch 渲染到纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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