【问题标题】:Framebuffer in Libgdx, using glclearcolor() clears whole screenLibgdx 中的帧缓冲区,使用 glclearcolor() 清除整个屏幕
【发布时间】:2015-03-24 09:55:30
【问题描述】:

我在begin()中使用glClearColor,在framebuffer中使用end(), 但它正在清除整个屏幕颜色,我做错了吗?

public class FrameBufferTest implements ApplicationListener{

    OrthographicCamera camera;
    SpriteBatch batcher;
    FrameBuffer fbo;
    Texture tex;
    @Override
    public void create() {
        batcher = new SpriteBatch();

        camera = new OrthographicCamera(800, 480);
        camera.position.set(camera.viewportWidth/2f, camera.viewportHeight/2f, 0);

        fbo = new FrameBuffer(Format.RGBA8888, 100, 100,false);

        camera.position.set(camera.viewportWidth/2f, camera.viewportHeight/2f, 0);
        tex = new Texture("data/bg.png");
    }

    @Override
    public void render() {
        GL20 gl = Gdx.graphics.getGL20();
        gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        gl.glClearColor(0.5f,0.5f,0.5f,0.5f); // grey color

        camera.update();
        batcher.setProjectionMatrix(camera.combined);

        batcher.enableBlending();
        batcher.begin();
            batcher.draw(tex, 0, 0, 256, 256);
        batcher.end();

        fbo.begin();
            gl.glClearColor(1f,0,0,1f);
            gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        fbo.end();

        batcher.begin();
            batcher.draw(fbo.getColorBufferTexture(), 512, 0, 100, 100);
        batcher.end();
    }

【问题讨论】:

    标签: opengl libgdx framebuffer


    【解决方案1】:

    在渲染方法的开头交换这两行:

    gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    gl.glClearColor(0.5f,0.5f,0.5f,0.5f); // grey color
    

    按照您拥有它们的顺序,它使用最近设置的清除颜色清除颜色,这是您在渲染方法中设置得更远的红色(因为这是一个循环)。

    【讨论】:

    • 有什么方法可以使用帧缓冲区的颜色,而不使用网格或 shape_renderer。
    • 这不是你已经做过的吗?您将帧缓冲区设置为红色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    相关资源
    最近更新 更多