Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opengl Libgdx中的帧缓冲区,使用glclearcolor()清除整个屏幕_Opengl_Libgdx_Framebuffer - Fatal编程技术网

Opengl Libgdx中的帧缓冲区,使用glclearcolor()清除整个屏幕

Opengl Libgdx中的帧缓冲区,使用glclearcolor()清除整个屏幕,opengl,libgdx,framebuffer,Opengl,Libgdx,Framebuffer,我在framebuffer中使用glClearColor内部begin()和end(), 但它正在清除整个屏幕的颜色,我做错了什么吗 public class FrameBufferTest implements ApplicationListener{ OrthographicCamera camera; SpriteBatch batcher; FrameBuffer fbo; Texture tex; @Override public vo

我在
framebuffer
中使用
glClearColor
内部
begin()
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();
    }

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

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

按照您拥有它们的顺序,它将使用最近设置的“清除颜色”(clear color)清除颜色,这是您在渲染方法中较低位置设置的红色(因为这是一个循环)。

有没有任何方法可以在不使用网格或形状渲染器的情况下使用帧缓冲区的颜色。这不是您已经做过的吗?您使帧缓冲区变为红色。