当前位置: 首页>>代码示例>>Python>>正文


Python Program.bind方法代码示例

本文整理汇总了Python中vispy.gloo.Program.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Program.bind方法的具体用法?Python Program.bind怎么用?Python Program.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vispy.gloo.Program的用法示例。


在下文中一共展示了Program.bind方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Canvas

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Canvas(app.Canvas):
    def __init__(self):
        app.Canvas.__init__(self, size=(512, 512), title='Rotating cube',
                            keys='interactive')
        self.timer = app.Timer('auto', self.on_timer)

    def on_initialize(self, event):
        # Build cube data
        V, I, O = create_cube()
        vertices = VertexBuffer(V)
        self.faces = IndexBuffer(I)
        self.outline = IndexBuffer(O)

        # Build program
        # --------------------------------------
        self.program = Program(vertex, fragment)
        self.program.bind(vertices)

        # Build view, model, projection & normal
        # --------------------------------------
        view = translate((0, 0, -5))
        model = np.eye(4, dtype=np.float32)

        self.program['u_model'] = model
        self.program['u_view'] = view
        self.phi, self.theta = 0, 0

        # OpenGL initalization
        # --------------------------------------
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True,
                       polygon_offset=(1, 1), line_width=0.75,
                       blend_func=('src_alpha', 'one_minus_src_alpha'))
        self.timer.start()

    def on_draw(self, event):
        gloo.clear(color=True, depth=True)

        # Filled cube
        gloo.set_state(blend=False, depth_test=True, polygon_offset_fill=True)
        self.program['u_color'] = 1, 1, 1, 1
        self.program.draw('triangles', self.faces)

        # Outlined cube
        gloo.set_state(blend=True, depth_mask=False, polygon_offset_fill=False)
        self.program['u_color'] = 0, 0, 0, 1
        self.program.draw('lines', self.outline)
        gloo.set_state(depth_mask=True)

    def on_resize(self, event):
        gloo.set_viewport(0, 0, *event.size)
        projection = perspective(45.0, event.size[0] / float(event.size[1]),
                                 2.0, 10.0)
        self.program['u_projection'] = projection

    def on_timer(self, event):
        self.theta += .02
        self.phi += .02
        model = rotate(self.phi, (0, 1, 0)) * rotate(self.theta, (0, 0, 1))
        self.program['u_model'] = model
        self.update()
开发者ID:rreilink,项目名称:vispy,代码行数:62,代码来源:outlined_cube.py

示例2: Canvas

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Canvas(app.Canvas):
    def __init__(self):
        app.Canvas.__init__(self, title='Rain [Move mouse]',
                            size=(512, 512), keys='interactive')

        # Build data
        # --------------------------------------
        n = 500
        self.data = np.zeros(n, [('a_position', np.float32, 2),
                                 ('a_fg_color', np.float32, 4),
                                 ('a_size',     np.float32, 1)])
        self.index = 0
        self.program = Program(vertex, fragment)
        self.vdata = VertexBuffer(self.data)
        self.program.bind(self.vdata)
        self.program['u_antialias'] = 1.00
        self.program['u_linewidth'] = 1.00
        self.program['u_model'] = np.eye(4, dtype=np.float32)
        self.program['u_view'] = np.eye(4, dtype=np.float32)

        self.activate_zoom()

        gloo.set_clear_color('white')
        gloo.set_state(blend=True,
                       blend_func=('src_alpha', 'one_minus_src_alpha'))
        self.timer = app.Timer('auto', self.on_timer, start=True)

        self.show()

    def on_draw(self, event):
        gloo.clear()
        self.program.draw('points')

    def on_resize(self, event):
        self.activate_zoom()

    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

    def on_timer(self, event):
        self.data['a_fg_color'][..., 3] -= 0.01
        self.data['a_size'] += 1.0
        self.vdata.set_data(self.data)
        self.update()

    def on_mouse_move(self, event):
        x, y = event.pos
        h = self.size[1]
        self.data['a_position'][self.index] = x, h - y
        self.data['a_size'][self.index] = 5
        self.data['a_fg_color'][self.index] = 0, 0, 0, 1
        self.index = (self.index + 1) % 500
