OpenGL帧缓冲深度不起作用

时间:2016-03-25 07:08:26

标签: java opengl lwjgl opengl-3

当我只使用后缓冲区时,这可以正常工作,但是当我使用帧缓冲区时,对象不会以大于1的距离渲染(在视图空间中)。这是使用OpenGL 3.2上下文。

    colorTextureID = GL11.glGenTextures();
    depthTexutreID = GL11.glGenTextures();
    frameBufferID = GL30.glGenFramebuffers();

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTextureID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthTexutreID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT32, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTextureID, 0);
    GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexutreID, 0);

    if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE)
        throw new RuntimeException("Frame buffer is not complete");

    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

1 个答案:

答案 0 :(得分:-1)

这与帧缓冲区无关我忘记设置模型并在渲染帧缓冲区时将矩阵视为标识。