def paintGL(self): """ docstring """ self._mutex.acquire() GL.glViewport(0,0,DEFAULT_SHAPE[0],DEFAULT_SHAPE[1]) gloo.clear(color=True, depth=True,stencil=True) self._chosenAlgo.timedUpdate() self._mutex.release()
def on_draw(self, event): # Clear gloo.clear() # Draw self._program["u_time"] = time.time() - self._starttime self._program.draw("points")
def on_draw(self, event): while os.path.exists(self.filename()): self.frame += 1 if self.frame > self.anim_frames: vispy.app.quit() print("{:5d}/{}".format(self.frame, self.anim_frames)) self.fbo.activate() gloo.set_state(depth_test=False, clear_color='black') gloo.clear(color=True) w, h = self.fbsize gloo.set_viewport(0, 0, w, h) self.render['aspect'] = w / h self.render['width'] = w self.render['frame'] = self.frame self.render.draw('triangle_strip') self.context.finish() arr = self.fbo.read().copy() arr[:, :, 3] = 255 img = Image.fromarray(arr) img.save(self.filename()) self.frame += 1 self.update()
def on_draw(self, event): gloo.clear() gloo.set_viewport(0, 0, self.camera.width, self.camera.height) self.program['u_light_position'] = [100., 100., 500.] self.program['u_is_lighting'] = True self.program['u_model'] = self.camera.model self.program['u_normal'] = self.camera.rotation self.program['u_view'] = self.camera.view self.program['u_projection'] = self.camera.projection self.program['u_is_fog'] = self.camera.is_fog self.program['u_fog_far'] = self.camera.fog_far self.program['u_fog_near'] = self.camera.fog_near self.program['u_fog_color'] = self.camera.fog_color gl.glEnable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LEQUAL) gl.glCullFace(gl.GL_FRONT) gl.glEnable(gl.GL_CULL_FACE) self.draw_buffers(self.program) gl.glDisable(gl.GL_BLEND) gl.glDisable(gl.GL_DEPTH_TEST) gl.glDisable(gl.GL_CULL_FACE) self.console.draw() self.last_draw = 'screen' self.update()
def on_draw(self, event): """Draw the visual.""" gloo.clear(color=True, depth=True) if self._show_mean: self.mean.draw() else: self.visual.draw()
def on_draw(self, event): '''TODO: Make a better way to skip drawing...this is a hack at best ''' gloo.set_viewport(0, 0, *self.size) gloo.clear(color=True, depth=True) self.rendering_world.draw(self.view)
def test_regular_polygon_draw2(): """Test drawing transformed regular polygons using RegularPolygonVisual""" # noqa with TestingCanvas() as c: rpolygon = visuals.RegularPolygon(pos=(0., 0.), radius=0.4, sides=8, color=(0, 0, 1, 1)) rpolygon.transform = transforms.STTransform(scale=(75, 100), translate=(50, 50)) c.draw_visual(rpolygon) assert_image_equal("screenshot", 'visuals/regular_polygon4.png') gloo.clear() rpolygon = visuals.RegularPolygon(pos=(0., 0.), radius=0.4, sides=8, color=(0, 0, 1, 1), border_color=(1, 0, 0, 1)) rpolygon.transform = transforms.STTransform(scale=(75, 100), translate=(50, 50)) c.draw_visual(rpolygon) assert_image_equal("screenshot", 'visuals/regular_polygon5.png') gloo.clear() rpolygon = visuals.RegularPolygon(pos=(0., 0.), radius=0.4, sides=8, border_color=(1, 0, 0, 1)) rpolygon.transform = transforms.STTransform(scale=(75, 100), translate=(50, 50)) c.draw_visual(rpolygon) assert_image_equal("screenshot", 'visuals/regular_polygon6.png', 0.6)
def draw(self, event): #Turn on additive blending gloo.set_state('additive') gloo.clear() #Summary render to main screen if self.state == 'texture' or self.state == 'raw': self._program.draw('triangles', self.indices_buffer) elif self.state == 'flow': self._program_flow.bind(self._vbo) self._program_flow.draw('triangles', self.indices_buffer) elif self.state == 'mask': self._program_mask.bind(self._vbo) #self._updatemaskpalette(np.squeeze(self.randfacecolors[:,:,0])) #self._updatemaskpalette(np.squeeze(self.randhessfacecolors[:,:,1])) self._updatemaskpalette(np.squeeze(self.hessfacecolors[:,:,1])) #print self._program_mask['u_colors']#self.randfacecolors[:,:,0] self._program_mask.draw('triangles', self.indices_buffer) elif self.state == 'overlay': self._program_red['texture1'] = self.current_texture self._program_red.bind(self._quad) self._program_red.draw('triangles', self.quad_buffer) self._program_green.bind(self._vbo) self._program_green['texture1'] = self.init_texture self._program_green.draw('triangles', self.indices_buffer) else: self._program_outline.bind(self._vbo) self._program_outline.draw('lines', self.outline_buffer) #Draw wireframe, too if self.state != 'raw' and self.state != 'outline': self._program_lines.draw('lines', self.outline_buffer)
def on_draw(self, ev): test = self.physical_size gloo.set_viewport(800, 0, *self.physical_size) gloo.clear(color='white', depth=True) for mesh in self.meshes: mesh.draw()
def test_square_draw(): """Test drawing squares without transforms using PolygonVisual""" pos = np.array([[-0.5, 0.5, 0], [0.5, 0.5, 0], [0.5, -0.5, 0], [-0.5, -0.5, 0]]) with TestingCanvas() as c: polygon = visuals.Polygon(pos=pos, color=(1, 0, 0, 1)) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/square1.png') gloo.clear() polygon = visuals.Polygon(pos=pos, color=(1, 0, 0, 1), border_color=(1, 1, 1, 1)) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/square2.png') gloo.clear() polygon = visuals.Polygon(pos=pos, border_color=(1, 1, 1, 1)) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/square3.png', 0.45)
def test_use_framebuffer(): """Test drawing to a framebuffer""" shape = (100, 300) # for some reason Windows wants a tall window... data = np.random.rand(*shape).astype(np.float32) use_shape = shape + (3,) with Canvas(size=shape[::-1]) as c: orig_tex = Texture2D(data) fbo_tex = Texture2D(use_shape, format='rgb') rbo = RenderBuffer(shape, 'color') fbo = FrameBuffer(color=fbo_tex) c.context.glir.set_verbose(True) assert_equal(c.size, shape[::-1]) set_viewport((0, 0) + c.size) with fbo: draw_texture(orig_tex) draw_texture(fbo_tex) out_tex = _screenshot()[::-1, :, 0].astype(np.float32) assert_equal(out_tex.shape, c.size[::-1]) assert_raises(TypeError, FrameBuffer.color_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, fbo, 1.) fbo.color_buffer = rbo fbo.depth_buffer = RenderBuffer(shape) fbo.stencil_buffer = None print((fbo.color_buffer, fbo.depth_buffer, fbo.stencil_buffer)) clear(color='black') with fbo: clear(color='black') draw_texture(orig_tex) out_rbo = _screenshot()[:, :, 0].astype(np.float32) assert_allclose(data * 255., out_tex, atol=1) assert_allclose(data * 255., out_rbo, atol=1)
def test_gloo_without_app(): """ Test gloo without vispy.app (with FakeCanvas) """ # Create dummy parser class DummyParser(gloo.glir.BaseGlirParser): def __init__(self): self.commands = [] def parse(self, commands): self.commands.extend(commands) p = DummyParser() # Create fake canvas and attach our parser c = gloo.context.FakeCanvas() c.context.shared.parser = p # Do some commands gloo.clear() c.flush() gloo.clear() c.flush() assert len(p.commands) in (2, 3) # there may be a CURRENT command assert p.commands[-1][1] == 'glClear'
def on_draw(self, event): gloo.clear() self.program['u_light_position'] = [100., 100., 500.] self.program['u_is_lighting'] = True self.program['u_model'] = self.camera.model self.program['u_normal'] = self.camera.rotation self.program['u_view'] = self.camera.view self.program['u_projection'] = self.camera.projection self.program['u_is_fog'] = self.camera.is_fog self.program['u_fog_far'] = self.camera.zoom + 50 self.program['u_fog_near'] = 1 self.program['u_fog_color'] = self.camera.fog_color # self.program.bind(self.cylinder_vertex_buffer) # self.program.draw('triangles', self.cylinder_index_buffer) self.program.bind(self.arrow_buffer) self.program.draw('triangles') self.program.bind(self.ballstick_vertex_buffer) self.program.draw('triangles', self.ballstick_index_buffer) self.program.bind(self.cartoon_vertex_buffer) self.program.draw('triangles', self.cartoon_index_buffer) self.update()
def test_ellipse_draw(): """Test drawing transformed ellipses using EllipseVisual""" with TestingCanvas() as c: ellipse = visuals.Ellipse(pos=(0., 0.), radius=(20, 15), color=(0, 0, 1, 1)) ellipse.transform = transforms.STTransform(scale=(2.0, 3.0), translate=(50, 50)) c.draw_visual(ellipse) assert_image_equal("screenshot", 'visuals/ellipse1.png') gloo.clear() ellipse = visuals.Ellipse(pos=(0., 0.), radius=(20, 15), color=(0, 0, 1, 1), border_color=(1, 0, 0, 1)) ellipse.transform = transforms.STTransform(scale=(2.0, 3.0), translate=(50, 50)) c.draw_visual(ellipse) assert_image_equal("screenshot", 'visuals/ellipse2.png') gloo.clear() ellipse = visuals.Ellipse(pos=(0., 0.), radius=(20, 15), border_color=(1, 0, 0, 1)) ellipse.transform = transforms.STTransform(scale=(2.0, 3.0), translate=(50, 50)) c.draw_visual(ellipse) assert_image_equal("screenshot", 'visuals/ellipse3.png')
def test_rectangle_draw(): """Test drawing rectangles with transforms using PolygonVisual""" pos = np.array([[-0.1, 0.5, 0], [0.1, 0.5, 0], [0.1, -0.5, 0], [-0.1, -0.5, 0]]) with TestingCanvas() as c: polygon = visuals.Polygon(pos=pos, color=(1, 1, 0, 1)) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/rectangle1.png') gloo.clear() polygon = visuals.Polygon(pos=pos, color=(1, 1, 0, 1), border_color=(1, 0, 0, 1)) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/rectangle2.png') gloo.clear() polygon = visuals.Polygon(pos=pos, border_color=(1, 0, 0, 1), border_width=2) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/rectangle3.png')
def test_use_framebuffer(): """Test drawing to a framebuffer""" shape = (100, 100) data = np.random.rand(*shape).astype(np.float32) orig_tex = Texture2D(data) use_shape = shape + (3,) fbo_tex = Texture2D(shape=use_shape, dtype=np.ubyte, format='rgb') rbo = ColorBuffer(shape=shape) fbo = FrameBuffer(color=fbo_tex) with Canvas(size=(100, 100)) as c: set_viewport((0, 0) + c.size) with fbo: draw_texture(orig_tex) draw_texture(fbo_tex) out_tex = _screenshot()[::-1, :, 0].astype(np.float32) assert_raises(TypeError, FrameBuffer.color_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, fbo, 1.) fbo.color_buffer = rbo fbo.depth_buffer = DepthBuffer(shape) fbo.stencil_buffer = None print((fbo.color_buffer, fbo.depth_buffer, fbo.stencil_buffer)) clear(color='black') with fbo: clear(color='black') draw_texture(orig_tex) out_rbo = _screenshot()[:, :, 0].astype(np.float32) assert_allclose(data * 255., out_tex, atol=1) assert_allclose(data * 255., out_rbo, atol=1)
def draw(self): gloo.clear(self.background_color) if self.measuring: self.measure_line.draw(self.canvas.tr_sys) if self.show_spikes: self.point_program.draw('points') self.strip_program.draw('line_strip')
def test_reactive_draw(): """Test reactive RectPolygon attributes""" with TestingCanvas() as c: rectpolygon = visuals.Rectangle(pos=(50, 50, 0), height=40., width=80., color='red') c.draw_visual(rectpolygon) gloo.clear() rectpolygon.radius = [20., 20, 0., 10.] c.draw_visual(rectpolygon) assert_image_equal("screenshot", 'visuals/reactive_rectpolygon1.png') gloo.clear() rectpolygon.pos = (60, 60, 0) c.draw_visual(rectpolygon) assert_image_equal("screenshot", 'visuals/reactive_rectpolygon2.png') gloo.clear() rectpolygon.color = 'blue' c.draw_visual(rectpolygon) assert_image_equal("screenshot", 'visuals/reactive_rectpolygon3.png') gloo.clear() rectpolygon.border_color = 'yellow' c.draw_visual(rectpolygon) assert_image_equal("screenshot", 'visuals/reactive_rectpolygon4.png') gloo.clear() rectpolygon.radius = 10. c.draw_visual(rectpolygon) assert_image_equal("screenshot", 'visuals/reactive_rectpolygon5.png')
def on_draw(self, event): gloo.clear() # Filled cube gloo.set_state(blend=False, depth_test=True, polygon_offset_fill=True) self.program.draw('triangles', self.filled_buf)
def on_draw(self, event): """Draw the correlograms visual.""" gloo.clear() self.visual.draw() self.boxes.draw() if self._lines: self.axes.draw()
def on_draw(self, event): gloo.clear() self._program['sizeFactor'] = 1# + np.sin(time.time() * 3) * 0.2 self._program.draw('triangles', indices_buffer) #Draw wireframe, too self._program_lines['sizeFactor'] = 1# + np.sin(time.time() * 3) * 0.2 self._program_lines['u_color'] = 1, 1, 0, 1 self._program_lines.draw('lines', outline_buffer)
def on_draw(self, event): """Draw the features in a grid view.""" gloo.clear(color=True, depth=True) self.axes.draw() self.background.draw() self.visual.draw() self.lasso.draw() self.boxes.draw()
def on_draw(self, event): gloo.clear('black') gloo.set_viewport(0, 0, *self.size) self.program.draw('triangle_strip') self.program2.draw('triangle_strip') self.program3.draw('triangle_strip') self.text.draw(self.tr_sys) self.steptext.draw(self.tr_sys)
def draw(self): gloo.clear((0.5, 0.5, 0.5, 1)) if self.measuring: self.measure_line.draw() self.program.draw('lines') for label in self.tick_labels: label.draw() self.tick_marks.draw()
def on_draw(self, event): t = timeit.default_timer() self.times.append(t) if len(self.times) >= 2: print(1./(t-self.times[-2])) gloo.clear() self.program.draw('points') self.update()
def on_draw(self, event): """ canvas update callback """ gloo.clear() # Filled cube gloo.set_state(blend=True, depth_test=False, polygon_offset_fill=True) self.program['u_color'] = [1.0, 1.0, 1.0, 0.6] self.program.draw('triangles', self.I)
def test_wrappers(): """Test gloo wrappers""" with Canvas(): gl.use_gl('desktop debug') gloo.clear('#112233') # make it so that there's something non-zero # check presets assert_raises(ValueError, gloo.set_state, preset='foo') for state in gloo.get_state_presets().keys(): gloo.set_state(state) assert_raises(ValueError, gloo.set_blend_color, (0., 0.)) # bad color assert_raises(TypeError, gloo.set_hint, 1, 2) # need strs assert_raises(TypeError, gloo.get_parameter, 1) # need str # this doesn't exist in ES 2.0 namespace assert_raises(ValueError, gloo.set_hint, 'fog_hint', 'nicest') # test bad enum assert_raises(RuntimeError, gloo.set_line_width, -1) # check read_pixels x = gloo.read_pixels() assert_true(isinstance(x, np.ndarray)) assert_true(isinstance(gloo.read_pixels((0, 0, 1, 1)), np.ndarray)) assert_raises(ValueError, gloo.read_pixels, (0, 0, 1)) # bad port y = gloo.read_pixels(alpha=False, out_type=np.ubyte) assert_equal(y.shape, x.shape[:2] + (3,)) assert_array_equal(x[..., :3], y) y = gloo.read_pixels(out_type='float') assert_allclose(x/255., y) # now let's (indirectly) check our set_* functions viewport = (0, 0, 1, 1) blend_color = (0., 0., 0.) _funs = dict(viewport=viewport, # checked hint=('generate_mipmap_hint', 'nicest'), depth_range=(1., 2.), front_face='cw', # checked cull_face='front', line_width=1., polygon_offset=(1., 1.), blend_func=('zero', 'one'), blend_color=blend_color, blend_equation='func_add', scissor=(0, 0, 1, 1), stencil_func=('never', 1, 2, 'back'), stencil_mask=4, stencil_op=('zero', 'zero', 'zero', 'back'), depth_func='greater', depth_mask=True, color_mask=(True, True, True, True), sample_coverage=(0.5, True)) gloo.set_state(**_funs) gloo.clear((1., 1., 1., 1.), 0.5, 1) gloo.flush() gloo.finish() # check some results assert_array_equal(gloo.get_parameter('viewport'), viewport) assert_equal(gloo.get_parameter('front_face'), gl.GL_CW) assert_equal(gloo.get_parameter('blend_color'), blend_color + (1,))
def draw(self): gloo.clear(self.background_color) if self.measuring: self.measure_line.draw() if self.show_spikes and len(self.spike_data) > 0: self.point_program.draw('points') self.strip_program.draw('line_strip') self.scale_bar.draw() self.scale_label.draw()
def on_draw(self, event): # Render in the FBO. with self._fbo: gloo.clear((1,1,1,1)) gloo.set_viewport(0, 0, *self.true_size) self.program.draw(gl.GL_TRIANGLE_STRIP) # Retrieve the contents of the FBO texture. self.shadowsArray = _screenshot((0, 0, self.true_size[0], self.true_size[1])) # Immediately exit the application. app.quit()
def on_draw(self, event): with self.framebuffer: set_viewport(0, 0, 512, 512) clear(color=True, depth=True) set_state(depth_test=True) self.cube.draw('triangles', self.indices) set_viewport(0, 0, *self.size) clear(color=True) set_state(depth_test=False) self.quad.draw('triangle_strip')
def on_draw(self, event): gloo.set_viewport(0, 0, *self.size) gloo.clear(color=True, depth=True) self.rendering_world.draw(self.view)
def on_draw(event): gloo.clear((1, 1, 1, 1)) program.draw('line_strip')
def on_draw(self, ev): gloo.clear('black', depth=True) gloo.set_viewport(0, 0, *self.physical_size) for line in self.lines: line.draw(line.tr_sys)
def on_draw(e): gloo.clear('white') polys.draw() paths.draw()
def on_draw(self, event): gloo.clear() self.program.draw('line_strip')
def on_draw(self, event): clear(color=True, depth=True) self.image.draw('triangle_strip') self.lines.draw('line_strip')
def on_draw(self, ev): gloo.clear(color='black', depth=True) gloo.set_viewport(0, 0, *self.physical_size) # Create a TransformSystem that will tell the visual how to draw for img in self.images: img.draw(img.tr_sys)
def on_draw(self, event): gloo.clear('black') gloo.set_viewport(0, 0, *self.physical_size) for visual in self.visuals: visual.draw(visual.tr_sys)
def clear(self): gloo.clear(color=True, depth=True)
def on_draw(self, event): gloo.clear() self.program.draw('points') self.program_e.draw('lines', self.index)
def on_draw(event): gloo.set_clear_color((0.2, 0.4, 0.6, 1.0)) gloo.clear()
def on_draw(self, event): # clear the color buffer gloo.clear(color="white") for bar in self.bars: bar.draw(self.transform_sys)
def on_draw(self, event): gloo.clear('black') self.axis_x.draw() self.axis_y.draw() self.line.draw()
def _on_draw(self, event): gloo.clear() self._render_program.draw(gloo.gl.GL_TRIANGLE_STRIP)
def draw(self): gloo.clear((0.0, 0.0, 0.0, 1)) self.outline.draw(self.canvas.tr_sys) self.program.draw('triangles')
def on_draw(self, event): gloo.set_viewport(0, 0, *self.size) gloo.clear('white') self.tr_sys.auto_configure() self.cube.draw(self.tr_sys)
def on_draw(self, event): gloo.set_viewport(0, 0, *self.physical_size) gloo.clear('white', depth=True) self.cube.draw()
def on_draw(self, event): #Read about depth testing and changing stated in vispy here http://vispy.org/gloo.html?highlight=set_state gloo.clear(color=[0, 0, 0, 1.0], depth=True) #delta_time self.current_frame = time() self.delta_time = self.current_frame - self.last_frame self.last_frame = self.current_frame if self.camera.bool_a: self.camera.ProcessKeyboard(Camera_Movement.LEFT, self.delta_time) if self.camera.bool_w: self.camera.ProcessKeyboard(Camera_Movement.FORWARD, self.delta_time) if self.camera.bool_s: self.camera.ProcessKeyboard(Camera_Movement.BACKWARD, self.delta_time) if self.camera.bool_d: self.camera.ProcessKeyboard(Camera_Movement.RIGHT, self.delta_time) self.view = self.camera.GetViewMatrix() self.projection = glm.perspective(glm.radians(self.camera.Zoom), builtins.width / builtins.height, 0.1, 100.0) # vispy takes numpy array in m * n matrix form self.view = (np.array(self.view.to_list()).astype(np.float32)) self.projection = (np.array(self.projection.to_list()).astype( np.float32)) # reshaping to (m, n) to (1, m*n) to support data input in vispy self.view = self.view.reshape( (1, self.view.shape[0] * self.view.shape[1])) self.projection = self.projection.reshape( (1, self.projection.shape[0] * self.projection.shape[1])) self.model = glm.mat4(1.0) self.model = glm.translate(self.model, self.cubePositions[1]) self.model = (np.array(self.model.to_list()).astype(np.float32)) self.model = self.model.reshape( (1, self.model.shape[0] * self.model.shape[1])) self.programLightSource['model'] = self.model self.programLightSource['view'] = self.view self.programLightSource['projection'] = self.projection self.programLightSource['a_position'] = self.vertices self.programLightSource.draw('triangles') # drawing second cube self.program['view'] = self.view self.program['projection'] = self.projection self.program['a_position'] = self.vertices self.program['objectColor'] = [1, 0.5, 0.31] self.program['lightColor'] = [1, 1, 1] self.model = glm.mat4(1.0) self.model = glm.translate(self.model, self.cubePositions[0]) self.model = (np.array(self.model.to_list()).astype(np.float32)) self.model = self.model.reshape( (1, self.model.shape[0] * self.model.shape[1])) self.program['model'] = self.model self.program.draw('triangles') self.update()
def on_draw(self, event): gloo.clear(color=True, depth=True) self.program.draw('triangles', self.indices)
def on_draw(self, event): gloo.clear() self.program_v.draw('triangle_strip') self.program_s.draw('points')
def on_draw(self, ev): gloo.clear('black', depth=True) for line in self.lines: line.draw()
def on_draw(self, event): gloo.clear(color=True, depth=True)
def draw_bounding_boxes(self): program = gloo.Program(_bounding_box_vertex_code, _bounding_box_fragment_code) program['u_light_eye_pos'] = [0, 0, 0] program['u_light_ambient_w'] = self.ambient_weight # Texture where we render the scene render_tex = gloo.Texture2D(shape=self.shape + (4, ), format=gl.GL_RGBA, internalformat=gl.GL_RGBA) # Frame buffer object fbo = gloo.FrameBuffer(render_tex, gloo.RenderBuffer(self.shape)) with fbo: gloo.set_state(depth_test=True) gloo.set_state(cull_face=True) gloo.set_state(blend=True) gloo.set_state(blend_func=('src_alpha', 'one_minus_src_alpha')) gloo.set_cull_face('back') # Back-facing polygons will be culled gloo.set_clear_color(self.bg_color) gloo.clear(color=True, depth=True) gloo.set_viewport(0, 0, *self.size) for i in range(len(self.vertex_buffers)): self.mat_view = compute_view_matrix(self.poses[i]['R'], self.poses[i]['t']) program['u_mv'] = _compute_model_view(self.mat_model, self.mat_view) # program['u_nm'] = compute_normal_matrix(self.model, self.view) program['u_mvp'] = _compute_model_view_proj( self.mat_model, self.mat_view, self.mat_proj) #program.bind(self.vertex_buffers[i]) #program.draw('triangles', self.index_buffers[i]) model = self.models[i] vertices = model['vertices'] x_max = np.amax(vertices['a_position'][:, 0]) x_min = np.amin(vertices['a_position'][:, 0]) y_max = np.amax(vertices['a_position'][:, 1]) y_min = np.amin(vertices['a_position'][:, 1]) z_max = np.amax(vertices['a_position'][:, 2]) z_min = np.amin(vertices['a_position'][:, 2]) line_vertices = [ # First side of the cube [x_max, y_min, z_max], [x_max, y_min, z_min], [x_min, y_min, z_min], [x_min, y_min, z_max], [x_max, y_min, z_max], # Side wall of the cube [x_max, y_max, z_max], [x_max, y_max, z_min], [x_max, y_min, z_min], [x_max, y_max, z_min], # Next side wall [x_max, y_max, z_min], [x_min, y_max, z_min], [x_min, y_min, z_min], [x_min, y_max, z_min], # Next side wall [x_min, y_max, z_max], [x_min, y_min, z_max], [x_min, y_max, z_max], [x_max, y_max, z_max] ] program['a_position'] = gloo.VertexBuffer(line_vertices) program['a_color'] = gloo.VertexBuffer( np.tile(vertices['a_color'][0], [len(line_vertices), 1])) gl.glLineWidth(10) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) program.draw('line_strip') self.retrieve_bounding_boxes()
def on_draw(self, ev): gloo.clear(color='w', depth=True) for vis in self.visuals: vis.draw()
def clear(self, color=True, depth=True): """Clear the renderer background.""" gloo.set_state(clear_color=self.style.background_color) # pylint: disable=no-member gloo.clear(color=color, depth=depth) # pylint: disable=no-member
def on_draw(self, event): gloo.clear(color=(0.0, 0.0, 0.0, 1.0)) self.program.draw('line_strip')
def on_draw(self, event): gloo.clear('black') # gloo.clear(color='white') self.program.draw('points') self.text.draw()
def on_draw(self, event): gloo.clear() self.program.draw('points')
def on_draw(self, event): gloo.clear('black') for visual in self.visuals: visual.draw()
def draw(self): gloo.clear((0.5, 0.5, 0.5, 1)) self.program.draw('line_strip') self.grid.draw(self.canvas.tr_sys)