开发者ID:Eric89GXL,项目名称:vispy,代码行数:57,代码来源:rain.py

示例3: Canvas

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Canvas(app.Canvas):
    def __init__(self):
        app.Canvas.__init__(self, size=(512, 512), title='Textured cube',
                            keys='interactive')
        self.timer = app.Timer('auto', self.on_timer)

        # Build cube data
        V, I, _ = create_cube()
        vertices = VertexBuffer(V)
        self.indices = IndexBuffer(I)

        # Build program
        self.program = Program(vertex, fragment)
        self.program.bind(vertices)

        # Build view, model, projection & normal
        view = translate((0, 0, -5))
        model = np.eye(4, dtype=np.float32)
        self.program['model'] = model
        self.program['view'] = view
        self.program['texture'] = checkerboard()

        self.activate_zoom()

        self.phi, self.theta = 0, 0

        # OpenGL initalization
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True)
        self.timer.start()

        self.show()

    def on_draw(self, event):
        gloo.clear(color=True, depth=True)
        self.program.draw('triangles', self.indices)

    def on_resize(self, event):
        self.activate_zoom()

    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

    def on_timer(self, event):
        self.theta += .5
        self.phi += .5
        self.program['model'] = np.dot(rotate(self.theta, (0, 0, 1)),
                                       rotate(self.phi, (0, 1, 0)))
        self.update()
开发者ID:Calvarez20,项目名称:vispy,代码行数:53,代码来源:textured_cube.py

示例4: Canvas

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Canvas(app.Canvas):
    def __init__(self):
        app.Canvas.__init__(self, size=(512, 512), title='Textured cube',
                            close_keys='escape')
        self.timer = app.Timer(1./60., self.on_timer)

    def on_initialize(self, event):
        # Build cube data
        V, I, _ = cube()
        vertices = VertexBuffer(V)
        self.indices = IndexBuffer(I)

        # Build program
        self.program = Program(vertex, fragment)
        self.program.bind(vertices)

        # Build view, model, projection & normal
        view = np.eye(4, dtype=np.float32)
        model = np.eye(4, dtype=np.float32)
        translate(view, 0, 0, -5)
        self.program['model'] = model
        self.program['view'] = view
        self.program['texture'] = checkerboard()

        self.phi, self.theta = 0, 0

        # OpenGL initalization
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True)
        self.timer.start()

    def on_draw(self, event):
        gloo.clear(color=True, depth=True)
        self.program.draw('triangles', self.indices)

    def on_resize(self, event):
        gloo.set_viewport(0, 0, *event.size)
        projection = perspective(45.0, event.size[0] / float(event.size[1]),
                                 2.0, 10.0)
        self.program['projection'] = projection

    def on_timer(self, event):
        self.theta += .5
        self.phi += .5
        model = np.eye(4, dtype=np.float32)
        rotate(model, self.theta, 0, 0, 1)
        rotate(model, self.phi, 0, 1, 0)
        self.program['model'] = model
        self.update()
开发者ID:shjoshi,项目名称:vispy,代码行数:50,代码来源:textured_cube.py

示例5: Example

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Example(Drawable):
    '''Draw a cube'''    
    cube_vertex = """
        #version 120
        uniform mat4 model;
        uniform mat4 view;
        uniform mat4 projection;
        attribute vec3 position;
        attribute vec2 texcoord;
        varying vec2 v_texcoord;
        void main()
        {
            gl_Position = projection * view * model * vec4(position, 1.0);
            v_texcoord = texcoord;
        }
    """
    
    cube_fragment = """
        #version 120
        uniform sampler2D texture;
        varying vec2 v_texcoord;
        void main()
        {
            float r = texture2D(texture, v_texcoord).r;
            gl_FragColor = vec4(0, r, r, 1);
        }
    """

    def __init__(self):
        vertices, indices, _ = create_cube()
        vertices = VertexBuffer(vertices)
        self.indices = IndexBuffer(indices)
        self.program = Program(self.cube_vertex, self.cube_fragment)

        self.model = np.eye(4)
        self.view = np.eye(4)

        self.program.bind(vertices)
        self.program['texture'] = utils.checkerboard()
        self.program['texture'].interpolation = 'linear'
        self.program['model'] = self.model
        self.program['view'] = self.view

    def draw(self):
        self.program.draw('triangles', self.indices)
