绘制到纹理上时,帧缓冲区对象渲染为空白

问题描述 投票:0回答:0

我正在尝试将阴影贴图渲染到我的 FBO 中。就像问题指出将缓冲区绘制到纹理会导致它变成白色一样。

这是我创建和绑定 FBO 的方法:

    @staticmethod
    def __bind_frame_buffer(frame_buffer: int, width: int, height: int) -> None:
        """
        Binds the frame buffer as the current render target.
        :param frame_buffer: the frame buffer.
        :param width: the width of the frame buffer.
        :param height: the height of the frame buffer.
        :return:
        """
        glBindTexture(GL_TEXTURE_2D, 0)
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frame_buffer)
        glViewport(0, 0, width, height)

    @staticmethod
    def __create_frame_buffer() -> int:
        """
        Creates a frame buffer and binds it so that attachments can be added to
        it. The draw buffer is set to none, indicating that there's no colour
        buffer to be rendered to.
        :return: The newly created frame buffer's ID.
        """
        frame_buffer = glGenFramebuffers(1)
        glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer)
        glDrawBuffer(GL_NONE)
        glReadBuffer(GL_NONE)
        return frame_buffer

这是我创建深度缓冲区附件的方法:

    @staticmethod
    def __create_depth_buffer_attachment(width: int, height: int) -> int:
        """
        Creates a depth buffer texture attachment.
        :param width: the width of the texture.
        :param height: the height of the texture.
        :return: The ID of the depth texture.
        """
        texture = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D, texture)

        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, None)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
        glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texture, 0)
        return texture

我发现这个问题,答案不是很有帮助,因为我的函数中已经有那段代码了。

检查 FBO 的状态 返回其已完成。

注释掉渲染循环中的

bind_frame_buffer
调用会导致纹理变黑。我会假设某些东西正在被传递,但根本不是我所期望的。

据我所知,模型-视图-投影矩阵中的计算是正确的,但如果需要,我可以添加这些。

哪些假设的事情可能会破坏我的代码?我见过有人说 Mipmapping 可能会破坏它,但删除它(将其级别设置为 0)也无法解决问题。

python opengl pyopengl
© www.soinside.com 2019 - 2024. All rights reserved.