def draw_model(self, model): # gl.glLoadIdentity() gl.glPushMatrix() # sets the color gl.glColor4f(*model.color) # sets the position gl.glTranslatef(model.x - self.cx, model.y - self.cy, model.z - self.cz) # sets the rotation gl.glRotatef(model.rx, 1, 0, 0) gl.glRotatef(model.ry, 0, 1, 0) gl.glRotatef(model.rz, 0, 0, 1) # sets the scale gl.glScalef(model.scale, model.scale, model.scale) # draws the quads pyglet.graphics.draw_indexed(len(model.vertices) // 3, gl.GL_QUADS, model.quad_indices, ('v3f', model.vertices)) # draws the triangles pyglet.graphics.draw_indexed(len(model.vertices) // 3, gl.GL_TRIANGLES, model.triangle_indices, ('v3f', model.vertices)) gl.glPopMatrix()
def modelview(self): gl.glPushMatrix() try: gl.glMatrixMode(gl.GL_MODELVIEW) x, y = self.pos - self.ss gl.glTranslatef(-x, -y, 0) yield finally: gl.glPopMatrix()
def draw(self): gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glLoadIdentity() gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() gl.glOrtho(0, self.window.width, 0, self.window.height, -1, 1) self.batch.draw() for label_id, label in self.labels.items(): if label['visible']: label['label'].raw_draw() gl.glPopMatrix() gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPopMatrix()
def draw_ground_plane(self): size = 100 gl.glPushMatrix() gl.glColor3f(1, 1, 1) # no textures drawn without this for some reason gl.glEnable(gl.GL_TEXTURE_2D) gl.glBindTexture(gl.GL_TEXTURE_2D, self.tex.id) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) # you need two gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) # I don't know why! pos = ('v3f', (-size, -self.cy, -size, size, -self.cy, -size, size, -self.cy, size, -size, -self.cy, size)) tex_coords = ('t2f', (0, 0, 1, 0, 1, 1, 0, 1)) vlist = pyglet.graphics.vertex_list(4, pos, tex_coords) vlist.draw(gl.GL_QUADS) gl.glDisable(gl.GL_TEXTURE_2D) gl.glPopMatrix()
def draw(self): self.moneylabel.document.text = 'Money: $%d' % self.money self.weightlabel.document.text = 'Weight: %dkg' % self.squid.total_weight() cap = self.squid.fuel_capacity() if cap: self.fuellabel.document.text = 'Fuel Capacity: %dkg' % cap else: self.fuellabel.document.text = 'Fuel Capacity: -' tr = v(SCREEN_SIZE) pos = tr - self.tile_size - v(10, 10) gl.glPushMatrix() gl.glTranslatef(pos.x, pos.y + self.scroll, 0) for item in self.items: item.draw() gl.glTranslatef(0, -self.tile_size.y - 10, 0) gl.glPopMatrix() self.moneylabel.draw() self.weightlabel.draw() self.fuellabel.draw() self.startbutton.draw()
def draw(self): """Draw the label. The OpenGL state is assumed to be at default values, except that the MODELVIEW and PROJECTION matrices are ignored. At the return of this method the matrix mode will be MODELVIEW. """ gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glLoadIdentity() gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() gl.glOrtho(0, self.window.width, 0, self.window.height, -1, 1) self.label.draw() gl.glPopMatrix() gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPopMatrix()
def draw_simplified(self, xyz, num_divisions=0, division=0): diffuse_color = [0, 1, 0, 1] axes, center, hwl = get_principle_axes(xyz) gl.glPushMatrix() local_matrix = np.eye(4) local_matrix[:3, :3] = axes local_matrix[:3, 3] = center gl.glMultMatrixf(to_floatv4x4(local_matrix)) if division < num_divisions: xyz_aligned = get_aligned_xyz(xyz, axes.T, -center) for xyz_partition in get_octant_xyz(xyz_aligned): self.draw_simplified(xyz_partition, num_divisions=num_divisions, division=division + 1) else: radius = np.linalg.norm(0.5 * hwl[:2]) length = hwl[2] - 2.0 * radius if length > 0.0: CapsuleMesh(radius, length, color=diffuse_color).draw() else: SphereMesh(radius, color=diffuse_color) gl.glPopMatrix()
def draw(self): gl.glPushMatrix() # sets the position gl.glTranslatef(self.x, self.y, self.z) # sets the rotation gl.glRotatef(self.rx, 1, 0, 0) gl.glRotatef(self.ry, 0, 1, 0) gl.glRotatef(self.rz, 0, 0, 1) # sets the color gl.glColor4f(*self.color) # draw primitives with batch or vertex_list # batch=pyglet.graphics.Batch(); # vertex_list=batch.add(len(self.vertices) // 3,gl.GL_QUADS,None,('v3f', self.vertices)); # batch.draw(); # # draw by texture rendering if len(self.text_indices) > 0: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) print("text mode!") self.vertex_list.draw(gl.GL_TRIANGLES) # draw by wire-frame mode else: # sets wire-frame mode gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) # draws the quads pyglet.graphics.draw_indexed( len(self.vertices) // 3, gl.GL_QUADS, self.quad_indices, ('v3f', self.vertices)) # draws the triangles pyglet.graphics.draw_indexed( len(self.vertices) // 3, gl.GL_TRIANGLES, self.triangle_indices, ('v3f', self.vertices)) gl.glPopMatrix()
def draw_world(self): gl.glEnableClientState(gl.GL_NORMAL_ARRAY) self.projection.set_perspective(45) self.modelview.set_world() for item in self.world: if not hasattr(item, 'shape'): continue glyph = item.glyph gl.glPushMatrix() if hasattr(item, 'position'): gl.glTranslatef(*item.position) # TODO: item orientation gl.glVertexPointer( Glyph.DIMENSIONS, gl.GL_FLOAT, 0, glyph.glvertices) gl.glColorPointer( Color.NUM_COMPONENTS, gl.GL_UNSIGNED_BYTE, 0, glyph.glcolors) gl.glNormalPointer(gl.GL_FLOAT, 0, glyph.glnormals) gl.glDrawElements( gl.GL_TRIANGLES, len(glyph.glindices), type_to_enum[glyph.glindex_type], glyph.glindices) gl.glPopMatrix()
def __exit__(self, *args): gl.glMatrixMode(gl.GL_PROJECTION); gl.glPopMatrix() gl.glMatrixMode(gl.GL_MODELVIEW); gl.glPopMatrix()
def draw(self): glColor4ub(255, 255, 255, 255) glPushMatrix() self.transform() self.img.blit(0, 0) glPopMatrix()
def render(self, scene): """ Render the arrow on the current view. :param scene: The view to render the model into. :type scene: pyglet_helper.objects.View """ mat = Material() if self.degenerate: return self.init_model(scene) self.color.gl_set(self.opacity) _head_width, _shaft_width, _len, _head_length = \ self.effective_geometry(1.0) if self.mat and self.mat.get_shader_program(): model_material_loc = self.mat.get_shader_program().\ get_uniform_location(scene, "model_material") else: model_material_loc = -1 # Render the shaft and the head in back to front order (the shaft is in # front of the head if axis points away from the camera) shaft = self.axis.dot(scene.camera - (self.pos + self.axis * (1 - _head_length / _len))) < 0 gl.glPushMatrix() self.model_world_transform(scene.gcf).gl_mult() for part in range(0, 2): if part == shaft: gl.glScaled(_len - _head_length, _shaft_width, _shaft_width) gl.glTranslated(0.5, 0, 0) if model_material_loc >= 0: model_mat = Tmatrix() scale = 1.0 / max(_len, _head_width) _translation_magnitude = (_len - _head_length) * scale *\ 0.5 model_mat.translate( Vector([_translation_magnitude, 0.5, 0.5])) model_mat.scale( Vector([(_len - _head_length), _shaft_width, _shaft_width]) * scale) mat.get_shader_program().\ set_uniform_matrix(scene, model_material_loc, model_mat) scene.box_model.gl_render() gl.glTranslated(-0.5, 0, 0) gl.glScaled(1 / (_len - _head_length), 1 / _shaft_width, 1 / _shaft_width) else: gl.glTranslated(_len - _head_length, 0, 0) gl.glScaled(_head_length, _head_width, _head_width) if model_material_loc >= 0: model_mat = Tmatrix() _scale = 1.0 / max(_len, _head_width) model_mat.translate( Vector([(_len - _head_length) * _scale, 0.5, 0.5])) model_mat.scale( Vector([_head_length, _head_width, _head_width]) * _scale) mat.get_shader_program().\ set_uniform_matrix(scene, model_material_loc, model_mat) scene.pyramid_model.gl_render() gl.glScaled(1 / _head_length, 1 / _head_width, 1 / _head_width) gl.glTranslated(-_len + _head_length, 0, 0) gl.glPopMatrix()
def draw( self ): if self.img: glPushMatrix() self.transform() self.img.blit(0, 0) glPopMatrix()