def draw(self): if self.graph: glPushMatrix() glScalef(self.scale, self.scale, 1.0) self.graph.draw() glPopMatrix() self.grid.batch.draw()
def draw_axes(self): 'draw x y z axis in r g b with text labels' gl.glPushMatrix() gl.glScalef( 1.1, 1.1, 1.1) o = 0, 0, 0 x = 1, 0, 0 y = 0, 1, 0 z = 0, 0, 1 verts = numpy.array([ o, x, o, y, o, z], dtype=constants.DTYPE ) colors = numpy.array([ x, x, y, y, z, z], dtype=constants.DTYPE ) idxs = numpy.cast[constants.INTDTYPE]( numpy.mgrid[:6] ) self.drawlines( verts, colors, idxs) def draw_axis_label( name, xyz): 'draw a single label' gl.glPushMatrix() gl.glTranslatef( xyz[0], xyz[1], xyz[2] ) gl.glScalef( .01, .01, .01 ) gl.glRotatef( 90, 0, 1, 0 ) gl.glRotatef( 90, 0, 0, 1 ) pyglet.text.Label(name).draw() gl.glPopMatrix() draw_axis_label( 'x', x) draw_axis_label( 'y', y) draw_axis_label( 'z', z) gl.glPopMatrix()
def draw_circle(xpos, ypos, size, hsv): gl.glPushMatrix() gl.glTranslatef(xpos, ypos, 0) gl.glScalef(size, size, size) gl.glColor3f(*hsv_to_rgb(*hsv)) CIRCLE_VERTS.draw(gl.GL_TRIANGLE_FAN) gl.glPopMatrix()
def transform(self): """ Apply ModelView transformations. You will most likely want to wrap calls to this function with ``glPushMatrix()``/``glPopMatrix()`` """ x, y = director.get_window_size() if not(self.grid and self.grid.active): # only apply the camera if the grid is not active # otherwise, the camera will be applied inside the grid self.camera.locate() gl.glTranslatef(self.position[0], self.position[1], 0) gl.glTranslatef(self.transform_anchor_x, self.transform_anchor_y, 0) if self.rotation != 0.0: gl.glRotatef(-self._rotation, 0, 0, 1) if self.scale != 1.0 or self.scale_x != 1.0 or self.scale_y != 1.0: gl.glScalef(self._scale * self._scale_x, self._scale * self._scale_y, 1) if self.transform_anchor != (0, 0): gl.glTranslatef( -self.transform_anchor_x, -self.transform_anchor_y, 0)
def transform(self): """ Apply ModelView transformations. You will most likely want to wrap calls to this function with ``glPushMatrix()``/``glPopMatrix()`` """ x, y = director.get_window_size() if not (self.grid and self.grid.active): # only apply the camera if the grid is not active # otherwise, the camera will be applied inside the grid self.camera.locate() gl.glTranslatef(self.position[0], self.position[1], 0) gl.glTranslatef(self.transform_anchor_x, self.transform_anchor_y, 0) if self.rotation != 0.0: gl.glRotatef(-self._rotation, 0, 0, 1) if self.scale != 1.0 or self.scale_x != 1.0 or self.scale_y != 1.0: gl.glScalef(self._scale * self._scale_x, self._scale * self._scale_y, 1) if self.transform_anchor != (0, 0): gl.glTranslatef(-self.transform_anchor_x, -self.transform_anchor_y, 0)
def on_draw(self): self.clear() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() (w, h) = self.get_size() gl.glScalef( float(min(w, h))/w, -float(min(w, h))/h, 1 ) gl.gluPerspective(45.0, 1, 0.1, 1000.0) gl.gluLookAt(0, 0, 2.4, 0, 0, 0, 0, 1, 0) global render_texture render_texture = self.texture for v in self.visions.values(): gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() v.iteration() buf = pyglet.image.get_buffer_manager().get_color_buffer() rawimage = buf.get_image_data() self.texture = rawimage.get_texture() clock.tick()
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() if self.orthographic: glTranslatef(0, 0, -3 * self.dist) # Move back else: glTranslatef(0, 0, -self.dist) # Move back # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Move origin to bottom left of platform platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2 platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2 glTranslatef(platformx0, platformy0, 0) for obj in self.parent.objects: if not obj.model \ or not obj.model.loaded \ or not obj.model.initialized: continue glPushMatrix() glTranslatef(*(obj.offsets)) glTranslatef(*(obj.centeroffset)) glRotatef(obj.rot, 0.0, 0.0, 1.0) glScalef(*obj.scale) obj.model.display() glPopMatrix() glPopMatrix()
def flush_labels(self): gl.glClear(gl.GL_DEPTH_BUFFER_BIT) gl.glPushMatrix() gl.glTranslatef(-self.game.camera_x * defs.WINDOW_SCALE[0], -self.game.camera_y * defs.WINDOW_SCALE[1], 0) for label, x, y, scale in self.labels: if scale: gl.glPushMatrix() label.anchor_x = 'center' label.anchor_y = 'center' gl.glTranslatef(x * defs.WINDOW_SCALE[0], y * defs.WINDOW_SCALE[1], 0) gl.glScalef(*scale) label.x = label.y = 0 label.draw() gl.glPopMatrix() else: label.x = x * defs.WINDOW_SCALE[0] label.y = y * defs.WINDOW_SCALE[1] label.draw() self.labels = [] gl.glColor3f(1, 1, 1) gl.glEnable(gl.GL_DEPTH_TEST) gl.glPopMatrix() # self.fps_label.draw() self.game.score.draw()
def render(self, draw_bbox, annotated=False): """ Renders the object to screen """ if not self.visible: return from pyglet import gl # Draw the bounding box if draw_bbox: gl.glColor3f(1, 0, 0) gl.glBegin(gl.GL_LINE_LOOP) gl.glVertex3f(self.obj_corners.T[0, 0], 0.01, self.obj_corners.T[1, 0]) gl.glVertex3f(self.obj_corners.T[0, 1], 0.01, self.obj_corners.T[1, 1]) gl.glVertex3f(self.obj_corners.T[0, 2], 0.01, self.obj_corners.T[1, 2]) gl.glVertex3f(self.obj_corners.T[0, 3], 0.01, self.obj_corners.T[1, 3]) gl.glEnd() gl.glPushMatrix() gl.glTranslatef(*self.pos) gl.glScalef(self.scale, self.scale, self.scale) gl.glRotatef(self.y_rot, 0, 1, 0) gl.glColor3f(*self.color) annotated = annotated and self.on_driveable_tile if annotated and self.annotated_mesh is not None: self.annotated_mesh.render(annotated=annotated) else: self.mesh.render(annotated=annotated) gl.glPopMatrix()
def render(self, draw_bbox: bool, enable_leds: bool, segment: bool = False): """ Renders the object to screen """ if not self.visible: return # Draw the bounding box if draw_bbox: gl.glColor3f(1, 0, 0) gl.glBegin(gl.GL_LINE_LOOP) gl.glVertex3f(self.obj_corners.T[0, 0], 0.01, self.obj_corners.T[1, 0]) gl.glVertex3f(self.obj_corners.T[0, 1], 0.01, self.obj_corners.T[1, 1]) gl.glVertex3f(self.obj_corners.T[0, 2], 0.01, self.obj_corners.T[1, 2]) gl.glVertex3f(self.obj_corners.T[0, 3], 0.01, self.obj_corners.T[1, 3]) gl.glEnd() gl.glPushMatrix() gl.glTranslatef(*self.pos) gl.glScalef(self.scale, self.scale, self.scale) gl.glRotatef(self.x_rot, 1, 0, 0) # Niki-added gl.glRotatef(self.y_rot, 0, 1, 0) gl.glRotatef(self.z_rot, 0, 0, 1) # Niki-added gl.glColor4f(*self.color) self.render_mesh(segment, enable_leds=enable_leds) gl.glPopMatrix()
def draw(self): if self.batch is not None: glPushMatrix() glScalef(self.scale, self.scale, 0) self.batch.draw() glPopMatrix() self.grid.batch.draw()
def render(self, draw_bbox): """ Renders the object to screen """ if not self.visible: return from pyglet import gl # Draw the bounding box if draw_bbox: gl.glColor3f(1, 0, 0) gl.glBegin(gl.GL_LINE_LOOP) gl.glVertex3f(self.obj_corners.T[0, 0], 0.01, self.obj_corners.T[1, 0]) gl.glVertex3f(self.obj_corners.T[0, 1], 0.01, self.obj_corners.T[1, 1]) gl.glVertex3f(self.obj_corners.T[0, 2], 0.01, self.obj_corners.T[1, 2]) gl.glVertex3f(self.obj_corners.T[0, 3], 0.01, self.obj_corners.T[1, 3]) gl.glEnd() gl.glPushMatrix() gl.glTranslatef(*self.pos) gl.glScalef(self.scale, self.scale, self.scale) gl.glRotatef(self.y_rot, 0, 1, 0) gl.glColor3f(*self.color) self.mesh.render() gl.glPopMatrix()
def draw(self): self.margin.draw(GL_LINE_LOOP) scale = self.height / max(1, self.low_high.amplitude) glTranslatef(0, -self.low_high.lowest * scale, 0) glScalef(1, scale, 1) for candle in self.candles: candle.draw()
def on_resize(width, height): pgl.glBlendFunc(pgl.GL_SRC_ALPHA, pgl.GL_ONE_MINUS_SRC_ALPHA) pgl.glViewport(0, 0, 400, 400) #pgl.glEnable(pgl.GL_CULL_FACE) pgl.glScalef(100, 100, 0.01) pgl.glTranslatef(2, 2, 2) pgl.glRotatef(10, 0, 0, 1)
def draw(self): self.loadStartPosition() gl.glRotatef(90.0, 0.0, 0.0, 1.0) gl.glBegin(gl.GL_QUADS) gl.glColor3f(1.0, 1.0, 0.0) tenth = math.pi * 2.0 / 10.0 for z in [-0.1, 0.1]: for i in xrange(5): a = float(i) * tenth * 2.0 gl.glVertex3f(0.0, 0.0, z) gl.glVertex3f(0.4 * math.cos(a - tenth), 0.4 * math.sin(a - tenth), z) gl.glVertex3f(math.cos(a), math.sin(a), z) gl.glVertex3f(0.4 * math.cos(a + tenth), 0.4 * math.sin(a + tenth), z) for i in xrange(5): a = float(i) * tenth * 2.0 gl.glVertex3f(0.4 * math.cos(a - tenth), 0.4 * math.sin(a - tenth), 0.1) gl.glVertex3f(math.cos(a), math.sin(a), 0.1) gl.glVertex3f(math.cos(a), math.sin(a), -0.1) gl.glVertex3f(0.4 * math.cos(a - tenth), 0.4 * math.sin(a - tenth), -0.1) gl.glVertex3f(0.4 * math.cos(a + tenth), 0.4 * math.sin(a + tenth), 0.1) gl.glVertex3f(math.cos(a), math.sin(a), 0.1) gl.glVertex3f(math.cos(a), math.sin(a), -0.1) gl.glVertex3f(0.4 * math.cos(a + tenth), 0.4 * math.sin(a + tenth), -0.1) gl.glEnd() self.loadStartPosition() gl.glTranslatef(0.0, 0.0, 0.1) gl.glScalef(0.01, 0.01, 0.0) self.label.draw() gl.glLoadIdentity()
def predraw(w,h): gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION,vec(1,1,10, 3)) gl.glLightModelfv( gl.GL_LIGHT_MODEL_AMBIENT|gl.GL_LIGHT_MODEL_TWO_SIDE, vec(1,1,1, 1.0) ) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() #glOrtho(-1, 1, -1, 1, -1, 1) #(w,h) = self.get_size() gl.glScalef( float(min(w,h))/w, -float(min(w,h))/h, 1 ) gl.gluPerspective(45.0, 1, 0.1, 1000.0) gl.gluLookAt( camera.x, camera.y, camera.z, 0,0,0, camera.up[0], camera.up[1], camera.up[2] )
def draw_text(self, text, position, color, scale=1.0): if len(color) == 3: color = (color[0], color[1], color[2], 1.0) if self._p.label_font is None: self._p.label_font = font.load(self._p.font_face, self._p.font_size, bold=True, italic=False) label = font.Text( self._p.label_font, text, color=color, valign=font.Text.BASELINE, halign=font.Text.CENTER, ) pgl.glPushMatrix() pgl.glTranslatef(*position) billboard_matrix() scale_factor = 0.005 * scale pgl.glScalef(scale_factor, scale_factor, scale_factor) pgl.glColor4f(0, 0, 0, 0) label.draw() pgl.glPopMatrix()
def on_draw(self): self.clear() gl.glPushMatrix() zoom = float(self.height) / float(HEIGHT) gl.glScalef(zoom, zoom, 1) offset_x = (self.width / zoom - WIDTH) / 2 if offset_x > 0: #letterboxing pt. 1 gl.glTranslatef(offset_x, 0, 0) self.game.draw() #self.fps_display.draw() if self.state == self.menu: self.menu.draw() if offset_x > 0: #letterboxing pt. 2 gl.glTranslatef(-offset_x, 0, 0) gl.glColor4f(0, 0, 0, 1) gl.glBegin(gl.GL_QUADS) gl.glVertex3f(0, 0, 0) gl.glVertex3f(offset_x, 0, 0) gl.glVertex3f(offset_x, HEIGHT, 0) gl.glVertex3f(0, HEIGHT, 0) gl.glVertex3f(offset_x + WIDTH, 0, 0) gl.glVertex3f(offset_x * 2 + WIDTH, 0, 0) gl.glVertex3f(offset_x * 2 + WIDTH, HEIGHT, 0) gl.glVertex3f(offset_x + WIDTH, HEIGHT, 0) gl.glEnd() gl.glColor4f(1, 1, 1, 1) gl.glPopMatrix()
def draw_quad(self): """Draw a full-screen quad.""" gl.glPushMatrix() gl.glLoadIdentity() gl.glScalef(self.w, self.h, 1.0) self.vl.draw(gl.GL_QUADS) gl.glPopMatrix()
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Move origin to bottom left of platform platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2 platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2 glTranslatef(platformx0, platformy0, 0) for obj in self.parent.objects: if not obj.model \ or not obj.model.loaded: continue # Skip (comment out) initialized check, which safely causes empty # model during progressive load. This can cause exceptions/garbage # render, but seems fine for now # May need to lock init() and draw_objects() together # if not obj.model.initialized: # continue glPushMatrix() glTranslatef(*(obj.offsets)) glRotatef(obj.rot, 0.0, 0.0, 1.0) glTranslatef(*(obj.centeroffset)) glScalef(*obj.scale) obj.model.display() glPopMatrix() glPopMatrix()
def drawBody(self, body): # type: (Dict[str, Any]) -> None """Draw a body""" pos = body['position'] rpy = body['rotation'] r, p, y = rpy[0], rpy[1], rpy[2] gl.glPushMatrix() gl.glTranslatef(pos[0], pos[1], pos[2]) gl.glRotatef(np.rad2deg(y), 0.0, 0.0, 1.0) gl.glRotatef(np.rad2deg(p), 0.0, 1.0, 0.0) gl.glRotatef(np.rad2deg(r), 1.0, 0.0, 0.0) self.drawCoords() rel_pos = body['center'] gl.glTranslatef(rel_pos[0], rel_pos[1], rel_pos[2]) transparent = 'transparent' in body and body['transparent'] dim = body['size3'] gl.glScalef(dim[0], dim[1], dim[2]) self.setMaterial(body['material']) if body['geometry'] is 'box': if transparent: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) # Wireframe self.drawCube() if transparent: gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) elif body['geometry'] is 'mesh': self.drawMesh(body['name']) gl.glPopMatrix()
def begin(self): # Set the current camera offset so you can draw your scene. # Translate using the zoom and the offset. glTranslatef(-self.offset_x, -self.offset_y, 0) # Scale by zoom level. glScalef(self._zoom, self._zoom, 1)
def on_draw(): pyglet.clock.tick() window.clear() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() (w, h) = window.get_size() gl.glScalef( float(min(w, h))/w, -float(min(w, h))/h, 1 ) gl.gluPerspective(45.0, 1, 0.1, 1000.0) gl.gluLookAt(0, 0, 2.4, 0, 0, 0, 0, 1, 0) for vision in window.visions.values(): gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() vision() buf = pyglet.image.get_buffer_manager().get_color_buffer() rawimage = buf.get_image_data() window.texture = rawimage.get_texture()
def draw_square(xpos, ypos, height, width, hsv): gl.glPushMatrix() gl.glTranslatef(xpos, ypos, 0) gl.glScalef(height, width, 1) gl.glColor3f(*hsv_to_rgb(*hsv)) SQUARE_VERTS.draw(gl.GL_TRIANGLE_STRIP) gl.glPopMatrix()
def render(self, mode='human'): if mode == 'human': if self.window is None: self.window = pyglet.window.Window(self.map.width*tile_width, self.map.height*tile_width) glTranslatef(-1, 1, 0) glScalef(2/self.map.width/tile_width, -2/self.map.height/tile_width, 1) self.batch = pyglet.graphics.Batch() self.trajectories_batch = pyglet.graphics.Batch() self.circle = shapes.Circle(self.car.pos.x*tile_width, self.car.pos.y*tile_width, tile_width/4, color=(255, 128, 128), batch=self.batch) self.map.draw(self.batch) self.circle.x = self.car.pos.x*tile_width self.circle.y = self.car.pos.y*tile_width self.window.clear() # Draw board self.batch.draw() self.trajectories_batch.draw() # Draw car self.circle.draw() self.window.flip() if mode == 'trajectories': if self.window is None: self.window = pyglet.window.Window(self.map.width*tile_width, self.map.height*tile_width) glTranslatef(-1, 1, 0) glScalef(2/self.map.width/tile_width, -2/self.map.height/tile_width, 1) self.batch = pyglet.graphics.Batch() self.map.draw(self.batch) self.window.clear() self.batch.draw() self.window.flip()
def draw(self, frame): # The gneneral plan here is: # 1. Get the dots in the range of 0-255. # 2. Create a texture with the dots data. # 3. Draw the texture, scaled up with nearest-neighbor. # 4. Draw a mask over the dots to give them a slightly more realistic look. gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glLoadIdentity() # Draw the dots in this color: #gl.glColor3f(1.0, 0.5, 0.25) gl.glScalef(1, -1, 1) gl.glTranslatef(0, -DMD_SIZE[1]*DMD_SCALE, 0) #data = frame.get_data_mult() #this new jk_get_data will read the dots using the dmd function #and convert them via the map to rGB. data = self.jk_get_data(frame) image = pyglet.image.ImageData(DMD_SIZE[0], DMD_SIZE[1], 'RGB', data, pitch=DMD_SIZE[0] * 3) gl.glTexParameteri(image.get_texture().target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) image.blit(0, 0, width=DMD_SIZE[0]*DMD_SCALE, height=DMD_SIZE[1]*DMD_SCALE) del image gl.glScalef(DMD_SCALE/float(MASK_SIZE), DMD_SCALE/float(MASK_SIZE), 1.0) gl.glColor4f(1.0, 1.0, 1.0, 1.0) self.mask_texture.blit_tiled(x=0, y=0, z=0, width=DMD_SIZE[0]*MASK_SIZE, height=DMD_SIZE[1]*MASK_SIZE)
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Move origin to bottom left of platform platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2 platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2 glTranslatef(platformx0, platformy0, 0) light_z = max(self.parent.platform.width, self.parent.platform.depth) glLightfv(GL_LIGHT0, GL_POSITION, vec(0, self.parent.platform.depth / 2, light_z, 0)) glLightfv(GL_LIGHT1, GL_POSITION, vec(self.parent.platform.width, self.parent.platform.depth / 2, light_z, 0)) for obj in self.parent.objects: if not obj.model \ or not obj.model.loaded \ or not obj.model.initialized: continue glPushMatrix() glTranslatef(*(obj.offsets)) glTranslatef(*(obj.centeroffset)) glRotatef(obj.rot, 0.0, 0.0, 1.0) glScalef(*obj.scale) obj.model.display() glPopMatrix() glPopMatrix()
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Move origin to bottom left of platform platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2 platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2 glTranslatef(platformx0, platformy0, 0) for obj in self.parent.objects: if not obj.model \ or not obj.model.loaded \ or not obj.model.initialized: continue glPushMatrix() glTranslatef(*(obj.offsets)) glRotatef(obj.rot, 0.0, 0.0, 1.0) glTranslatef(*(obj.centeroffset)) glScalef(*obj.scale) obj.model.display() glPopMatrix() glPopMatrix()
def add_movies(self, *movie_paths): clip_file_name = self._clip_file_pattern.format(index=len(self._clips)) # noinspection PyTypeChecker with NamedTemporaryFile(mode="w") as file: paths = "\n- ".join(movie_paths) print(f"Concat movie files into {clip_file_name}: \n-{paths}") for path in movie_paths: line = f"file '{os.path.abspath(path)}'\n" file.write(line) file.flush() (ffmpeg.input(file.name, format="concat", safe=0).output(clip_file_name, c="copy").run(overwrite_output=True)) print(f"Created {clip_file_name}") clip: FFmpegSource = pyglet.media.load(clip_file_name) self._clips.append(Clip(source=clip, file=clip_file_name)) if not self.video_y: ratio_y = self._window.height / clip.video_format.height ratio_x = self._window.width / clip.video_format.width ratio = min(ratio_x, ratio_y) gl.glScalef(ratio, ratio, ratio) if ratio_x == ratio: self.video_y = ( (self._window.height - clip.video_format.height * ratio) / ratio) / 2 else: self.video_y = 0 return self
def write_text(self, text): #gl.glTexEnvf( gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE ) #gl.glEnable( gl.GL_DEPTH_TEST ) gl.glEnable(gl.GL_BLEND) #gl.glEnable( gl.GL_COLOR_MATERIAL ) #gl.glColorMaterial( gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE ) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_TEXTURE_2D) gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture_id) gl.glColor4f(1, 1, 0, 1) gl.glPushMatrix() gl.glLoadIdentity() gl.glScalef(0.003, 0.003, 0) #gl.glTranslatef(10, 100, 0) gl.glPushMatrix() gl.glListBase(self.base) gl.glCallLists(len(text), gl.GL_UNSIGNED_BYTE, bytes(text, 'utf-8')) #for c in text: # gl.glCallList(self.base + 1 + ord(c)) gl.glPopMatrix() gl.glPopMatrix() gl.glDisable(gl.GL_BLEND) gl.glDisable(gl.GL_TEXTURE_2D)
def draw(self): glPushMatrix() glRotatef(self.angle, 0., 0., 1.) glScalef(self.scale, 1., 1.) glTranslatef(0., -common_res.ray.height/2, 0.) glColor4f(1., 1., 1., self.alpha) common_res.ray.blit(0, 0) glPopMatrix()
def update(self): gl.glColor3f(*self.color) gl.glPushMatrix() gl.glTranslatef(self.x, self.y, self.z) gl.glScalef(self.scale, self.scale, self.scale) for list in self.vertex_lists: list.draw(gl.GL_LINES) gl.glPopMatrix()
def draw(self): glPushMatrix() glRotatef(self.angle, 0., 0., 1.) glScalef(self.scale, 1., 1.) glTranslatef(0., -common_res.ray.height / 2, 0.) glColor4f(1., 1., 1., self.alpha) common_res.ray.blit(0, 0) glPopMatrix()
def draw(self, scale=1): gl.glPushMatrix() gl.glEnable(gl.GL_TEXTURE_2D) gl.glTranslatef(*self.position) gl.glRotatef(self.angle, 0, 0, 1) gl.glScalef(scale, scale, scale) self.batch.draw() gl.glPopMatrix()
def _draw_local(self): super(ShipPartConfigurationView, self)._draw_local() glPushMatrix() glRotatef(-self.yaw, 0, 1, 0) glRotatef(-90, 1, 0, 0) glScalef(0.025, 0.025, 0.025) self.infobox.draw() glPopMatrix()
def attach(self): """Applies camera transformations to subsequent draws. Calling :fn:`camera.Camera.detach` stops applying the transformations. """ gl.glPushMatrix() gl.glScalef(self.scale, self.scale, 0) gl.glTranslatef(-self.x, -self.y, 0)
def _draw_perspective(self): super(ModelInspectionMenuComponent, self)._draw_perspective() glTranslatef(0, 0, -10) glRotatef(90 + (self._animation_timer * 90), 1, .5, .5) glScalef(self._view_scale, self._view_scale, self._view_scale) self._view.draw() self._view.draw_transparent()
def draw(self): gl.glPushMatrix() gl.glTranslatef(self.xpos, self.ypos, 0) gl.glRotatef(self.angle, 0, 0, 1) gl.glScalef(self.size, self.size, self.size) gl.glColor3f(*self.rgb) self.vlist.draw(gl.GL_TRIANGLE_FAN) gl.glPopMatrix()
def on_resize(self, w, h): super().on_resize(w, h) self.label.x = w / 2 self.label.y = h / 2 scale = min(w // self.base_width, h // self.base_height) gl.glLoadIdentity() gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) gl.glScalef(scale, scale, scale)
def draw(self): ray = L('c-ray') glPushMatrix() glRotatef(self.angle, 0., 0., 1.) glScalef(self.scale, 1., 1.) glTranslatef(0., -ray.height/2, 0.) glColor4f(1., 1., 1., self.alpha) ray.blit(0, 0) glPopMatrix()
def end(self): # Since this is a matrix, you will need to reverse the translate after rendering otherwise # it will multiply the current offset every draw update pushing it further and further away. # Reverse scale, since that was the last transform. glScalef(round(1 / self._zoom, 1), round(1 / self._zoom, 1), 1) # Reverse translate. glTranslatef(self.offset_x, self.offset_y, 0)
def draw_axis_label( name, xyz): 'draw a single label' gl.glPushMatrix() gl.glTranslatef( xyz[0], xyz[1], xyz[2] ) gl.glScalef( .01, .01, .01 ) gl.glRotatef( 90, 0, 1, 0 ) gl.glRotatef( 90, 0, 0, 1 ) pyglet.text.Label(name).draw() gl.glPopMatrix()
def on_draw(self): rendr_components, trans_components = self.entity_manager.get_all_components_of_types([Render, Transform]) for render, trans in zip(rendr_components, trans_components): gl.glPushMatrix() gl.glTranslatef(trans.x, trans.y, 0.0) gl.glRotatef(trans.rotation, 0, 0, 1) gl.glScalef(trans.scale, trans.scale, 1.0) render.image.blit(trans.anchor_x, trans.anchor_y) gl.glPopMatrix()
def scale(x, y=None, z=None): if y is None: y, z = x, x elif z is None: z = 1 gl.glPushMatrix() gl.glScalef(x, y, z) yield gl.glPopMatrix()
def update(self): glPushMatrix() glLoadIdentity() glTranslatef(*self.position) glRotatef(self.pitch, 1, 0, 0) glRotatef(self.yaw, 0, 1, 0) glRotatef(self.roll, 0, 0, 1) glScalef(*self._mesh_scale) glGetFloatv(GL_MODELVIEW_MATRIX, self._model_view_matrix) glPopMatrix()
def draw(self): try: gl.glPushMatrix() gl.glLoadIdentity() gl.glTranslatef(self.position.x, self.position.y, 0) gl.glScalef(self.scale, self.scale, 1) self._label.draw() except Exception, e: print(e, traceback.print_exc()) time.sleep(0.0001) raise e
def draw(self, window): a = self.zoom(self.timeAlive) h = self.height(self.timeAlive) gl.glPushMatrix() gl.glTranslatef(self.props.windowWidth//2, h, 0) gl.glScalef(a,a,a) self.text.draw() gl.glPopMatrix()
def draw_lem_model (self): with push_matrix(gl.GL_MODELVIEW): gl.glTranslatef(*np.append(self.scaleFactor*self.simulator.lander.pos, 0)) gl.glRotatef(-math.degrees(self.simulator.lander.rot), 0, 0, -1) gl.glScalef(*[self.scaleFactor]*3) gl.glTranslatef(0, -3, 0) gl.glRotatef(0, 0, 1, 0) gl.glRotatef(90, -1, 0, 0) gl.glScalef(*[2**0.5]*3) self.lem_model.render()
def transform_start(self): angle = self.angle scale = self.scale gl.glPushMatrix() gl.glTranslatef(*tuple(self.pos)) gl.glRotatef(angle.z, 0, 0, 1) gl.glRotatef(angle.y, 0, 1, 0) gl.glRotatef(angle.x, 1, 0, 0) #experimental gl.glScalef(*tuple(scale))
def zoom(self, factor, to = None): glMatrixMode(GL_MODELVIEW) if to: delta_x = to[0] delta_y = to[1] glTranslatef(delta_x, delta_y, 0) glScalef(factor, factor, 1) self.zoom_factor *= factor if to: glTranslatef(-delta_x, -delta_y, 0) wx.CallAfter(self.Refresh)
def display(self, width, height): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glTranslatef(self.trans[0], self.trans[1], 0) gl.glScalef(self.trans[2], self.trans[2], self.trans[2]) # FIXME draw only visible part? self.renderer.render()
def reset_mview(self, factor): glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.setup_lights() if self.orthographic: wratio = self.width / self.dist hratio = self.height / self.dist minratio = float(min(wratio, hratio)) self.zoom_factor = 1.0 self.zoomed_width = wratio / minratio self.zoomed_height = hratio / minratio glScalef(factor * minratio, factor * minratio, 1)
def draw(self): glLoadIdentity() glTranslatef(self.x, self.y, 0.0) glRotatef(self.rot, 0, 0, 1) glScalef(self.size, self.size, 1.0) glBegin(GL_TRIANGLES) glColor4f(self.rand_colour1, self.rand_colour2, self.rand_colour3, 0.0) glVertex2f(0.0, 0.5) glColor4f(self.rand_colour3, self.rand_colour2, self.rand_colour1, 1.0) glVertex2f(0.2, -0.5) glColor4f(0.0, 0.0, 1.0, 1.0) glVertex2f(-0.2, -0.5) glEnd()
def scale(f, *args): if len(args) == 3: x, y, z = args elif len(args) == 2: x, y, z = args + [1] elif len(args) == 1: x, y, z = args * 3 else: raise TypeError # TODO better explaination push() gl.glScalef(x, y, z) f() pop()
def draw(self): gl.glTranslatef(window.width / 2, window.height // 2, 0) gl.glScalef(self.camera.zoom, self.camera.zoom, 1.0) gl.glTranslatef(-self.camera.x, self.camera.y, 0) OPACITY = 255 # 255 actually, but I'm testing now for tile in self.drawable_tiles: if tile.opacity < OPACITY: tile.opacity = min(OPACITY, int((time.time() - tile.loaded) * OPACITY)) tile.draw() self.salmon.draw() self.draw_arrows() for dot in self.dots: dot.draw()
def set_state(self): ''' Enables a scissor test on our region ''' gl.glPushAttrib(gl.GL_ENABLE_BIT | gl.GL_TRANSFORM_BIT | gl.GL_CURRENT_BIT) self.was_scissor_enabled = gl.glIsEnabled(gl.GL_SCISSOR_TEST) gl.glEnable(gl.GL_SCISSOR_TEST) gl.glScissor(int(self.x), int(self.y), int(self.width), int(self.height)) if self._scale != 1.0: gl.glPushMatrix(gl.GL_MODELVIEW_MATRIX) gl.glScalef(self._scale,self._scale,1.0)
def fit(self): if not self.parent.model or not self.parent.model.loaded: return self.canvas.SetCurrent(self.context) dims = self.parent.model.dims self.reset_mview(1.0) center_x = (dims[0][0] + dims[0][1]) / 2 center_y = (dims[1][0] + dims[1][1]) / 2 center_x = self.build_dimensions[0] / 2 - center_x center_y = self.build_dimensions[1] / 2 - center_y if self.orthographic: ratio = float(self.dist) / max(dims[0][2], dims[1][2]) glScalef(ratio, ratio, 1) glTranslatef(center_x, center_y, 0) wx.CallAfter(self.Refresh)