Esempio n. 1
0
    def __init__(self):
        app.Canvas.__init__(self)
        self.size = 800, 600

        self.vertices, self.filled, self.outline = cube()
        self.filled_buf = gloo.ElementBuffer(self.filled)
        self.outline_buf = gloo.ElementBuffer(self.outline)

        self.program = gloo.Program(vert, frag)
        self.program.set_vars(gloo.VertexBuffer(self.vertices))

        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        translate(self.view, 0, 0, -5)
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view

        self.theta = 0
        self.phi = 0

        self._timer = app.Timer(1.0 / 60)
        self._timer.connect(self.on_timer)
        self._timer.start()
Esempio n. 2
0
    def __init__(self, **kwargs):
        # Initialize the canvas for real
        app.Canvas.__init__(self, **kwargs)
        self.size = 512, 512
        self.position = 50, 50
        
        self.vbo = gloo.VertexBuffer(data)
        self.index = gloo.ElementBuffer(edges)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        self.program = gloo.Program(markers.vert, markers.frag + markers.disc)
        self.program.set_vars(self.vbo,
                              u_size=1,
                              u_antialias=u_antialias,
                              u_model=self.model,
                              u_view=self.view,
                              u_projection=self.projection)

        self.program_e = gloo.Program(vs, fs)
        self.program_e.set_vars(self.vbo)
Esempio n. 3
0
im1 = np.zeros((100,100,3), 'float64')
im1[:50,:,0] = 1.0
im1[:,:50,1] = 1.0
im1[50:,50:,2] = 1.0

# Create vetices and texture coords, combined in one array for high performance
vertex_data = np.zeros(4, dtype=[   ('a_position', np.float32, 3), 
                                    ('a_texcoord', np.float32, 2) ])
vertex_data['a_position'] = np.array([ [-0.8, -0.8, 0.0], [+0.7, -0.7, 0.0],  
                                       [-0.7, +0.7, 0.0], [+0.8, +0.8, 0.0,] ])
vertex_data['a_texcoord'] = np.array([    [0.0, 0.0], [0.0, 1.0], 
                                          [1.0, 0.0], [1.0, 1.0] ])

# Create indices and an ElementBuffer for it
indices = np.array([0,1,2, 1,2,3], np.uint16)
indices_buffer = gloo.ElementBuffer(indices)
client_indices_buffer = gloo.ElementBuffer(indices, client=True)


VERT_SHADER = """ // simple vertex shader

attribute vec3 a_position;
attribute vec2 a_texcoord;
uniform float sizeFactor;
//attribute float sizeFactor;

void main (void) {
    // Pass tex coords
    gl_TexCoord[0] = vec4(a_texcoord.x, a_texcoord.y, 0.0, 0.0);
    // Calculate position
    gl_Position = sizeFactor*vec4(a_position.x, a_position.y, a_position.z,
uniform sampler2D u_texture;
varying vec2 v_texcoord;

void main()
{
    float ty = v_texcoord.y;
    float tx = sin(ty*50.0)*0.01 + v_texcoord.x;
    gl_FragColor = texture2D(u_texture, vec2(tx, ty));
}
"""

# Read cube data
positions, faces, normals, texcoords = dataio.read_mesh('cube.obj')
colors = np.random.uniform(0, 1, positions.shape).astype('float32')

faces_buffer = gloo.ElementBuffer(faces.astype(np.uint16))


class Canvas(app.Canvas):
    def __init__(self, **kwargs):
        app.Canvas.__init__(self, **kwargs)
        self.geometry = 0, 0, 400, 400

        self.program = gloo.Program(VERT_CODE, FRAG_CODE)

        # Set attributes
        self.program['a_position'] = gloo.VertexBuffer(positions)
        self.program['a_texcoord'] = gloo.VertexBuffer(texcoords)

        self.program['u_texture'] = gloo.Texture2D(dataio.crate())