开发者ID:jpanikulam,项目名称:visar,代码行数:47,代码来源:example.py

示例6: make_mesh

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
    def make_mesh(self):
        '''mesh()
        Generates a default mesh (a cube)
        treat it as though it is a property (i.e. not a function)
        ex:
        >>> x = Target((100, 100, 100))
        >>> mesh = Target.mesh
        '''
        cube = Program(cube_vertex, cube_fragment)
        cube.bind(vertices)
        self.program['model'] = model
        self.program['view'] = view
        self.program['projection'] = projection

        if self.mesh is None:
            vertices, indices, _ = create_cube()
            # self.mesh = 
            
        else:
            return self.mesh
开发者ID:jpanikulam,项目名称:visar,代码行数:22,代码来源:drawable.py

示例7: Canvas

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Canvas(app.Canvas):

    def __init__(self):
        app.Canvas.__init__(self, title='Framebuffer post-processing',
                            keys='interactive', size=(512, 512))

    def on_initialize(self, event):
        # Build cube data
        # --------------------------------------
        vertices, indices, _ = create_cube()
        vertices = VertexBuffer(vertices)
        self.indices = IndexBuffer(indices)

        # Build program
        # --------------------------------------
        view = np.eye(4, dtype=np.float32)
        model = np.eye(4, dtype=np.float32)
        translate(view, 0, 0, -7)
        self.phi, self.theta = 60, 20
        rotate(model, self.theta, 0, 0, 1)
        rotate(model, self.phi, 0, 1, 0)

        self.cube = Program(cube_vertex, cube_fragment)
        self.cube.bind(vertices)
        self.cube["texture"] = checkerboard()
        self.cube["texture"].interpolation = 'linear'
        self.cube['model'] = model
        self.cube['view'] = view
        
        color = Texture2D((512, 512, 3), interpolation='linear')
        self.framebuffer = FrameBuffer(color, RenderBuffer((512, 512)))

        self.quad = Program(quad_vertex, quad_fragment, count=4)
        self.quad['texcoord'] = [(0, 0), (0, 1), (1, 0), (1, 1)]
        self.quad['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
        self.quad['texture'] = color

        # OpenGL and Timer initalization
        # --------------------------------------
        set_state(clear_color=(.3, .3, .35, 1), depth_test=True)
        self.timer = app.Timer('auto', connect=self.on_timer, start=True)
        self._set_projection(self.size)

    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.size)
        clear(color=True)
        set_state(depth_test=False)
        self.quad.draw('triangle_strip')

    def on_resize(self, event):
        self._set_projection(event.size)
    
    def _set_projection(self, size):
        width, height = size
        set_viewport(0, 0, width, height)
        projection = perspective(30.0, width / float(height), 2.0, 10.0)
        self.cube['projection'] = projection

    def on_timer(self, event):
        self.theta += .5
        self.phi += .5
        model = np.eye(4, dtype=np.float32)
        rotate(model, self.theta, 0, 0, 1)
        rotate(model, self.phi, 0, 1, 0)
        self.cube['model'] = model
        self.update()
开发者ID:Peque,项目名称:vispy,代码行数:73,代码来源:post_processing.py

