pyOpenGL每次调用glReadPixels时都需要绘制一个对象吗?

时间:2017-11-09 14:25:24

标签: opengl 3d depth pyopengl glulookat

我想获取从3D对象的不同视图捕获的深度缓冲图像。要使用pyOpenGL执行此操作,请使用以下代码

def get_depth(LookAt_x, LookAt_y, LookAt_z)

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    gluLookAt(LookAt_x, LookAt_y, LookAt_z, 0, 0, 0, 0, 1, 0)
    draw_object() // glBegin() for ... glvertex3f........ glEnd()
    glReadBuffer(GL_FRONT)
    depth_image = glReadPixels(0, 0, image_size, image_size, GL_DEPTH_COMPONENT, GL_FLOAT)

def draw_object(self):
    glBegin(GL_TRIANGLES)
    for tri in self.get_triangles():
        glNormal3f(tri.normal.x,tri.normal.y,tri.normal.z)
        glVertex3f(tri.points[0].x,tri.points[0].y,tri.points[0].z)
        glVertex3f(tri.points[1].x,tri.points[1].y,tri.points[1].z)
        glVertex3f(tri.points[2].x,tri.points[2].y,tri.points[2].z)
    glEnd()

代码链接:https://www.linux.com/blog/python-stl-model-loading-and-display-opengl

我使用不同的视点LookAt_xLookAt_yLookAt_z调用此函数。但是,每次绘制对象都需要花费太多时间。

有可能的方法,一旦绘制了对象,只需更改视点以获得深度图像吗?

0 个答案:

没有答案