本文整理汇总了Python中vispy.gloo.set_viewport函数的典型用法代码示例。如果您正苦于以下问题:Python set_viewport函数的具体用法?Python set_viewport怎么用?Python set_viewport使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_viewport函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_zoom
def apply_zoom(self):
width, height = self.physical_size
gloo.set_viewport(0, 0, width, height)
self.fractal['resolution'] = [width, height]
self.skeleton_bones['resolution'] = [width, height]
self.mask['resolution'] = [width, height]
示例2: __init__
def __init__(self):
app.Canvas.__init__(self, size=(512, 512), title='scaling quad',
keys='interactive')
# program with 4 vertices
program = gloo.Program(vert=vertex, frag=fragment, count=4)
# bind data
program['a_position'] = [(-1, -1), (-1, 1), (1, -1), (1, 1)]
program['color'] = [(1, 0, 0, 1),
(0, 1, 0, 1),
(0, 0, 1, 1),
(1, 1, 0, 1)]
program['scale'] = 1.0
self.program = program
# set viewport
gloo.set_viewport(0, 0, *self.physical_size)
# bind a timer
self.timer = app.Timer('auto', self.on_timer)
self.clock = 0.0
self.timer.start()
# show the canvas
self.show()
示例3: __init__
def __init__(self):
app.Canvas.__init__(self, keys='interactive', size=(W, H))
self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
# Set uniform and attribute
self.program['a_id'] = gloo.VertexBuffer(a_id)
self.program['a_position'] = gloo.VertexBuffer(a_position)
self.translate = 5
self.view = translate((0, 0, -self.translate), dtype=np.float32)
self.model = np.eye(4, dtype=np.float32)
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]), 1.0, 1000.0)
self.program['u_projection'] = self.projection
self.program['u_model'] = self.model
self.program['u_view'] = self.view
self.theta = 0
self.phi = 0
self.context.set_clear_color('white')
self.context.set_state('translucent')
self.timer = app.Timer('auto', connect=self.on_timer)
self.show()
示例4: resize
def resize(self, width, height):
gloo.set_viewport(0, 0, width, height)
data_width = self._data_lim[0][1] - self._data_lim[0][0]
data_height = self._data_lim[1][1] - self._data_lim[1][0]
data_aspect = data_width / float(data_height)
frame_aspect = width / float(height)
if frame_aspect >= data_aspect:
padding = (frame_aspect * data_height - data_width) / 2.
frame_lim = [
[self._data_lim[0][0] - padding,
self._data_lim[0][1] + padding],
[self._data_lim[1][0],
self._data_lim[1][1]]]
else:
padding = (data_width / frame_aspect - data_height) / 2.
frame_lim = [
[self._data_lim[0][0],
self._data_lim[0][1]],
[self._data_lim[1][0] - padding,
self._data_lim[1][1] + padding]]
args_ortho = frame_lim[0][::(1 if self._dir_x_right else -1)]
args_ortho += frame_lim[1][::(1 if self._dir_y_top else -1)]
args_ortho += -1000, 1000
self.projection = ortho(*args_ortho)
self.program['projection'] = self.projection
示例5: on_resize
def on_resize(self, event):
width, height = event.size
gloo.set_viewport(0, 0, width, height)
self.projection = ortho(0, width, 0, height, -100, 100)
self.u_size = width / 512.0
self.program['u_projection'] = self.projection
self.program['u_size'] = self.u_size
示例6: test_text
def test_text():
"""Test basic text support"""
# test a simple cases
data = (np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0]]) * 255).astype(np.uint8)
expd = (np.array([[8, 5, 4, 4, 4, 4, 4, 5, 8],
[5, 2, 1, 1, 1, 1, 1, 2, 5],
[4, 1, 0, 0, 0, 0, 0, 1, 4],
[4, 1, 0, -1, -4, -1, 0, 1, 4], # XXX artifact
[4, 1, 0, -1, -4, -1, 0, 1, 4],
[4, 1, 0, -1, -4, -1, 0, 1, 4]]))
expd = 0.5 - (np.sqrt(np.abs(expd)) * np.sign(expd)) / 256. * 8
expd = np.round(256 * expd).astype(np.int)
with Canvas(size=(100, 100)):
tex = gloo.Texture2D(shape=data.shape, dtype=np.ubyte, format='rgb')
SDFRenderer().render_to_texture(data, tex, (0, 0), data.shape[::-1])
gloo.set_viewport(0, 0, *data.shape[::-1])
gloo.util.draw_texture(tex)
result = gloo.util._screenshot()[:, :, 0].astype(np.int)
print(result)
print(expd)
assert_allclose(result, expd, atol=1)
示例7: on_draw
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()
示例8: __init__
def __init__(self):
app.Canvas.__init__(self, size=(1024, 1024), title='Skybox example',
keys='interactive')
self.cubeSize = 10
self.pressed = False
self.azimuth = pi / 2.0
self.elevation = pi / 2.0
self.distanceMin = 1
self.distanceMax = 50
self.distance = 30
self.sensitivity = 5.0
self.view = getView(self.azimuth, self.elevation, self.distance)
self.model = np.eye(4, dtype=np.float32)
self.projection = np.eye(4, dtype=np.float32)
self.program = gloo.Program(vertex_shader, fragment_shader, count=24)
self.program['a_position'] = faces*self.cubeSize
self.program['a_texcoord'] = faces
self.program['a_texture'] = gloo.TextureCube(texture, interpolation='linear')
self.program['u_model'] = self.model
self.program['u_view'] = self.view
gloo.set_viewport(0, 0, *self.physical_size)
self.projection = perspective(60.0, self.size[0] /
float(self.size[1]), 1.0, 100.0)
self.program['u_projection'] = self.projection
gl.glEnable(gl.GL_DEPTH_TEST)
gloo.set_clear_color('black')
self.show()
示例9: on_draw
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()
示例10: __init__
def __init__(self):
app.Canvas.__init__(self, size=(512, 512),
keys='interactive')
self.image = Program(image_vertex, image_fragment, 4)
self.image['position'] = (-1, -1), (-1, +1), (+1, -1), (+1, +1)
self.image['texcoord'] = (0, 0), (0, +1), (+1, 0), (+1, +1)
self.image['vmin'] = +0.0
self.image['vmax'] = +1.0
self.image['cmap'] = 0 # Colormap index to use
self.image['colormaps'] = colormaps
self.image['n_colormaps'] = colormaps.shape[0]
self.image['image'] = I.astype('float32')
self.image['image'].interpolation = 'linear'
set_viewport(0, 0, *self.physical_size)
self.lines = Program(lines_vertex, lines_fragment)
self.lines["position"] = np.zeros((4+4+514+514, 2), np.float32)
color = np.zeros((4+4+514+514, 4), np.float32)
color[1:1+2, 3] = 0.25
color[5:5+2, 3] = 0.25
color[9:9+512, 3] = 0.5
color[523:523+512, 3] = 0.5
self.lines["color"] = color
set_state(clear_color='white', blend=True,
blend_func=('src_alpha', 'one_minus_src_alpha'))
self.show()
示例11: on_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)
示例12: on_resize
def on_resize(self, event):
width, height = event.size
self.width=width
self.height=height
gloo.set_viewport(0, 0, width, height)
self.projection = ortho(-self.scale/2, self.scale/2, -self.scale/2, self.scale/2, -1, 100) #perspective(1.0, width / float(height), 1.0, 10000000.0)
self.program['u_projection'] = self.projection
示例13: on_draw
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()
示例14: test_use_framebuffer
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)
示例15: activate_zoom
def activate_zoom(self):
self.width, self.height = self.size
gloo.set_viewport(0, 0, *self.physical_size)
vp = (0, 0, self.physical_size[0], self.physical_size[1])
gui.configure(canvas=self, viewport=vp)
cars.configure(canvas=self, viewport=vp)
field.set_needs_display()