示例8: Canvas

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Canvas(app.Canvas):
    def __init__(self):
        app.Canvas.__init__(self, size=(512, 512), title="Lighted cube", keys="interactive")
        self.timer = app.Timer("auto", self.on_timer)

        # Build cube data
        V, F, O = create_cube()
        vertices = VertexBuffer(V)
        self.faces = IndexBuffer(F)
        self.outline = IndexBuffer(O)

        # Build view, model, projection & normal
        # --------------------------------------
        self.view = np.eye(4, dtype=np.float32)
        model = np.eye(4, dtype=np.float32)
        translate(self.view, 0, 0, -5)
        normal = np.array(np.matrix(np.dot(self.view, model)).I.T)

        # Build program
        # --------------------------------------
        self.program = Program(vertex, fragment)
        self.program.bind(vertices)
        self.program["u_light_position"] = 2, 2, 2
        self.program["u_light_intensity"] = 1, 1, 1
        self.program["u_model"] = model
        self.program["u_view"] = self.view
        self.program["u_normal"] = normal
        self.phi, self.theta = 0, 0

        # OpenGL initalization
        # --------------------------------------
        gloo.set_state(
            clear_color=(0.30, 0.30, 0.35, 1.00),
            depth_test=True,
            polygon_offset=(1, 1),
            blend_func=("src_alpha", "one_minus_src_alpha"),
            line_width=0.75,
        )
        self.timer.start()

    def on_draw(self, event):
        gloo.clear(color=True, depth=True)
        # program.draw(gl.GL_TRIANGLES, indices)

        # Filled cube
        gloo.set_state(blend=False, depth_test=True, polygon_offset_fill=True)
        self.program["u_color"] = 1, 1, 1, 1
        self.program.draw("triangles", self.faces)

        # Outlined cube
        gloo.set_state(polygon_offset_fill=False, blend=True, depth_mask=False)
        self.program["u_color"] = 0, 0, 0, 1
        self.program.draw("lines", self.outline)
        gloo.set_state(depth_mask=True)

    def on_resize(self, event):
        gloo.set_viewport(0, 0, *event.size)
        projection = perspective(45.0, event.size[0] / float(event.size[1]), 2.0, 10.0)
        self.program["u_projection"] = projection

    def on_timer(self, event):
        self.theta += 0.5
        self.phi += 0.5
        model = np.eye(4, dtype=np.float32)
        rotate(model, self.theta, 0, 0, 1)
        rotate(model, self.phi, 0, 1, 0)
        normal = np.array(np.matrix(np.dot(self.view, model)).I.T)
        self.program["u_model"] = model
        self.program["u_normal"] = normal
        self.update()
开发者ID:rossant,项目名称:vispy,代码行数:72,代码来源:lighted_cube.py

示例9: cube

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
glut.glutReshapeWindow(512, 512)
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)
glut.glutTimerFunc(1000 / 60, timer, 60)

# Build cube data
# --------------------------------------
V, I, _ = cube()
vertices = VertexBuffer(V)
indices = IndexBuffer(I)

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(vertices)

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4, dtype=np.float32)
model = np.eye(4, dtype=np.float32)
projection = np.eye(4, dtype=np.float32)
translate(view, 0, 0, -5)
program["model"] = model
program["view"] = view
phi, theta = 0, 0

# OpenGL initalization
# --------------------------------------
gl.glClearColor(0.30, 0.30, 0.35, 1.00)
gl.glEnable(gl.GL_DEPTH_TEST)
开发者ID:tatak,项目名称:experimental,代码行数:33,代码来源:server.py

示例10: Program

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
glut.glutPassiveMotionFunc(on_passive_motion)
glut.glutTimerFunc(1000 / 60, timer, 60)

# Build data
# --------------------------------------
n = 500
data = np.zeros(n, [('a_position', np.float32, 2),
                    ('a_fg_color', np.float32, 4),
                    ('a_size',     np.float32, 1)])
index = 0

# Build program
# --------------------------------------
program = Program(vertex, fragment)
vdata = VertexBuffer(data)
program.bind(vdata)
program['u_antialias'] = 1.00
program['u_linewidth'] = 1.00

# Build view, model, projection
# --------------------------------------
program['u_model'] = np.eye(4, dtype=np.float32)
program['u_view'] = np.eye(4, dtype=np.float32)

# OpenGL initalization
# --------------------------------------
gloo.set_clear_color((1.0, 1.0, 1.0, 1.0))
gloo.set_state(blend=True, blend_func=('src_alpha', 'one_minus_src_alpha'))
gloo.gl_initialize()

# Start
开发者ID:MatthieuDartiailh,项目名称:vispy,代码行数:33,代码来源:rain.py

示例11: VertexBuffer

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
vertices = VertexBuffer(V)

I = [0,1,2, 0,2,3,  0,3,4, 0,4,5,  0,5,6, 0,6,1,
     1,6,7, 1,7,2,  7,4,3, 7,3,2,  4,7,6, 4,6,5]
indices = IndexBuffer(I)

O = [0,1, 1,2, 2,3, 3,0,
     4,7, 7,6, 6,5, 5,4,
     0,5, 1,6, 2,7, 3,4 ]
