glrender.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:DenseHumanBodyCorrespondences 作者: halimacc 项目源码 文件源码
def draw(self, vertices, colors, mvp):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glUseProgram(self.program)
        glUniformMatrix4fv(self.mvpMatrix, 1, GL_FALSE, mvp)

        glEnableVertexAttribArray(0)
        glBindBuffer(GL_ARRAY_BUFFER, self.vertexBuf)
        glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
        glVertexAttribPointer(
            0,                  # attribute
            vertices.shape[1],                  # size
            GL_FLOAT,           # type
            GL_FALSE,           # normalized?
            0,                  # stride
            None            # array buffer offset
        );

        glEnableVertexAttribArray(1)
        glBindBuffer(GL_ARRAY_BUFFER, self.colorBuf)
        glBufferData(GL_ARRAY_BUFFER, colors, GL_STATIC_DRAW);
        glVertexAttribPointer(
            1,                                # attribute
            colors.shape[1],                                # size
            GL_FLOAT,                         # type
            GL_FALSE,                         # normalized?
            0,                                # stride
            None                          # array buffer offset
        );

        glDrawArrays(GL_TRIANGLES, 0, vertices.shape[0])
        glDisableVertexAttribArray(0)
        glDisableVertexAttribArray(1)
        glUseProgram(0)
        glutSwapBuffers()

        rgb = glReadPixels(0, 0, self.width, self.height, GL_RGB, GL_UNSIGNED_BYTE, outputType=None)
        z = glReadPixels(0, 0, self.width, self.height, GL_DEPTH_COMPONENT, GL_FLOAT, outputType=None)
        rgb = np.flip(np.flip(rgb, 0), 1)
        z = np.flip(np.flip(z, 0), 1)
        return rgb, z
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号