How to use the vispy.gloo.Program 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 / examples / basics / gloo / rotate_cube.py View on Github external
def __init__(self):
        app.Canvas.__init__(self, keys='interactive')
        self.size = 800, 600

        self.vertices, self.filled, self.outline = cube()
        self.filled_buf = gloo.IndexBuffer(self.filled)
        self.outline_buf = gloo.IndexBuffer(self.outline)

        self.program = gloo.Program(vert, frag)
        self.program.bind(gloo.VertexBuffer(self.vertices))

        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        translate(self.view, 0, 0, -5)
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view

        self.theta = 0
        self.phi = 0

        gloo.set_clear_color('white')
        gloo.set_state('opaque')
        gloo.set_polygon_offset(1, 1)
github vispy / vispy / examples / basics / gloo / multi_texture.py View on Github external
def __init__(self):
        app.Canvas.__init__(self, size=(500, 500), keys='interactive')

        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self.program['u_tex1'] = gloo.Texture2D(im1, interpolation='linear')
        self.program['u_tex2'] = gloo.Texture2D(im2, interpolation='linear')
        self.program.bind(gloo.VertexBuffer(data))

        gloo.set_clear_color('white')

        self.show()
github alexandrebarachant / muse-lsl / muselsl / viewer_v2.py View on Github external
# Various signal amplitudes.
        amplitudes = np.zeros((m, n)).astype(np.float32)
        # gamma = np.ones((m, n)).astype(np.float32)
        # Generate the signals as a (m, n) array.
        y = amplitudes

        color = color_palette("RdBu_r", n_rows)

        color = np.repeat(color, n, axis=0).astype(np.float32)
        # Signal 2D index of each vertex (row and col) and x-index (sample index
        # within each signal).
        index = np.c_[np.repeat(np.repeat(np.arange(n_cols), n_rows), n),
                      np.repeat(np.tile(np.arange(n_rows), n_cols), n),
                      np.tile(np.arange(n), m)].astype(np.float32)

        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self.program['a_position'] = y.reshape(-1, 1)
        self.program['a_color'] = color
        self.program['a_index'] = index
        self.program['u_scale'] = (1., 1.)
        self.program['u_size'] = (n_rows, n_cols)
        self.program['u_n'] = n

        # text
        self.font_size = 48.
        self.names = []
        self.quality = []
        for ii in range(self.n_chans):
            text = visuals.TextVisual(ch_names[ii], bold=True, color='white')
            self.names.append(text)
            text = visuals.TextVisual('', bold=True, color='white')
            self.quality.append(text)
github vispy / vispy / examples / demo / gloo / shadertoy.py View on Github external
def __init__(self, shadertoy=None):
        app.Canvas.__init__(self, keys='interactive')
        if shadertoy is None:
            shadertoy = """
            void main(void)
            {
                vec2 uv = gl_FragCoord.xy / iResolution.xy;
                gl_FragColor = vec4(uv,0.5+0.5*sin(iGlobalTime),1.0);
            }"""
        self.program = gloo.Program(vertex, fragment % shadertoy)

        self.program["position"] = [(-1, -1), (-1, 1), (1, 1),
                                    (-1, -1), (1, 1), (1, -1)]
        self.program['iMouse'] = 0, 0, 0, 0

        self.program['iSampleRate'] = 44100.
        for i in range(4):
            self.program['iChannelTime[%d]' % i] = 0.
        self.program['iGlobalTime'] = 0.

        self.activate_zoom()

        self._timer = app.Timer('auto', connect=self.on_timer, start=True)

        self.show()
github p5py / p5 / p5 / sketch / renderer2d.py View on Github external
vertices = np.array([[-1.0, -1.0],
							 [+1.0, -1.0],
							 [-1.0, +1.0],
							 [+1.0, +1.0]],
							np.float32)
		texcoords = np.array([[0.0, 0.0],
							  [1.0, 0.0],
							  [0.0, 1.0],
							  [1.0, 1.0]],
							 dtype=np.float32)

		self.fbuf_vertices = VertexBuffer(data=vertices)
		self.fbuf_texcoords = VertexBuffer(data=texcoords)

		self.fbuffer_prog = Program(src_fbuffer.vert, src_fbuffer.frag)
		self.fbuffer_prog['texcoord'] = self.fbuf_texcoords
		self.fbuffer_prog['position'] = self.fbuf_vertices

		self.vertex_buffer = VertexBuffer()
		self.index_buffer = IndexBuffer()

		self.default_prog = Program(src_default.vert, src_default.frag)
		self.texture_prog = Program(src_texture.vert, src_texture.frag)
		self.texture_prog['texcoord'] = self.fbuf_texcoords

		self.reset_view()