outline = IndexBuffer(O)

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(vertices)

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4,dtype=np.float32)
rotate(view, 20, 1, 0, 0)
translate(view, 0,1 ,-8)
model = np.eye(4,dtype=np.float32)
projection = np.eye(4,dtype=np.float32)
program['model'] = model
program['view'] = view
program['o_projection'] = ortho(-10, 10, -10, 10, -10, 20)
phi, theta = 0,0

program2 = Program(vertex, ilio.read('black.frag'), count=4)
program2['model'] = model
开发者ID:Fuco1,项目名称:sturdy-eureka,代码行数:32,代码来源:reflection.py

示例12: Canvas

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Canvas(app.Canvas):
    def __init__(self):
        app.Canvas.__init__(self, size=(512, 512), title='Lighted cube',
                            keys='interactive')
        self.timer = app.Timer('auto', self.on_timer)

        # Build cube data
        V, F, O = create_cube()
        vertices = VertexBuffer(V)
        self.faces = IndexBuffer(F)
        self.outline = IndexBuffer(O)

        # Build view, model, projection & normal
        # --------------------------------------
        self.view = translate((0, 0, -5))
        model = np.eye(4, dtype=np.float32)
        normal = np.array(np.matrix(np.dot(self.view, model)).I.T)

        # Build program
        # --------------------------------------
        self.program = Program(vertex, fragment)
        self.program.bind(vertices)
        self.program["u_light_position"] = 2, 2, 2
        self.program["u_light_intensity"] = 1, 1, 1
        self.program["u_model"] = model
        self.program["u_view"] = self.view
        self.program["u_normal"] = normal
        self.phi, self.theta = 0, 0

        self.activate_zoom()

        # OpenGL initialization
        # --------------------------------------
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True,
                       polygon_offset=(1, 1),
                       blend_func=('src_alpha', 'one_minus_src_alpha'),
                       line_width=0.75)
        self.timer.start()

        self.show()

    def on_draw(self, event):
        gloo.clear(color=True, depth=True)
        # program.draw(gl.GL_TRIANGLES, indices)

        # Filled cube
        gloo.set_state(blend=False, depth_test=True, polygon_offset_fill=True)
        self.program['u_color'] = 1, 1, 1, 1
        self.program.draw('triangles', self.faces)

        # Outlined cube
        gloo.set_state(polygon_offset_fill=False, blend=True, depth_mask=False)
        self.program['u_color'] = 0, 0, 0, 1
        self.program.draw('lines', self.outline)
        gloo.set_state(depth_mask=True)

    def on_resize(self, event):
        self.activate_zoom()

    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['u_projection'] = projection

    def on_timer(self, event):
        self.theta += .5
        self.phi += .5
        model = np.dot(rotate(self.theta, (0, 0, 1)),
                       rotate(self.phi, (0, 1, 0)))
        normal = np.linalg.inv(np.dot(self.view, model)).T
        self.program['u_model'] = model
        self.program['u_normal'] = normal
        self.update()
开发者ID:Lx37,项目名称:vispy,代码行数:76,代码来源:lighted_cube.py

