def render_obj(self): logger.info(' === render === ') sc = self.scene if self.do_vbo: glEnableClientState( GL_VERTEX_ARRAY ) glEnableClientState( GL_NORMAL_ARRAY ) glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.VBO_vertex ) glVertexPointer( 3, GL_FLOAT, 0, None ) if self.do_lighting: glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.VBO_normal ) glNormalPointer( GL_FLOAT, 0, None ) glDrawArrays( GL_TRIANGLES, 0, self.vbo_array_size ) glDisableClientState( GL_VERTEX_ARRAY ) glDisableClientState( GL_NORMAL_ARRAY ) if self.do_immediate_mode: glBegin(GL_TRIANGLES) # Factorisation might be bad for performances def send_point_to_gl(p): # Order: texture, normal, points if False and p.coord_mapping: glTexCoord2f(*p.coord_mapping) if p.normal: glNormal3f(*p.normal) glVertex3f(*p) for j in xrange(len(sc.faces)): t = sc.faces[j] p1 = sc.points[t[0]] p2 = sc.points[t[1]] p3 = sc.points[t[2]] n = sc.faces_normals[j] n1 = sc.normals[n[0]] n2 = sc.normals[n[1]] n3 = sc.normals[n[2]] glNormal3f(*n1) glVertex3f(*p1) glNormal3f(*n2) glVertex3f(*p2) glNormal3f(*n3) glVertex3f(*p3) glEnd() display_normals = False if display_normals: if self.normal_dl is not None: glCallList(self.normal_dl) else: self.normal_dl = glGenLists(1) glNewList(self.normal_dl, GL_COMPILE) glBegin(GL_LINES) glColor3f(0.0, 0.0, 1.0) def draw_normal(p, n): glVertex3fv(p) N = map(lambda x, y: x + y, p, n) glVertex3fv(N) for j, t in enumerate(sc.faces): p1 = sc.points[t[0]] p2 = sc.points[t[1]] p3 = sc.points[t[2]] n1 = sc.normals[j][0] n2 = sc.normals[j][1] n3 = sc.normals[j][2] draw_normal(p1, n1) draw_normal(p2, n2) draw_normal(p3, n3) glEnd() glEndList() glCallList(self.normal_dl)
def render_obj(self): logger.info(' === render === ') sc = self.scene if self.do_vbo: glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.VBO_vertex) glVertexPointer(3, GL_FLOAT, 0, None) if self.do_lighting: glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.VBO_normal) glNormalPointer(GL_FLOAT, 0, None) glDrawArrays(GL_TRIANGLES, 0, self.vbo_array_size) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_NORMAL_ARRAY) if self.do_immediate_mode: glBegin(GL_TRIANGLES) # Factorisation might be bad for performances def send_point_to_gl(p): # Order: texture, normal, points if False and p.coord_mapping: glTexCoord2f(*p.coord_mapping) if p.normal: glNormal3f(*p.normal) glVertex3f(*p) for j in xrange(len(sc.faces)): t = sc.faces[j] p1 = sc.points[t[0]] p2 = sc.points[t[1]] p3 = sc.points[t[2]] n = sc.faces_normals[j] n1 = sc.normals[n[0]] n2 = sc.normals[n[1]] n3 = sc.normals[n[2]] glNormal3f(*n1) glVertex3f(*p1) glNormal3f(*n2) glVertex3f(*p2) glNormal3f(*n3) glVertex3f(*p3) glEnd() display_normals = False if display_normals: if self.normal_dl is not None: glCallList(self.normal_dl) else: self.normal_dl = glGenLists(1) glNewList(self.normal_dl, GL_COMPILE) glBegin(GL_LINES) glColor3f(0.0, 0.0, 1.0) def draw_normal(p, n): glVertex3fv(p) N = map(lambda x, y: x + y, p, n) glVertex3fv(N) for j, t in enumerate(sc.faces): p1 = sc.points[t[0]] p2 = sc.points[t[1]] p3 = sc.points[t[2]] n1 = sc.normals[j][0] n2 = sc.normals[j][1] n3 = sc.normals[j][2] draw_normal(p1, n1) draw_normal(p2, n2) draw_normal(p3, n3) glEnd() glEndList() glCallList(self.normal_dl)
def setup_vbo(self): glInitVertexBufferObjectARB() self.VBO_vertex = int(glGenBuffersARB(1)) # Get A Valid Name self.VBO_normal = int(glGenBuffersARB(1)) # Get A Valid Name # Load The Data sc = self.scene self.vbo_array_size = len(sc.faces) * 3 vertices = Numeric.zeros ( (self.vbo_array_size, 3), 'f') if self.do_lighting: normals = Numeric.zeros ( (self.vbo_array_size, 3), 'f') if not sc.normals: print 'compute normals' from geom_ops import compute_normals sc.normals, sc.faces_normals = compute_normals(sc) i = 0 for j in xrange(len(sc.faces)): t = sc.faces[j] p1 = sc.points[t[0]] p2 = sc.points[t[1]] p3 = sc.points[t[2]] vertices [i, 0] = p1[0] vertices [i, 1] = p1[1] vertices [i, 2] = p1[2] vertices [i+1, 0] = p2[0] vertices [i+1, 1] = p2[1] vertices [i+1, 2] = p2[2] vertices [i+2, 0] = p3[0] vertices [i+2, 1] = p3[1] vertices [i+2, 2] = p3[2] # print p1, p2, p3 if self.do_lighting: n = sc.faces_normals[j] n1 = sc.normals[n[0]] n2 = sc.normals[n[1]] n3 = sc.normals[n[2]] normals [i, 0] = n1[0] normals [i, 1] = n1[1] normals [i, 2] = n1[2] normals [i+1, 0] = n2[0] normals [i+1, 1] = n2[1] normals [i+1, 2] = n2[2] normals [i+2, 0] = n3[0] normals [i+2, 1] = n3[1] normals [i+2, 2] = n3[2] i += 3 glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.VBO_vertex ) glBufferDataARB( GL_ARRAY_BUFFER_ARB, vertices, GL_STATIC_DRAW_ARB ); if self.do_lighting: glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.VBO_normal ) glBufferDataARB( GL_ARRAY_BUFFER_ARB, normals, GL_STATIC_DRAW_ARB ); if self.gpu_info: print glGetString (GL_VENDOR) print glGetString (GL_RENDERER) print glGetString (GL_VERSION) Extensions = glGetString (GL_EXTENSIONS) for ext in Extensions.split(): print ext return self.VBO_vertex, self.VBO_normal
def setup_vbo(self): glInitVertexBufferObjectARB() self.VBO_vertex = int(glGenBuffersARB(1)) # Get A Valid Name self.VBO_normal = int(glGenBuffersARB(1)) # Get A Valid Name # Load The Data sc = self.scene self.vbo_array_size = len(sc.faces) * 3 vertices = Numeric.zeros((self.vbo_array_size, 3), 'f') if self.do_lighting: normals = Numeric.zeros((self.vbo_array_size, 3), 'f') if not sc.normals: print 'compute normals' from geom_ops import compute_normals sc.normals, sc.faces_normals = compute_normals(sc) i = 0 for j in xrange(len(sc.faces)): t = sc.faces[j] p1 = sc.points[t[0]] p2 = sc.points[t[1]] p3 = sc.points[t[2]] vertices[i, 0] = p1[0] vertices[i, 1] = p1[1] vertices[i, 2] = p1[2] vertices[i + 1, 0] = p2[0] vertices[i + 1, 1] = p2[1] vertices[i + 1, 2] = p2[2] vertices[i + 2, 0] = p3[0] vertices[i + 2, 1] = p3[1] vertices[i + 2, 2] = p3[2] # print p1, p2, p3 if self.do_lighting: n = sc.faces_normals[j] n1 = sc.normals[n[0]] n2 = sc.normals[n[1]] n3 = sc.normals[n[2]] normals[i, 0] = n1[0] normals[i, 1] = n1[1] normals[i, 2] = n1[2] normals[i + 1, 0] = n2[0] normals[i + 1, 1] = n2[1] normals[i + 1, 2] = n2[2] normals[i + 2, 0] = n3[0] normals[i + 2, 1] = n3[1] normals[i + 2, 2] = n3[2] i += 3 glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.VBO_vertex) glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertices, GL_STATIC_DRAW_ARB) if self.do_lighting: glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.VBO_normal) glBufferDataARB(GL_ARRAY_BUFFER_ARB, normals, GL_STATIC_DRAW_ARB) if self.gpu_info: print glGetString(GL_VENDOR) print glGetString(GL_RENDERER) print glGetString(GL_VERSION) Extensions = glGetString(GL_EXTENSIONS) for ext in Extensions.split(): print ext return self.VBO_vertex, self.VBO_normal