github vispy / vispy / examples / demo / gloo / show_markers.py View on Github external
def __init__(self):
        app.Canvas.__init__(self, keys='interactive')

        # This size is used for comparison with agg (via matplotlib)
        self.size = 512, 512 + 2 * 32
        self.title = "Markers demo [press space to change marker]"

        self.vbo = VertexBuffer(data)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = ortho(0, self.size[0], 0, self.size[1], -1, 1)
        self.programs = [
            Program(markers.vert, markers.frag + markers.tailed_arrow),
            Program(markers.vert, markers.frag + markers.disc),
            Program(markers.vert, markers.frag + markers.diamond),
            Program(markers.vert, markers.frag + markers.square),
            Program(markers.vert, markers.frag + markers.cross),
            Program(markers.vert, markers.frag + markers.arrow),
            Program(markers.vert, markers.frag + markers.vbar),
            Program(markers.vert, markers.frag + markers.hbar),
            Program(markers.vert, markers.frag + markers.clobber),
            Program(markers.vert, markers.frag + markers.ring)]

        for program in self.programs:
            program.bind(self.vbo)
            program["u_antialias"] = u_antialias,
            program["u_size"] = 1
            program["u_model"] = self.model
            program["u_view"] = self.view
            program["u_projection"] = self.projection
        self.index = 0
        self.program = self.programs[self.index]
github vispy / vispy / examples / basics / gloo / split_screen.py View on Github external
def __init__(self, bgcolor):
        self._bgcolor = bgcolor
        self.events = EmitterGroup(source=self,
                                   resize=app.canvas.ResizeEvent,
                                   mouse_press=app.canvas.MouseEvent,
                                   mouse_release=app.canvas.MouseEvent,
                                   mouse_move=app.canvas.MouseEvent,
                                   mouse_wheel=app.canvas.MouseEvent)

        # Create program
        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self.program['u_size'] = 20.0
        self.program['u_color'] = bgcolor

        # Create position
        self.vbo = gloo.VertexBuffer(dtype=np.float32)
        self.program['a_position'] = self.vbo

        # Init
        self._pos = 25, 25
        self._size = 1, 1
github vispy / vispy / examples / basics / gloo / gpuimage.py View on Github external
def __init__(self):
        app.Canvas.__init__(self, position=(300, 100),
                            size=(800, 800), keys='interactive')

        self.program = gloo.Program(vertex, fragment)
        self.program['a_position'] = [(-1., -1.), (-1., +1.),
                                      (+1., -1.), (+1., +1.)]

        self.program['u_time'] = 0.0
        self.timer = app.Timer('auto', connect=self.on_timer, start=True)

        self.show()
github spyking-circus / spyking-circus-ort / circusort / block / qt_displayer.py View on Github external
def __init__(self):

        app.Canvas.__init__(self, title="Vispy canvas", keys="interactive")

        self.program = gloo.Program(vert=VERT_SHADER, frag=FRAG_SHADER)
        self.program['a_position'] = y.reshape(-1, 1)
        self.program['a_color'] = color
        self.program['a_index'] = index
        self.program['u_scale'] = (1.0, 0.01)
        self.program['u_size'] = (nrows, ncols)
        self.program['u_n'] = n

        self.program_bis = gloo.Program(vert=VERT_SHADER_BIS, frag=FRAG_SHADER_BIS)
        self.program_bis['a_index'] = index_bis
        self.program_bis['u_scale'] = (1.0, 1.0)
        self.program_bis['u_size'] = (nrows, ncols)

        gloo.set_viewport(0, 0, *self.physical_size)

        # self._timer = app.Timer('auto', connect=self.on_timer, start=True)
github vispy / vispy / examples / texturing.py View on Github external
def __init__(self):
        app.Canvas.__init__(self)
        
        # Create program
        self._program = Program(VERT_SHADER, FRAG_SHADER)
        
        # Set uniforms and samplers
        self._program['a_position'] = VertexBuffer(positions)
        self._program['a_texcoord'] = VertexBuffer(texcoords)
        #
        self._program['u_texture1'] = Texture2D(im1)
        self._program['u_texture2'] = Texture2D(im2)
        self._program['u_texture3'] = Texture2D(im3)