Esempio n. 1
0
 def on_initialize(self, event):
     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)  # _MINUS_SRC_ALPHA)
     # Start the timer upon initialization.
     self.timer.start()
Esempio n. 2
0
File: atom.py Progetto: LiloD/vispy
 def on_initialize(self, event):
     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_MINUS_SRC_ALPHA)
     gl.glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)
     gl.glEnable(GL_POINT_SPRITE)
Esempio n. 3
0
 def on_initialize(self, event):
     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) #_MINUS_SRC_ALPHA)
     # Start the timer upon initialization.
     self.timer.start()
Esempio n. 4
0
    def draw_points(self):

        gl.glDisable(gl.GL_BLEND)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glDepthMask(gl.GL_TRUE)

        self.program_points.draw('points')
Esempio n. 5
0
 def _draw_context(self):
     if self._rect_clip is None:
         yield
     else:
         gl.glEnable(gl.GL_SCISSOR_TEST);
         gloo.set_scissor(*self._rect_clip)
         yield
         gl.glDisable(gl.GL_SCISSOR_TEST);
Esempio n. 6
0
    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),
                                    ('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)
Esempio n. 7
0
    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)
Esempio n. 8
0
    def draw_model(self):

        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glDepthMask(gl.GL_TRUE)
        gl.glFrontFace(gl.GL_CCW)
        gl.glDisable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_ZERO, gl.GL_ZERO)

        if self.render_params['transparent']:

            gl.glEnable(gl.GL_BLEND)
            gl.glDepthMask(gl.GL_FALSE)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        self.program_solids.draw('triangles')
Esempio n. 9
0
def _test_enabling_disabling():
    # Enabling/disabling
    gl.glEnable(gl.GL_DEPTH_TEST)
    assert_equal(gl.glIsEnabled(gl.GL_DEPTH_TEST), True)
    assert_equal(gl.glGetParameter(gl.GL_DEPTH_TEST), 1)
    gl.glDisable(gl.GL_DEPTH_TEST)
    assert_equal(gl.glIsEnabled(gl.GL_DEPTH_TEST), False)
    assert_equal(gl.glGetParameter(gl.GL_DEPTH_TEST), 0)
    #
    gl.glEnable(gl.GL_BLEND)
    assert_equal(gl.glIsEnabled(gl.GL_BLEND), True)
    assert_equal(gl.glGetParameter(gl.GL_BLEND), 1)
    gl.glDisable(gl.GL_BLEND)
    assert_equal(gl.glIsEnabled(gl.GL_BLEND), False)
    assert_equal(gl.glGetParameter(gl.GL_BLEND), 0)

    gl.check_error()
Esempio n. 10
0
def _test_enabling_disabling():
    # Enabling/disabling
    gl.glEnable(gl.GL_DEPTH_TEST)
    assert_equal(gl.glIsEnabled(gl.GL_DEPTH_TEST), True)
    assert_equal(gl.glGetParameter(gl.GL_DEPTH_TEST), 1)
    gl.glDisable(gl.GL_DEPTH_TEST)
    assert_equal(gl.glIsEnabled(gl.GL_DEPTH_TEST), False)
    assert_equal(gl.glGetParameter(gl.GL_DEPTH_TEST), 0)
    #
    gl.glEnable(gl.GL_BLEND)
    assert_equal(gl.glIsEnabled(gl.GL_BLEND), True)
    assert_equal(gl.glGetParameter(gl.GL_BLEND), 1)
    gl.glDisable(gl.GL_BLEND)
    assert_equal(gl.glIsEnabled(gl.GL_BLEND), False)
    assert_equal(gl.glGetParameter(gl.GL_BLEND), 0)
    
    gl.check_error()
Esempio n. 11
0
    def on_paint(self, event):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        with self.program as prog:
            # Filled cube
            gl.glDisable(gl.GL_BLEND)
            gl.glEnable(gl.GL_DEPTH_TEST)
            gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
            prog['u_color'] = 1, 1, 1, 1
            prog.draw(gl.GL_TRIANGLES, self.filled_buf)

            # Outline
            gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
            gl.glEnable(gl.GL_BLEND)
            gl.glDepthMask(gl.GL_FALSE)
            prog['u_color'] = 0, 0, 0, 1
            prog.draw(gl.GL_LINES, self.outline_buf)
            gl.glDepthMask(gl.GL_TRUE)
Esempio n. 12
0
def draw_depth(camera, renderables, rend_target):
    rendfb, rendtex, _ = rend_target

    material = DepthMaterial()
    program = DepthMaterial().compile()

    with rendfb:
        gloo.clear(color=camera.clear_color)
        gloo.set_state(depth_test=True)
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glCullFace(gl.GL_FRONT)
        for renderable in renderables:
            material.upload_camera(program, camera)
            material.upload_attributes(program, renderable._attributes)
            program['u_model'] = renderable.model_mat.T
            program.draw(gl.GL_TRIANGLES)
        gl.glCullFace(gl.GL_BACK)
        gl.glDisable(gl.GL_CULL_FACE)
Esempio n. 13
0
 def on_initialize(self, event):
     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_MINUS_SRC_ALPHA)
