本文整理汇总了Python中vispy.gloo.gl.glViewport函数的典型用法代码示例。如果您正苦于以下问题:Python glViewport函数的具体用法?Python glViewport怎么用?Python glViewport使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了glViewport函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw00
def draw00(event):
print(" {0:7}: {1}".format("0", bgcolors[0]))
if bgcolors[0] is not None:
gl.glViewport(0, 0, *list(_win_size))
gl.glClearColor(*bgcolors[0])
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
gl.glFinish()
示例2: draw11
def draw11(event):
print(' {0:7}: {1}'.format('1', bgcolors[1]))
if bgcolors[1] is not None:
gl.glViewport(0, 0, *list(_win_size))
gl.glClearColor(*bgcolors[1])
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
gl.glFinish()
示例3: _test_functonality
def _test_functonality(backend):
""" Create app and canvas so we have a context. Then run tests.
"""
# use the backend
gl.use_gl(backend)
with Canvas() as canvas:
_clear_screen()
# Prepare
w, h = canvas.size
gl.glViewport(0, 0, w, h)
gl.glScissor(0, 0, w, h) # touch
gl.glClearColor(0.0, 0.0, 0.0, 1.0)
# Setup visualization, ensure to do it in a draw event
objects = _prepare_vis()
_clear_screen()
_draw1()
_clear_screen()
_draw2()
_clear_screen()
_draw3()
# Clean up
for delete_func, handle in objects:
delete_func(handle)
gl.glFinish()
示例4: on_paint
def on_paint(self, event):
# Set framebuffer input output
self._program['u_texture'] = self._tex1
self._fbo.attach_color(self._tex2)
with self._fbo:
# Init
gl.glViewport(0, 0, im1.shape[1], im1.shape[0])
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
# Draw
self._program.draw(gl.GL_TRIANGLE_STRIP)
# Draw to the normal color buffer (i.e. the screen)
self._program['u_texture'] = self._tex2
# Init
gl.glViewport(0, 0, self.size[0], self.size[1])
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
# Draw
self._program.draw(gl.GL_TRIANGLE_STRIP)
# Prepare for next round
self._tex1, self._tex2 = self._tex2, self._tex1
# Force redraw
self.update()
示例5: paint0
def paint0(event):
print(' {0:7}: {1}'.format(backend + '_0', bgcolors[0]))
if bgcolors[0] is not None:
gl.glViewport(0, 0, *list(_win_size))
gl.glClearColor(*bgcolors[0])
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
gl.glFinish()
示例6: on_resize
def on_resize(self, event):
width, height = event.size
gl.glViewport(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
示例7: on_initialize
def on_initialize(self, event):
# Build & activate program
self.program = gl.glCreateProgram()
vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER)
fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
gl.glShaderSource(vertex, vertex_code)
gl.glShaderSource(fragment, fragment_code)
gl.glCompileShader(vertex)
gl.glCompileShader(fragment)
gl.glAttachShader(self.program, vertex)
gl.glAttachShader(self.program, fragment)
gl.glLinkProgram(self.program)
gl.glDetachShader(self.program, vertex)
gl.glDetachShader(self.program, fragment)
gl.glUseProgram(self.program)
# Build vertex buffer
n = 10000
self.data = np.zeros(n, dtype=[('lifetime', np.float32, 1),
('start', np.float32, 3),
('end', np.float32, 3)])
vbuffer = gl.glCreateBuffer()
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbuffer)
gl.glBufferData(gl.GL_ARRAY_BUFFER, self.data, gl.GL_DYNAMIC_DRAW)
# Bind buffer attributes
stride = self.data.strides[0]
offset = 0
loc = gl.glGetAttribLocation(self.program, "lifetime")
gl.glEnableVertexAttribArray(loc)
gl.glVertexAttribPointer(loc, 1, gl.GL_FLOAT, False, stride, offset)
offset = self.data.dtype["lifetime"].itemsize
loc = gl.glGetAttribLocation(self.program, "start")
gl.glEnableVertexAttribArray(loc)
gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset)
offset = self.data.dtype["start"].itemsize
loc = gl.glGetAttribLocation(self.program, "end")
gl.glEnableVertexAttribArray(loc)
gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset)
# OpenGL initalization
self.elapsed_time = 0
gl.glClearColor(0, 0, 0, 1)
gl.glDisable(gl.GL_DEPTH_TEST)
gl.glEnable(gl.GL_BLEND)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)
gl.glEnable(34370) # gl.GL_VERTEX_PROGRAM_POINT_SIZE
gl.glEnable(34913) # gl.GL_POINT_SPRITE
gl.glViewport(0, 0, *self.physical_size)
self.new_explosion()
self.timer = app.Timer('auto', self.on_timer, start=True)
示例8: _test_functonality
def _test_functonality(backend):
""" Create app and canvas so we have a context. Then run tests.
"""
# use the backend
gl.use(backend)
# Note that we explicitly use pyglet because with Qt we seem
# to get errors for this test
with app_opengl_context('qt') as context:
_clear_screen()
# Prepare
w, h = context.c.size
gl.glViewport(0, 0, w, h)
gl.glScissor(0, 0, w, h) # touch
gl.glClearColor(0.0, 0.0, 0.0, 1.0)
# Setup visualization, ensure to do it in a paint event
objects = context.test(_prepare_vis)
_clear_screen()
# Draw 1
context.test(_draw1)
if SHOW:
context.c.swap_buffers()
app.process_events()
time.sleep(1.0)
_clear_screen()
# Draw 2
context.test(_draw2)
if SHOW:
context.c.swap_buffers()
app.process_events()
time.sleep(1.0)
_clear_screen()
# Draw 3
context.test(_draw3)
if SHOW:
context.c.swap_buffers()
app.process_events()
time.sleep(1.0)
# Clean up
for delete_func, handle in objects:
delete_func(handle)
示例9: on_resize
def on_resize(self, event):
width, height = event.size
gl.glViewport(0, 0, width, height)
self.projection = ortho( 0, width, 0, height, -100, 100 )
self.program['u_projection'] = self.projection
# Compute thje new size of the quad
r = width/float(height)
R = W/float(H)
if r < R:
w,h = width, width/R
x,y = 0, int((height-h)/2)
else:
w,h = height*R, height
x,y = int((width-w)/2), 0
data['a_position'] = np.array([[x, y], [x+w, y], [x, y+h], [x+w, y+h]])
self.program.set_vars(gloo.VertexBuffer(data))
示例10: on_paint
def on_paint(self, event):
# Paint events are "manually" propagated to the viewport instances,
# because we first want to set the glViewport for each one.
# Prepare
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
w1 = self.size[0] // 2
w2 = self.size[0] - w1
# Left
gl.glViewport(0, 0, w1, self.size[1])
self.left.on_paint()
# Right
gl.glViewport(w1, 0, w2, self.size[1])
self.right.on_paint()
# Invoke new draw
self.update()
示例11: resize
def resize(self, width, height):
gl.glViewport(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.program['projection'] = ortho(*args_ortho)
示例12: on_resize
def on_resize(self, event):
w, h = event.size
gl.glViewport(0, 0, w, h)
self.projection = perspective(45.0, w / float(h), 2.0, 10.0)
示例13: on_resize
def on_resize(self, event):
width, height = event.size
gl.glViewport(0, 0, width, height)
projection = perspective(35.0, width / float(height), 2.0, 10.0)
loc = gl.glGetUniformLocation(self.cube, "u_projection")
gl.glUniformMatrix4fv(loc, 1, False, projection)
示例14: on_resize
def on_resize(self, event):
gl.glViewport(0, 0, *event.size)
示例15: test_application
def test_application():
"""Test application running"""
app = use_app()
print(app) # __repr__ without app
app.create()
wrong = 'glut' if app.backend_name.lower() != 'glut' else 'pyglet'
assert_raises(RuntimeError, use_app, wrong)
app.process_events()
print(app) # test __repr__
assert_raises(ValueError, Canvas, keys='foo')
assert_raises(TypeError, Canvas, keys=dict(escape=1))
assert_raises(ValueError, Canvas, keys=dict(escape='foo')) # not an attr
pos = [0, 0] if app.backend_module.capability['position'] else None
size = (100, 100)
# Use "with" statement so failures don't leave open window
# (and test context manager behavior)
title = 'default'
with Canvas(title=title, size=size, app=app, show=True,
position=pos) as canvas:
assert_true(canvas.create_native() is None) # should be done already
assert_is(canvas.app, app)
assert_true(canvas.native)
assert_equal('swap_buffers', canvas.events.draw.callback_refs[-1])
canvas.measure_fps(0.001)
sleep(0.002)
canvas.update()
app.process_events()
assert_true(canvas.fps > 0)
# Other methods
print(canvas) # __repr__
assert_equal(canvas.title, title)
canvas.title = 'you'
with use_log_level('warning', record=True, print_msg=False) as l:
if app.backend_module.capability['position']:
# todo: disable more tests based on capability
canvas.position = pos
canvas.size = size
if 'ipynb_vnc' in canvas.app.backend_name.lower():
assert_true(len(l) >= 1)
else:
assert_true(len(l) == 0)
canvas.connect(on_mouse_move)
assert_raises(ValueError, canvas.connect, _on_mouse_move)
if sys.platform != 'darwin': # XXX knownfail, prob. needs warmup
canvas.show(False)
canvas.show()
app.process_events()
assert_raises(ValueError, canvas.connect, on_nonexist)
# deprecation of "paint"
with use_log_level('info', record=True, print_msg=False) as log:
olderr = sys.stderr
try:
with open(os.devnull, 'w') as fid:
sys.stderr = fid
@canvas.events.paint.connect
def fake(event):
pass
finally:
sys.stderr = olderr
assert_equal(len(log), 1)
assert_in('deprecated', log[0])
# screenshots
gl.glViewport(0, 0, *size)
ss = _screenshot()
assert_array_equal(ss.shape, size + (4,))
assert_equal(len(canvas._backend._vispy_get_geometry()), 4)
if (app.backend_name.lower() != 'glut' and # XXX knownfail for Almar
sys.platform != 'win32'): # XXX knownfail for windows
assert_array_equal(canvas.size, size)
assert_equal(len(canvas.position), 2) # XXX knawnfail, doesn't "take"
# GLOO: should have an OpenGL context already, so these should work
vert = VertexShader("void main (void) {gl_Position = pos;}")
frag = FragmentShader("void main (void) {gl_FragColor = pos;}")
program = Program(vert, frag)
assert_raises(RuntimeError, program.activate)
vert = VertexShader("uniform vec4 pos;"
"void main (void) {gl_Position = pos;}")
frag = FragmentShader("uniform vec4 pos;"
"void main (void) {gl_FragColor = pos;}")
program = Program(vert, frag)
#uniform = program.uniforms[0]
program['pos'] = [1, 2, 3, 4]
program.activate() # should print
#uniform.upload(program)
program.detach(vert)
program.detach(frag)
assert_raises(RuntimeError, program.detach, vert)
assert_raises(RuntimeError, program.detach, frag)
vert = VertexShader("attribute vec4 pos;"
"void main (void) {gl_Position = pos;}")
frag = FragmentShader("void main (void) {}")
#.........这里部分代码省略.........