本文整理汇总了Python中vispy.gloo.program.Program.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Program.bind方法的具体用法?Python Program.bind怎么用?Python Program.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vispy.gloo.program.Program
的用法示例。
在下文中一共展示了Program.bind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_application
# 需要导入模块: from vispy.gloo.program import Program [as 别名]
# 或者: from vispy.gloo.program.Program import bind [as 别名]
def _test_application(backend):
"""Test application running"""
app = Application()
assert_raises(ValueError, app.use, "foo")
app.use(backend)
wrong = "Glut" if app.backend_name != "Glut" else "Pyglet"
assert_raises(RuntimeError, app.use, wrong)
app.process_events()
if backend is not None:
# "in" b/c "qt" in "PySide (qt)"
assert_in(backend, app.backend_name)
print(app) # test __repr__
# Canvas
pos = [0, 0]
size = (100, 100)
# Use "with" statement so failures don't leave open window
# (and test context manager behavior)
title = "default" if backend is None else backend
with Canvas(title=title, size=size, app=app, show=True, position=pos) as canvas:
assert_is(canvas.app, app)
assert_true(canvas.native)
assert_equal("swap_buffers", canvas.events.paint.callback_refs[-1])
print(canvas) # __repr__
assert_array_equal(canvas.size, size)
assert_equal(canvas.title, title)
canvas.title = "you"
canvas.position = pos
canvas.size = size
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)
# screenshots
gl.glViewport(0, 0, *size)
ss = _screenshot()
assert_array_equal(ss.shape, size + (3,))
assert_equal(len(canvas._backend._vispy_get_geometry()), 4)
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) {}")
program = Program(vert, frag)
# attribute = program.attributes[0]
program["pos"] = [1, 2, 3, 4]
program.activate()
# attribute.upload(program)
# cannot get element count
# assert_raises(RuntimeError, program.draw, 'POINTS')
# use a real program
vert = (
"uniform mat4 u_model;"
"attribute vec2 a_position; attribute vec4 a_color;"
"varying vec4 v_color;"
"void main (void) {v_color = a_color;"
"gl_Position = u_model * vec4(a_position, 0.0, 1.0);"
"v_color = a_color;}"
)
frag = "void main() {gl_FragColor = vec4(0, 0, 0, 1);}"
n, p = 250, 50
T = np.random.uniform(0, 2 * np.pi, n)
position = np.zeros((n, 2), dtype=np.float32)
position[:, 0] = np.cos(T)
position[:, 1] = np.sin(T)
color = np.ones((n, 4), dtype=np.float32) * (1, 1, 1, 1)
data = np.zeros(n * p, [("a_position", np.float32, 2), ("a_color", np.float32, 4)])
data["a_position"] = np.repeat(position, p, axis=0)
data["a_color"] = np.repeat(color, p, axis=0)
program = Program(vert, frag)
program.bind(VertexBuffer(data))
program["u_model"] = np.eye(4, dtype=np.float32)
# different codepath if no call to activate()
program.draw(gl.GL_POINTS)
subset = IndexBuffer(np.arange(10, dtype=np.uint32))
program.draw(gl.GL_POINTS, subset)
#.........这里部分代码省略.........
示例2: test_application
# 需要导入模块: from vispy.gloo.program import Program [as 别名]
# 或者: from vispy.gloo.program.Program import bind [as 别名]
#.........这里部分代码省略.........
# 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) {}")
program = Program(vert, frag)
#attribute = program.attributes[0]
program["pos"] = [1, 2, 3, 4]
program.activate()
#attribute.upload(program)
# cannot get element count
#assert_raises(RuntimeError, program.draw, 'POINTS')
# use a real program
vert = ("uniform mat4 u_model;"
"attribute vec2 a_position; attribute vec4 a_color;"
"varying vec4 v_color;"
"void main (void) {v_color = a_color;"
"gl_Position = u_model * vec4(a_position, 0.0, 1.0);"
"v_color = a_color;}")
frag = "void main() {gl_FragColor = vec4(0, 0, 0, 1);}"
n, p = 250, 50
T = np.random.uniform(0, 2 * np.pi, n)
position = np.zeros((n, 2), dtype=np.float32)
position[:, 0] = np.cos(T)
position[:, 1] = np.sin(T)
color = np.ones((n, 4), dtype=np.float32) * (1, 1, 1, 1)
data = np.zeros(n * p, [('a_position', np.float32, 2),
('a_color', np.float32, 4)])
data['a_position'] = np.repeat(position, p, axis=0)
data['a_color'] = np.repeat(color, p, axis=0)
program = Program(vert, frag)
program.bind(VertexBuffer(data))
program['u_model'] = np.eye(4, dtype=np.float32)
# different codepath if no call to activate()
program.draw(gl.GL_POINTS)
subset = IndexBuffer(np.arange(10, dtype=np.uint32))
program.draw(gl.GL_POINTS, subset)
# bad programs
frag_bad = ("varying vec4 v_colors") # no semicolon
program = Program(vert, frag_bad)
assert_raises(RuntimeError, program.activate)
frag_bad = None # no fragment code. no main is not always enough
program = Program(vert, frag_bad)
assert_raises(ValueError, program.activate)
# Timer
timer = Timer(interval=0.001, connect=on_mouse_move, iterations=2,
start=True, app=app)
timer.start()
timer.interval = 0.002
assert_equal(timer.interval, 0.002)
assert_true(timer.running)
sleep(.003)
assert_true(timer.elapsed >= 0.002)
timer.stop()
assert_true(not timer.running)
assert_true(timer.native)
timer.disconnect()
# test that callbacks take reasonable inputs
_test_callbacks(canvas)
# cleanup
canvas.swap_buffers()
canvas.update()
app.process_events()
# put this in even though __exit__ will call it to make sure we don't
# have problems calling it multiple times
canvas.close() # done by context
示例3: _test_application
# 需要导入模块: from vispy.gloo.program import Program [as 别名]
# 或者: from vispy.gloo.program.Program import bind [as 别名]
def _test_application(backend):
"""Test application running"""
app = Application()
assert_raises(ValueError, app.use, 'foo')
app.use(backend)
wrong = 'Glut' if app.backend_name != 'Glut' else 'Pyglet'
assert_raises(RuntimeError, app.use, wrong)
app.process_events()
if backend is not None:
# "in" b/c "qt" in "PySide (qt)"
assert_in(backend, app.backend_name)
print(app) # test __repr__
# Canvas
pos = [0, 0, 1, 1]
# Use "with" statement so failures don't leave open window
# (and test context manager behavior)
with Canvas(title='me', app=app, show=True, position=pos) as canvas:
assert_is(canvas.app, app)
assert_true(canvas.native)
print(canvas.size >= (1, 1))
canvas.resize(90, 90)
canvas.move(1, 1)
assert_equal(canvas.title, 'me')
canvas.title = 'you'
canvas.position = (0, 0)
canvas.size = (100, 100)
canvas.connect(on_mouse_move)
assert_raises(ValueError, canvas.connect, _on_mouse_move)
canvas.show()
assert_raises(ValueError, canvas.connect, on_nonexist)
# screenshots
#ss = _screenshot()
#assert_array_equal(ss.shape[2], 3) # XXX other dimensions not correct?
# XXX it would be good to do real checks, but sometimes the
# repositionings don't "take" (i.e., lead to random errors)
#assert_equal(len(canvas._backend._vispy_get_geometry()), 4)
#assert_equal(len(canvas.size), 2)
#assert_equal(len(canvas.position), 2)
# 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) {}")
program = Program(vert, frag)
#attribute = program.attributes[0]
program["pos"] = [1, 2, 3, 4]
program.activate()
#attribute.upload(program)
# cannot get element count
#assert_raises(RuntimeError, program.draw, 'POINTS')
# use a real program
vert = ("uniform mat4 u_model;"
"attribute vec2 a_position; attribute vec4 a_color;"
"varying vec4 v_color;"
"void main (void) {v_color = a_color;"
"gl_Position = u_model * vec4(a_position, 0.0, 1.0);"
"v_color = a_color;}")
frag = "void main() {gl_FragColor = vec4(0, 0, 0, 1);}"
n, p = 250, 50
T = np.random.uniform(0, 2 * np.pi, n)
position = np.zeros((n, 2), dtype=np.float32)
position[:, 0] = np.cos(T)
position[:, 1] = np.sin(T)
color = np.ones((n, 4), dtype=np.float32) * (1, 1, 1, 1)
data = np.zeros(n * p, [('a_position', np.float32, 2),
('a_color', np.float32, 4)])
data['a_position'] = np.repeat(position, p, axis=0)
data['a_color'] = np.repeat(color, p, axis=0)
program = Program(vert, frag)
program.bind(VertexBuffer(data))
program['u_model'] = np.eye(4, dtype=np.float32)
# different codepath if no call to activate()
program.draw(gl.GL_POINTS)
subset = IndexBuffer(np.arange(10, dtype=np.uint32))
program.draw(gl.GL_POINTS, subset)
# bad programs
#.........这里部分代码省略.........