Reputation: 1
I want to get depth buffer images that have been captured from different views of a 3D object. To do this with pyOpenGL
I use the following code
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()
code link: https://www.linux.com/blog/python-stl-model-loading-and-display-opengl
I call this function with different viewpoints LookAt_x
, LookAt_y
, LookAt_z
. However, to draw the object every time costs too much time.
Is there a possible way, once the object is drawn, just change viewpoints to get depth images?
Upvotes: 0
Views: 289