示例13: Drawable

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Drawable(object):
    name = "Default Drawable"
    skip = False
    def __init__(self, *args, **kwargs):
        '''Drawable(*args, **kwargs) -> Drawable
        Everything is tracked internally, different drawables will handle things differently
        Inherit from this for all drawables.

        Inheriting:
            You must define a make_mesh, make_shaders, and draw method. 
            If you do not make shaders, you will get a default
            If you do not make a mesh, you'll get a square that takes up the screen

        '''
        self.model = np.eye(4)
        self.view = np.eye(4)
        self.projection = np.eye(4)

        self.mesh = self.make_mesh()
        self.vert_shader, self.frag_shader = self.make_shaders()
        self.program = Program(self.vert_shader, self.frag_shader)
        self.program.bind(VertexBuffer(self.mesh))
        if hasattr(self, make_texture):
            self.texture = self.make_texture()
            assert isinstance(self.texture, Texture2D), "Texture passed is not a texture!"

        self.program['texture'] = self.texture
        cube["texture"].interpolation = 'linear'

    def __setitem__(self, key, value):
        self.bind(key, value)

    def translate(self, *args):
        translate(self.model, *args)
        self.program['model'] = self.model

    def rotate(self, *args):
        rotate(self.model, *args)
        self.program['model'] = self.model

    def bind(self, key, value):
        '''Rebind a single program item to a value'''
        self.program[key] = value

    def bind_multiple(self, **kwargs):
        '''rebind multiple things!'''
        for key, value in kwargs:
            self.bind(key, value)

    def make_mesh(self):
        '''mesh()
        Generates a default mesh (a cube)
        treat it as though it is a property (i.e. not a function)
        ex:
        >>> x = Target((100, 100, 100))
        >>> mesh = Target.mesh
        '''
        cube = Program(cube_vertex, cube_fragment)
        cube.bind(vertices)
        self.program['model'] = model
        self.program['view'] = view
        self.program['projection'] = projection

        if self.mesh is None:
            vertices, indices, _ = create_cube()
            # self.mesh = 
            
        else:
            return self.mesh

    def make_shaders(self):
        '''shader -> (vertex, fragment) 
        Returns vertex and fragment shaders as 2-tuple of strings

        THIS IS A DEFAULT SHADER
        '''
        fragment = ''
        vertex = ''
        return vertex, fragment

    def make_texture(self):
        '''Make a texture
        THIS IS A DEFAULT TEXTURE
        '''
        texture = utils.checkerboard()
        return texture

    def update(self):
        pass

    def draw(self):
        self.program.draw()
开发者ID:jpanikulam,项目名称:visar,代码行数:94,代码来源:drawable.py

示例14: Canvas

# 需要导入模块: from vispy.gloo import Program [as 别名]
# 或者: from vispy.gloo.Program import bind [as 别名]
class Canvas(app.Canvas):

    def __init__(self):
        app.Canvas.__init__(self, title='Visualize Mesh',
                            keys='interactive', size=(1920, 1080))

    def on_initialize(self, event):
        self.rho = 0.0
        # Build cube data
        # --------------------------------------
        self.checker = Program(cube_vertex, cube_fragment)
        self.checker['texture'] = checkerboard()
        self.checker['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
        self.checker['texcoord'] = [(0, 0), (0, 1), (1, 0), (1, 1)]

        # sheet, indices = make_sheet((960, 1080))
        # sheet_buffer = VertexBuffer(sheet)

        left_eye = Texture2D((960, 1080, 3), interpolation='linear')
        self.left_eye_buffer = FrameBuffer(left_eye, RenderBuffer((960, 1080)))
        # Build program
        # --------------------------------------
        self.view = np.eye(4, dtype=np.float32)
        self.program = Program(vertex, fragment)
        distortion_buffer = VertexBuffer(make_distortion())
        self.program.bind(distortion_buffer)
        self.program['rotation'] = self.view
        self.program['texture'] = left_eye

        # OpenGL and Timer initalization
        # --------------------------------------
        set_state(clear_color=(.3, .3, .35, 1), depth_test=True)
        self.timer = app.Timer('auto', connect=self.on_timer, start=True)
        self._set_projection(self.size)

    def on_draw(self, event):
        with self.left_eye_buffer:
            set_viewport(0, 0, *self.size)
            clear(color=True)
            set_state(depth_test=False)
            self.checker.draw('triangle_strip')
        set_viewport(0, 0, *self.size)
        clear(color=True)
        set_state(depth_test=True)
        self.program.draw('points')

    def on_resize(self, event):
        self._set_projection(event.size)

    def on_mouse_move(self, event):
        pos = np.array(event.pos)

    def on_key_press(self, event):
        if event.text == 'q':
            sys.exit()

    def _set_projection(self, size):
        width, height = size
        set_viewport(0, 0, width, height)
        projection = perspective(30.0, width / float(height), 2.0, 10.0)
        # self.program['projection'] = projection

    def on_timer(self, event):
        self.rho = 0.1
        if self.rho >= 30:
            self.rho = 0

        self.update()
开发者ID:jpanikulam,项目名称:visar,代码行数:70,代码来源:visualize_mesh.py


注:本文中的vispy.gloo.Program.bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。