Ejemplo n.º 1
0
    def draw(self, event):
        if self.vt.codes is None: #not yet initialized
            return

        time_now = time.time()
        time_elapsed = time_now - self.start_time
        gl.glDepthMask(gl.GL_FALSE)
        gl.glEnable(gl.GL_BLEND)

        self.vbuffer["gindex"] = 2  # index of space in our font
        self.vbuffer["gindex"][:len(self.vt.codes)] = self.vt.codes
        self.vbuffer['fg'] = self.vt.buf['fg']/255
        self.vbuffer['bg'] = self.vt.buf['bg']/255
        self.handle_main_vbuffer()

        self.program1['time'] = time_elapsed*5
        gl.glBlendFuncSeparate(gl.GL_ONE,  gl.GL_ONE,
                               gl.GL_ZERO, gl.GL_ONE_MINUS_SRC_ALPHA)

        if not self.altscreen:
            self.vt.progman.draw(mouse=self.mouse)

        self.program.draw(self.program.GL_POINTS)

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_SRC_ALPHA)
        self.program1.draw(self.program1.GL_TRIANGLES)

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_SRC_ALPHA)
Ejemplo n.º 2
0
    def paint_spikes(self, data, scale=1.0):
        """Render the given array of neuron indexes."""

        # convert the data to a VBO
        vbo = glvbo.VBO(data)
        vbo.bind()

        # tell OpenGL that the VBO contains an array of vertices
        gl.glEnableVertexAttribArray(0)

        # array is a list of unsigned ints
        gl.glVertexAttribPointer(0, 1, gl.GL_UNSIGNED_INT,
                                 gl.GL_FALSE, 0, None)

        # activate the program
        gl.glUseProgram(self.program)
        gl.glUniform1f(self.scale, scale)

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendEquationSeparate(gl.GL_FUNC_ADD, gl.GL_FUNC_ADD)
        gl.glBlendFuncSeparate(gl.GL_ONE, gl.GL_ONE, 
                               gl.GL_ZERO, gl.GL_ONE)

        # draw the spikes
        gl.glDrawArrays(gl.GL_POINTS, 0, len(data))

        gl.glDisable(gl.GL_BLEND)
Ejemplo n.º 3
0
 def setup_blend(self):
     GL.glEnable(GL.GL_BLEND)
     if self.use_separate_blend:
         GL.glBlendEquationSeparate(*self.blend_equation_separate)
         GL.glBlendFuncSeparate(*self.blend_func_separate)
     else:
         GL.glBlendEquation(self.blend_equation)
         GL.glBlendFunc(*self.blend_func)
     GL.glEnable(GL.GL_DEPTH_TEST)
     GL.glDepthFunc(self.depth_test)
Ejemplo n.º 4
0
    def displayHeat(self, radius=150, points=[(200, 200)], alpha=0.5, left=0, bottom=0):
        # glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self.fbo) # Bind our frame buffer for rendering
        # gl.glPushAttrib(gl.GL_VIEWPORT_BIT | gl.GL_ENABLE_BIT) # Push our glEnable and glViewport states
        # gl.glViewport(0, 0, self.width, self.height) # Set the size of the frame buffer view port

        # gl.glClearColor(0.0, 0.0, 1.0, 1.0) # Set the clear colour
        # gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # Clear the depth and colour buffers
        # gl.glLoadIdentity() # Reset the modelview matrix

        #gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture)

        # Render all points with the specified radius
        gl.glUseProgram(self.fadedPointsProgram)

        gl.glUniform1f(gl.glGetUniformLocation(self.fadedPointsProgram, 'r'), radius)
        pointAttribLocation = gl.glGetAttribLocation(self.fadedPointsProgram, 'point')
        gl.glEnableVertexAttribArray(pointAttribLocation)
        gl.glVertexAttribPointer(pointAttribLocation, 2, gl.GL_FLOAT, False, 0,
                              struct.pack("ff" * 4 * len(points),
                                          *(val for (x, y) in points
                                                for val in (x - left, y - bottom) * 4)))
        # gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.fbo)
        # gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_ONE, gl.GL_ONE)

        vertices = [point for (x, y) in points
                          for point in ((x + radius, y + radius), (x - radius, y + radius),
                                        (x - radius, y - radius), (x + radius, y - radius))]
	gl.glVertexPointerd(vertices)
	gl.glDrawArrays(gl.GL_QUADS, 0, len(vertices))
        gl.glFlush()

        gl.glDisableVertexAttribArray(pointAttribLocation)

        # gl.glPopAttrib() # Restore our glEnable and glViewport states
        # glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) # Unbind our texture


        # Transform the color into the proper palette
        gl.glUseProgram(self.colorTransformProgram)
        gl.glUniform1f(gl.glGetUniformLocation(self.colorTransformProgram, 'alpha'), alpha)
        gl.glUniform1i(gl.glGetUniformLocation(self.colorTransformProgram, 'palette'), 0)
        gl.glUniform1i(gl.glGetUniformLocation(self.colorTransformProgram, 'framebuffer'), 1)
        gl.glUniform2f(gl.glGetUniformLocation(self.colorTransformProgram, 'windowSize'), self.width, self.height)

        # gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.fbo)
        #gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO)
        #gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)

        vertices = [(0, 0), (self.width, 0), (self.width, self.height), (0, self.height)]
	gl.glVertexPointerd(vertices)
	gl.glDrawArrays(gl.GL_QUADS, 0, len(vertices))
        gl.glFlush()
Ejemplo n.º 5
0
def shader_test(event_coll, event):
    """Use transfer function shader"""
    print("Changing shader to projection")
    scene = event_coll.scene
    for coll in scene.collections:
        coll.set_shader("default.v")
        coll.set_shader("transfer_function.f")
    scene.set_shader("passthrough.v")
    scene.set_shader("noop.f")
    for collection in scene.collections:
        collection.set_fields_log(True)
    #scene.update_minmax()
    # https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
    GL.glBlendEquationSeparate(GL.GL_FUNC_ADD, GL.GL_FUNC_ADD)
    GL.glBlendFuncSeparate(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA, GL.GL_ONE,
                           GL.GL_ZERO)
    return True
Ejemplo n.º 6
0
    def blend_mode(self, value):
        # type: (BlendMode) -> None
        if value is not self._blend_mode:
            self._blend_mode = value
            if value is BlendMode.none:
                GL.glBlendFunc(GL.GL_ONE, GL.GL_ZERO)

            elif value is BlendMode.add:
                try:
                    GL.glBlendFuncSeparate(GL.GL_SRC_ALPHA, GL.GL_ONE,
                                           GL.GL_ONE, GL.GL_ONE)
                except (NameError, Exception):
                    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE)

            elif value is BlendMode.alpha:
                try:
                    GL.glBlendFuncSeparate(GL.GL_SRC_ALPHA,
                                           GL.GL_ONE_MINUS_SRC_ALPHA,
                                           GL.GL_ONE,
                                           GL.GL_ONE_MINUS_SRC_ALPHA)
                except (NameError, Exception):
                    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

            elif value is BlendMode.multiply:
                try:
                    GL.glBlendFuncSeparate(GL.GL_ALPHA, GL.GL_ONE, GL.GL_ONE,
                                           GL.GL_ONE)
                except (NameError, Exception):
                    GL.glBlendFunc(GL.GL_DST_COLOR, GL.GL_ZERO)