Esempio n. 14
0
File: atom.py Progetto: ds604/vispy
 def on_initialize(self, event):
     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_MINUS_SRC_ALPHA)
Esempio n. 15
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     if self.enabled:
         gl.glDisable(GL_CONSERVATIVE_RASTERIZATION_NV)
Esempio n. 16
0
    def on_draw(self, event):

        # Read about depth testing and changing stated in vispy here http://vispy.org/gloo.html?highlight=set_state
        gloo.clear(color=[0, 0, 0, 1.0], depth=True)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_REPLACE)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT
                   | gl.GL_STENCIL_BUFFER_BIT)

        gl.glStencilFunc(gl.GL_ALWAYS, 1, 0xFF)
        gl.glStencilMask(0xFF)

        # delta_time
        self.current_frame = time()
        self.delta_time = self.current_frame - self.last_frame
        self.last_frame = self.current_frame

        if self.camera.bool_a:
            self.camera.ProcessKeyboard(Camera_Movement.LEFT, self.delta_time)
        if self.camera.bool_w:
            self.camera.ProcessKeyboard(Camera_Movement.FORWARD,
                                        self.delta_time)
        if self.camera.bool_s:
            self.camera.ProcessKeyboard(Camera_Movement.BACKWARD,
                                        self.delta_time)
        if self.camera.bool_d:
            self.camera.ProcessKeyboard(Camera_Movement.RIGHT, self.delta_time)

        self.view = self.camera.GetViewMatrix()
        self.projection = glm.perspective(glm.radians(self.camera.Zoom),
                                          builtins.width / builtins.height,
                                          0.1, 100.0)

        # vispy takes numpy array in m * n matrix form
        self.view = (np.array(self.view.to_list()).astype(np.float32))
        self.projection = (np.array(self.projection.to_list()).astype(
            np.float32))

        # reshaping to (m, n) to (1, m*n) to support data input in vispy
        self.view = self.view.reshape(
            (1, self.view.shape[0] * self.view.shape[1]))
        self.projection = self.projection.reshape(
            (1, self.projection.shape[0] * self.projection.shape[1]))

        # drawing normal cube
        self.program['view'] = self.view
        self.program['projection'] = self.projection
        self.program['a_position'] = self.vertices
        self.program['aNormal'] = self.aNormal
        self.program['viewPos'] = self.camera.Position
        self.program['texCoords'] = self.texCoord

        self.program['l_ambient[0]'] = [0.2, 0.2, 0.2]
        self.program['l_diffuse[0]'] = [1, 1, 0.5]
        self.program['l_specular[0]'] = [1.0, 1.0, 1.0]
        self.program['l_direction[0]'] = [-0.3, -1, -1]
        self.program['m_diffuse[0]'] = self.diffuse_map
        self.program['m_shininess[0]'] = 32
        self.program['m_specular[0]'] = self.specular_map

        self.model = glm.mat4(1.0)
        # rotate the cube if you want
        # self.model = glm.rotate(self.model, glm.radians((time() - self.startTime) * 10), glm.vec3(0,1.5,1))
        self.model = glm.translate(self.model, glm.vec3(0, 0.5, 0))
        self.model = (np.array(self.model.to_list()).astype(np.float32))
        self.model = self.model.reshape(
            (1, self.model.shape[0] * self.model.shape[1]))
        self.program['model'] = self.model
        self.program.draw('triangles')

        self.model = glm.mat4(1.0)
        self.model = glm.translate(self.model, glm.vec3(0.5, 0.5, 2))
        self.model = (np.array(self.model.to_list()).astype(np.float32))
        self.model = self.model.reshape(
            (1, self.model.shape[0] * self.model.shape[1]))
        self.program['model'] = self.model
        self.program.draw('triangles')

        self.program['a_position'] = self.vertices * 10
        self.model = glm.mat4(1.0)
        self.model = glm.translate(self.model, glm.vec3(0, -5, 0))
        self.model = (np.array(self.model.to_list()).astype(np.float32))
        self.model = self.model.reshape(
            (1, self.model.shape[0] * self.model.shape[1]))
        self.program['model'] = self.model
        self.program.draw('triangles')

        gl.glStencilFunc(gl.GL_NOTEQUAL, 1, 0xFF)
        gl.glStencilMask(0x00)
        gl.glDisable(gl.GL_DEPTH_TEST)

        self.model = glm.mat4(1.0)
        self.model = glm.translate(self.model, [0, 0.5, 0])
        self.model = (np.array(self.model.to_list()).astype(np.float32))
        self.model = self.model.reshape(
            (1, self.model.shape[0] * self.model.shape[1]))

        # drawing light source
        self.programLightSource['model'] = self.model
        self.programLightSource['view'] = self.view
        self.programLightSource['projection'] = self.projection
        self.programLightSource['a_position'] = self.vertices * 1.2

        self.programLightSource.draw('triangles')

        gl.glStencilMask(0xFF)
        gl.glStencilFunc(gl.GL_ALWAYS, 1, 0xFF)
        gl.glEnable(gl.GL_DEPTH_TEST)

        self.update()