How to use the vispy.gloo function in vispy

To help you get started, we’ve selected a few vispy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vispy / vispy / doc / ext / gloooverviewgenerator.py View on Github external
def get_docs_for_class(klass):
    """ Get props and methods for a class.
    """

    # Prepare
    baseatts = dir(gloo.GLObject)
    functype = type(gloo.GLObject.delete)
    proptype = type(gloo.GLObject.id)
    props, funcs = set(), set()

    for att in sorted(dir(klass)):
        if att.startswith('_') or att.lower() != att:
            continue
        # Get ob and module name
        attob = getattr(klass, att)
        modulename = klass.__module__.split('.')[-1]
        # Get actual klass
        actualklass = klass
        while True:
            tmp = actualklass.__base__
            if att in dir(tmp):
                actualklass = tmp
            else:
                break
github p5py / p5 / p5 / sketch / renderer2d.py View on Github external
def clear(self, color=True, depth=True):
		"""Clear the renderer background."""
		gloo.set_state(clear_color=self.background_color)
		gloo.clear(color=color, depth=depth)
github EtienneCmb / visbrain / visbrain / visuals / PicVisual.py View on Github external
# Select pictures :
        if isinstance(select, (list, np.ndarray)):
            data = data[select, ...]
            pos = pos[select, ...]

        # Check data and get vertices and faces :
        self._check_data(data, pos)

        # Get vertices and faces :
        a_position = self._data_to_pos(pos)
        faces, grid = self._get_index()

        # Define index and position buffers :
        self._index_buffer = gloo.IndexBuffer(faces)
        self._pos_buffer = gloo.VertexBuffer(a_position)
        self.shared_program.vert['a_position'] = self._pos_buffer

        # Re-order data :
        self._data = data.ravel()[np.argsort(grid.ravel())]
        self._data_buffer = gloo.VertexBuffer(vispy_array(self._data))
        self.shared_program.vert['a_data'] = self._data_buffer
        # Define the color buffer :
        self.shared_program.frag['u_alpha'] = alpha
        self.alpha = alpha
        self.set_data(**kwargs)

        # Define drawing mode :
        self._draw_mode = 'triangles'
github vispy / vispy / examples / tutorial / app / app_sdl2.py View on Github external
def on_draw(self, event):
        print('on_draw')
        gloo.clear(color=True, depth=True)
github vispy / vispy / examples / demo / gloo / mandelbrot.py View on Github external
def apply_zoom(self):
        width, height = self.physical_size
        gloo.set_viewport(0, 0, width, height)
        self.program['resolution'] = [width, height]
github vispy / vispy / examples / basics / visuals / line_visual2.py View on Github external
def __init__(self, parent=None, data=None, color=None):
        Visual.__init__(self, parent)
        
        # Create a program
        self._program = ModularProgram(vertex_template, fragment_template)
        
        # Define how we are going to specify position and color
        self._program.vert['gl_Position'] = '$transform(vec4($position, 1.0))'
        self._program.frag['gl_FragColor'] = 'vec4($color, 1.0)'
        
        # Set position data
        assert data is not None
        vbo = gloo.VertexBuffer(data)
        self._program.vert['position'] = vbo
        
        self._program.vert['transform'] = self.transform.shader_map()
        
        # Create some variables related to color. We use a combination
        # of these depending on the kind of color being set.
        # We predefine them here so that we can re-use VBO and uniforms
        vbo = gloo.VertexBuffer(data)
        self._color_var = Variable('uniform vec3 color')
        self._colors_var = Variable('attribute vec3 color', vbo)
        self._color_varying = Varying('v_color')
        
        self.set_color((0, 0, 1))
        if color is not None:
            self.set_color(color)
github vispy / vispy / examples / demo / gloo / graph.py View on Github external
('a_size', np.float32, 1),
                                  ('a_linewidth', np.float32, 1),
                                  ])
        edges = np.random.randint(size=(ne, 2), low=0,
                                  high=n).astype(np.uint32)
        data['a_position'] = np.hstack((.25 * np.random.randn(n, 2),
                                       np.zeros((n, 1))))
        data['a_fg_color'] = 0, 0, 0, 1
        color = np.random.uniform(0.5, 1., (n, 3))
        data['a_bg_color'] = np.hstack((color, np.ones((n, 1))))
        data['a_size'] = np.random.randint(size=n, low=8*ps, high=20*ps)
        data['a_linewidth'] = 1.*ps
        u_antialias = 1

        self.vbo = gloo.VertexBuffer(data)
        self.index = gloo.IndexBuffer(edges)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        self.program = gloo.Program(vert, frag)
        self.program.bind(self.vbo)
        self.program['u_size'] = 1
        self.program['u_antialias'] = u_antialias
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_projection'] = self.projection

        set_viewport(0, 0, *self.physical_size)

        self.program_e = gloo.Program(vs, fs)
        self.program_e.bind(self.vbo)
github vispy / vispy / examples / basics / gloo / hello_fbo.py View on Github external
def __init__(self):
        app.Canvas.__init__(self, keys='interactive', size=(560, 420))

        # Create texture to render to
        shape = self.physical_size[1], self.physical_size[0]
        self._rendertex = gloo.Texture2D((shape + (3,)))

        # Create FBO, attach the color buffer and depth buffer
        self._fbo = gloo.FrameBuffer(self._rendertex, gloo.RenderBuffer(shape))

        # Create program to render a shape
        self._program1 = gloo.Program(VERT_SHADER1, FRAG_SHADER1)
        self._program1['u_color'] = 0.9, 1.0, 0.4, 1
        self._program1['a_position'] = gloo.VertexBuffer(vPosition)

        # Create program to render FBO result
        self._program2 = gloo.Program(VERT_SHADER2, FRAG_SHADER2)
        self._program2['a_position'] = gloo.VertexBuffer(vPosition)
        self._program2['a_texcoord'] = gloo.VertexBuffer(vTexcoord)
        self._program2['u_texture1'] = self._rendertex

        self.show()
github vispy / vispy / examples / tutorial / visuals / T02_measurements.py View on Github external
self.vert_buffer = gloo.VertexBuffer(np.array([
            [x, y], 
            [x, y], 
            [x+w, y], 
            [x+w, y], 
            [x+w, y+h],
            [x+w, y+h],
            [x, y+h],
            [x, y+h],
            [x, y], 
            [x, y], 
        ], dtype=np.float32))
        
        # Direction each vertex should move to correct for line width
        # (the length of this vector will be corrected in the shader)
        self.adj_buffer = gloo.VertexBuffer(np.array([
            [0, 0],
            [1, 1],
            [0, 0],
            [-1, 1],
            [0, 0],
            [-1, -1],
            [0, 0],
            [1, -1],
            [0, 0],
            [1, 1],
        ], dtype=np.float32))
        
        self.shared_program.vert['position'] = self.vert_buffer
        self.shared_program.vert['adjust_dir'] = self.adj_buffer
        self.shared_program.vert['line_width'] = weight
        self.shared_program.frag['color'] = (1, 0, 0, 1)