How to use the vispy.gloo.set_viewport 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 genicam / harvesters / frontend / canvas.py View on Github external
def apply_magnification(self):
        #
        canvas_w, canvas_h = self.physical_size
        gloo.set_viewport(0, 0, canvas_w, canvas_h)

        #
        ratio = self._magnification
        w, h = self._width, self._height

        self._program['u_projection'] = ortho(
            self._coordinate[0],
            canvas_w * ratio + self._coordinate[0],
            self._coordinate[1],
            canvas_h * ratio + self._coordinate[1],
            -1, 1
        )

        x, y = int((canvas_w * ratio - w) / 2), int((canvas_h * ratio - h) / 2)  # centering x & y

        #
github p5py / p5 / p5 / sketch / renderer3d.py View on Github external
def draw_loop(self):
		"""The main draw loop context manager.
		"""

		self.transform_matrix = np.identity(4)

		self.default_prog['projection'] = self.projection_matrix.T.flatten()
		self.default_prog['perspective_matrix'] = self.lookat_matrix.T.flatten()

		self.fbuffer.color_buffer = self.fbuffer_tex_back

		with self.fbuffer:
			gloo.set_viewport(*self.texture_viewport)
			self._comm_toggles()
			self.fbuffer_prog['texture'] = self.fbuffer_tex_front
			self.fbuffer_prog.draw('triangle_strip')

			yield

			self.flush_geometry()
			self.transform_matrix = np.identity(4)

		gloo.set_viewport(*self.viewport)
		self._comm_toggles(False)
		self.clear()
		self.fbuffer_prog['texture'] = self.fbuffer_tex_back
		self.fbuffer_prog.draw('triangle_strip')

		self.fbuffer_tex_front, self.fbuffer_tex_back = self.fbuffer_tex_back, self.fbuffer_tex_front
github vispy / vispy / examples / collections / polygon_collection.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vispy: testskip

import numpy as np
from vispy import app, gloo
from vispy.visuals.collections import PathCollection, PolygonCollection


canvas = app.Canvas(size=(800, 800), show=True, keys='interactive')
gloo.set_viewport(0, 0, canvas.size[0], canvas.size[1])
gloo.set_state("translucent", depth_test=False)


def star(inner=0.5, outer=1.0, n=5):
    R = np.array([inner, outer] * n)
    T = np.linspace(0, 2 * np.pi, 2 * n, endpoint=False)
    P = np.zeros((2 * n, 3))
    P[:, 0] = R * np.cos(T)
    P[:, 1] = R * np.sin(T)
    return P

paths = PathCollection("agg", color='shared')
polys = PolygonCollection("raw", color='shared')

P = star()
github ssec / sift / sift / view / MapWidget.py View on Github external
def update_proj(self, event=None):
        if event is not None:
            gloo.set_viewport(0, 0, *event.physical_size)
        else:
            gloo.set_viewport(0, 0, self.physical_size[0], self.physical_size[1])
        vp = self.viewport
        # self.projection = perspective(45.0, self.size[0] /
        #                               float(self.size[1]), 2.0, 10.0)
        aspect = float(self.size[1]) / float(self.size[0])
        #self.projection = ortho(-4, 4, -4*aspect, 4*aspect, -10, 10)
        # FIXME: Z is backwards from documentation based on results. Negative first, positive second makes Z positive towards the viewer
        self.projection = ortho(
            vp.l, vp.r,
            vp.b, vp.t,
            -10000000, 10000000
        )
        if self._testtile:
            self._testtile.set_mvp(projection=self.projection)
github vispy / vispy / examples / tutorial / gloo / textured_cube.py View on Github external
def activate_zoom(self):
        gloo.set_viewport(0, 0, *self.physical_size)
        projection = perspective(45.0, self.size[0] / float(self.size[1]),
                                 2.0, 10.0)
        self.program['projection'] = projection
github vispy / vispy / examples / demo / gloo / rain.py View on Github external
def activate_zoom(self):
        gloo.set_viewport(0, 0, *self.physical_size)
        projection = ortho(0, self.size[0], 0,
                           self.size[1], -1, +1)
        self.program['u_projection'] = projection
github vispy / vispy / examples / demo / gloo / boids.py View on Github external
self.boids['size'] = 4*ps
        self.boids['color'] = 1, 1, 1, 1

        self.target['size'] = 16*ps
        self.target['color'][:] = 1, 1, 0, 1
        self.predator['size'] = 16*ps
        self.predator['color'][:] = 1, 0, 0, 1
        self.target['position'][:] = 0.25, 0.0, 0

        # Time
        self._t = time.time()
        self._pos = 0.0, 0.0
        self._button = None

        width, height = self.physical_size
        gloo.set_viewport(0, 0, width, height)

        # Create program
        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)

        # Create vertex buffers
        self.vbo_position = gloo.VertexBuffer(self.particles['position']
                                              .copy())
        self.vbo_color = gloo.VertexBuffer(self.particles['color'].copy())
        self.vbo_size = gloo.VertexBuffer(self.particles['size'].copy())

        # Bind vertex buffers
        self.program['color'] = self.vbo_color
        self.program['size'] = self.vbo_size
        self.program['position'] = self.vbo_position

        gloo.set_state(clear_color=(0, 0, 0, 1), blend=True,
github vispy / vispy / examples / demo / gloo / glsl_sandbox_cube.py View on Github external
def apply_zoom(self):
        gloo.set_viewport(0, 0, self.physical_size[0], self.physical_size[1])
        self.projection = perspective(45.0, self.size[0] /
                                      float(self.size[1]), 2.0, 10.0)
        self.program['u_projection'] = self.projection
github vispy / vispy / examples / demo / gloo / voronoi.py View on Github external
def activate_zoom(self):
        self.width, self.height = self.size
        gloo.set_viewport(0, 0, *self.physical_size)
        self.program_v['u_screen'] = self.physical_size
github vispy / vispy / examples / basics / gloo / post_processing.py View on Github external
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.physical_size)
        clear(color=True)
        set_state(depth_test=False)
        self.quad.draw('triangle_strip')