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

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

问题描述

是否可以渲染到纹理的libGdx(Java引擎为Android /台式机)使用SpriteBatch?如果是这样,怎么办呢?

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

基本上,我想要呈现的一切,以512×256的纹理320×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天全站免登陆