渲染到纹理隐藏了正面,z缓冲区有问题吗?

时间:2015-03-16 18:17:25

标签: opengl libgdx opengl-es-2.0

我想将场景渲染到纹理并将模糊着色器应用于此纹理。问题是当我绘制纹理时,立方体的正面是不可见的

没有超级采样

enter image description here

使用超级采样

enter image description here

*在两张照片中忽略了立方体周围的不透明物体。我使用较少的alpha和更大的比例双重渲染立方体,我禁用了此但我遇到了同样的问题。

出于某种原因,我使用y作为z,z作为y,因此立方体的正面比背面(而不是z)的y小,我猜z-buffer有问题。

渲染到纹理代码:

public class RenderOnTexture {
    private float m_fboScaler = 1f;
    private boolean m_fboEnabled = true;
    private FrameBuffer m_fbo = null;
    private TextureRegion m_fboRegion = null;
    public RenderOnTexture(float scale) {
        int width = (int) (Gdx.graphics.getWidth()*scale);
        int height = (int) (Gdx.graphics.getHeight()*scale);
        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,false);
    }
    public void begin(){
        if(m_fboEnabled)
        {                  
            m_fbo.begin();
            Gdx.gl.glClearColor(0, 0,0,0);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        }
    }
    public TextureRegion end(){
        if(m_fbo != null)
        {
            m_fbo.end();
            return m_fboRegion;
        }  
        return null;
    }
}

1 个答案:

答案 0 :(得分:1)

FrameBuffer中的Boolean参数启用深度缓冲附件。并且深度缓冲区必须与颜色缓冲区一起清除。

相关问题