Пример #1
0
    def __init__(self, items=None):

        super(GlPointVertexArray, self).__init__()

        self._number_of_items = 0
        self._vertex_array_buffer = GlArrayBuffer()

        if items is not None:
            self.set(items)
Пример #2
0
    def __init__(self, items=None):

        super(RuleVertexArray, self).__init__()

        self._number_of_items = 0
        # Fixme: _buffer or _vbo
        self._positions_buffer = GlArrayBuffer() # could pass data here
        self._dimensions_buffer = GlArrayBuffer()
        self._colours_buffer = GlArrayBuffer()

        if items is not None:
            self.set(*items)
Пример #3
0
    def __init__(self, image_texture, items=None):

        super(TextVertexArray, self).__init__()

        self._image_texture = image_texture # Fixme: could contains several font and size
        self._font_atlas_shape = image_texture.shape

        self._number_of_items = 0
        self._positions_buffer = GlArrayBuffer() # could pass data here
        self._texture_coordinates_buffer = GlArrayBuffer()
        self._colours_buffer = GlArrayBuffer()

        if items is not None:
            self.set(*items)
Пример #4
0
class GlPointVertexArray(GlVertexArrayObject):

    """ Base class to draw primitives as points. """

    ##############################################
    
    def __init__(self, items=None):

        super(GlPointVertexArray, self).__init__()

        self._number_of_items = 0
        self._vertex_array_buffer = GlArrayBuffer()

        if items is not None:
            self.set(items)

    ##############################################
    
    def bind_to_shader(self, shader_program_interface_attribute):

        """ Bind the vertex array to the shader program interface attribute.
        """

        self.bind()
        shader_program_interface_attribute.bind_to_buffer(self._vertex_array_buffer)
        self.unbind()

    ##############################################
    
    def set(self, items):

        """ Set the vertex array from a numpy array. """

        self._number_of_items = items.shape[0]

        # make copy
        vertex = np.array(items, dtype='f') # dtype=np.float

        self._vertex_array_buffer.set(vertex)

    ##############################################
    
    def draw(self):

        """ Draw the vertex array as points. """

        self.bind()
        GL.glDrawArrays(GL.GL_POINTS, 0, self._number_of_items)
        self.unbind()
Пример #5
0
class GlPointVertexArray(GlVertexArrayObject):
    """ Base class to draw primitives as points. """

    ##############################################

    def __init__(self, items=None):

        super(GlPointVertexArray, self).__init__()

        self._number_of_items = 0
        self._vertex_array_buffer = GlArrayBuffer()

        if items is not None:
            self.set(items)

    ##############################################

    def bind_to_shader(self, shader_program_interface_attribute):
        """ Bind the vertex array to the shader program interface attribute.
        """

        self.bind()
        shader_program_interface_attribute.bind_to_buffer(
            self._vertex_array_buffer)
        self.unbind()

    ##############################################

    def set(self, items):
        """ Set the vertex array from a numpy array. """

        self._number_of_items = items.shape[0]

        # make copy
        vertex = np.array(items, dtype='f')  # dtype=np.float

        self._vertex_array_buffer.set(vertex)

    ##############################################

    def draw(self):
        """ Draw the vertex array as points. """

        self.bind()
        GL.glDrawArrays(GL.GL_POINTS, 0, self._number_of_items)
        self.unbind()
Пример #6
0
    def __init__(self, items=None):

        super(GlPointVertexArray, self).__init__()

        self._number_of_items = 0
        self._vertex_array_buffer = GlArrayBuffer()

        if items is not None:
            self.set(items)
    def __init__(self, path=None):

        super(LineVertexArray, self).__init__()
        
        self._number_of_objects = 0
        self._vertex_array_buffer = GlArrayBuffer()
        
        if path is not None:
            self.set(path)
Пример #8
0
    def __init__(self, items=None):

        super(RuleVertexArray, self).__init__()

        self._number_of_items = 0
        # Fixme: _buffer or _vbo
        self._positions_buffer = GlArrayBuffer()  # could pass data here
        self._dimensions_buffer = GlArrayBuffer()
        self._colours_buffer = GlArrayBuffer()

        if items is not None:
            self.set(*items)
Пример #9
0
    def __init__(self, image_texture, items=None):

        super(TextVertexArray, self).__init__()

        self._image_texture = image_texture  # Fixme: could contains several font and size
        self._font_atlas_shape = image_texture.shape

        self._number_of_items = 0
        self._positions_buffer = GlArrayBuffer()  # could pass data here
        self._texture_coordinates_buffer = GlArrayBuffer()
        self._colours_buffer = GlArrayBuffer()

        if items is not None:
            self.set(*items)
Пример #10
0
class RuleVertexArray(GlVertexArrayObject):

    _logger = _module_logger.getChild('RuleVertexArray')

    ##############################################

    def __init__(self, items=None):

        super(RuleVertexArray, self).__init__()

        self._number_of_items = 0
        # Fixme: _buffer or _vbo
        self._positions_buffer = GlArrayBuffer()  # could pass data here
        self._dimensions_buffer = GlArrayBuffer()
        self._colours_buffer = GlArrayBuffer()

        if items is not None:
            self.set(*items)

    ##############################################

    def set(self, positions, dimensions, colours):
        """ Set the vertex array from a numpy array. """

        self._number_of_items = positions.shape[0]

        self._positions_buffer.set(positions)
        self._dimensions_buffer.set(dimensions)
        self._colours_buffer.set(colours)

    ##############################################

    def bind_to_shader(self, shader_program_interface):

        self.bind()
        shader_program_interface.position.bind_to_buffer(
            self._positions_buffer)
        shader_program_interface.dimension.bind_to_buffer(
            self._dimensions_buffer)
        shader_program_interface.colour.bind_to_buffer(self._colours_buffer)
        self.unbind()

    ##############################################

    def draw(self):

        self.bind()
        GL.glDrawArrays(GL.GL_POINTS, 0, self._number_of_items)
        self.unbind()
Пример #11
0
class RuleVertexArray(GlVertexArrayObject):

    _logger = _module_logger.getChild('RuleVertexArray')

    ##############################################
    
    def __init__(self, items=None):

        super(RuleVertexArray, self).__init__()

        self._number_of_items = 0
        # Fixme: _buffer or _vbo
        self._positions_buffer = GlArrayBuffer() # could pass data here
        self._dimensions_buffer = GlArrayBuffer()
        self._colours_buffer = GlArrayBuffer()

        if items is not None:
            self.set(*items)

    ##############################################
    
    def set(self, positions, dimensions, colours):

        """ Set the vertex array from a numpy array. """

        self._number_of_items = positions.shape[0]

        self._positions_buffer.set(positions)
        self._dimensions_buffer.set(dimensions)
        self._colours_buffer.set(colours)

    ##############################################
    
    def bind_to_shader(self, shader_program_interface):

        self.bind()
        shader_program_interface.position.bind_to_buffer(self._positions_buffer)
        shader_program_interface.dimension.bind_to_buffer(self._dimensions_buffer)
        shader_program_interface.colour.bind_to_buffer(self._colours_buffer)
        self.unbind()

    ##############################################
    
    def draw(self):

        self.bind()
        GL.glDrawArrays(GL.GL_POINTS, 0, self._number_of_items)
        self.unbind()
Пример #12
0
class TextVertexArray(GlVertexArrayObject):

    """ This class wraps a Text Vertex Array. """

    _logger = _module_logger.getChild('TextVertexArray')

    ##############################################
    
    def __init__(self, image_texture, items=None):

        super(TextVertexArray, self).__init__()

        self._image_texture = image_texture # Fixme: could contains several font and size
        self._font_atlas_shape = image_texture.shape

        self._number_of_items = 0
        self._positions_buffer = GlArrayBuffer() # could pass data here
        self._texture_coordinates_buffer = GlArrayBuffer()
        self._colours_buffer = GlArrayBuffer()

        if items is not None:
            self.set(*items)

    ##############################################
    
    def set(self, positions, texture_coordinates, colours):

        """ Set the vertex array from a numpy array. """

        self._number_of_items = positions.shape[0]

        self._positions_buffer.set(positions)
        self._texture_coordinates_buffer.set(texture_coordinates)
        self._colours_buffer.set(colours)

    ##############################################
    
    def bind_to_shader(self, shader_program_interface):

        self.bind()

        shader_program_interface.position.bind_to_buffer(self._positions_buffer)
        shader_program_interface.position_uv.bind_to_buffer(self._texture_coordinates_buffer)
        shader_program_interface.colour.bind_to_buffer(self._colours_buffer)

        # Texture unit as default
        # shader_program.uniforms.texture0 = 0

        self.unbind()

    ##############################################
    
    def draw(self, shader_program):

        # Freetype renders glyph as grayscale: white foreground on black background
        #   If the LCD filter is enabled then the pixels on border are coloured.
        #   black fragment should be discarded
        #
        # Blending equation for transparency:
        #   O = (1-Sa)*D + Sa*S
        #     if Sa = 1 then O = S overwrite
        #           = 0 then O = D keep the value
        #
        # Grayscale case:
        #   S = luminosity * colour   grayscale = luminosity
        #   Sa = average luminosity * alpha ???
        #
        # LCD case:
        #   white -> red : (1,1,1) -> (1,0,0)

        # Blending: O = Sf*S + Df*D
        #  where S is the colour from the fragment shader and D the colour from the framebuffer
        #   alpha: fully transparent = 0 and fully opaque = 1
        #   Sa = average luminosity * colour aplha
        #
        # Set (Sf, Df) for transparency: O = Sa*S + (1-Sa)*D 

        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

        shader_program.bind()
        self._image_texture.bind()
        self.bind()

        shader_program.uniforms.font_atlas = 0
        # shader_program.uniforms.gamma = 1.

        GL.glDrawArrays(GL.GL_POINTS, 0, self._number_of_items)

        self.unbind()
        self._image_texture.unbind()
        shader_program.unbind()

        GL.glDisable(GL.GL_BLEND)
class LineVertexArray(GlVertexArrayObject):

    """ Base class to draw segments primitives as lines. """

    _logger = _module_logger.getChild('LineVertexArray')

    ##############################################

    def __init__(self, path=None):

        super(LineVertexArray, self).__init__()
        
        self._number_of_objects = 0
        self._vertex_array_buffer = GlArrayBuffer()
        
        if path is not None:
            self.set(path)

    ##############################################

    @property
    def number_of_points(self):
        return self._number_of_objects

    ##############################################

    def reset(self):

        self._number_of_objects = 0
        # Fixme: only for dynamic ?

    ##############################################

    def bind_to_shader(self, shader_program_interface_attribute):

        """ Bind the vertex array to the shader program interface attribute.
        """

        self.bind()
        shader_program_interface_attribute.bind_to_buffer(self._vertex_array_buffer)
        self.unbind()

    ##############################################

    def draw(self):

        """ Draw the vertex array as lines. """

        if self._number_of_objects >= 2:
            self.bind()
            GL.glDrawArrays(GL.GL_LINES, 0, self._number_of_objects)
            self.unbind()

    ##############################################

    def set(self, path):

        """ Set the vertex array from an iterable of segments. """

        # Fixme: make no sense, must be a list of paths

        self._number_of_objects = path.number_of_points # Right ?
        vertexes = np.zeros((self._number_of_objects, 2), dtype=np.float32)
        vertexes[...] = path.points
        # vertexes += .5 # Fixme: to shader
        self._vertex_array_buffer.set(vertexes)
Пример #14
0
class TextVertexArray(GlVertexArrayObject):
    """ This class wraps a Text Vertex Array. """

    _logger = _module_logger.getChild('TextVertexArray')

    ##############################################

    def __init__(self, image_texture, items=None):

        super(TextVertexArray, self).__init__()

        self._image_texture = image_texture  # Fixme: could contains several font and size
        self._font_atlas_shape = image_texture.shape

        self._number_of_items = 0
        self._positions_buffer = GlArrayBuffer()  # could pass data here
        self._texture_coordinates_buffer = GlArrayBuffer()
        self._colours_buffer = GlArrayBuffer()

        if items is not None:
            self.set(*items)

    ##############################################

    def set(self, positions, texture_coordinates, colours):
        """ Set the vertex array from a numpy array. """

        self._number_of_items = positions.shape[0]

        self._positions_buffer.set(positions)
        self._texture_coordinates_buffer.set(texture_coordinates)
        self._colours_buffer.set(colours)

    ##############################################

    def bind_to_shader(self, shader_program_interface):

        self.bind()

        shader_program_interface.position.bind_to_buffer(
            self._positions_buffer)
        shader_program_interface.position_uv.bind_to_buffer(
            self._texture_coordinates_buffer)
        shader_program_interface.colour.bind_to_buffer(self._colours_buffer)

        # Texture unit as default
        # shader_program.uniforms.texture0 = 0

        self.unbind()

    ##############################################

    def draw(self, shader_program):

        # Freetype renders glyph as grayscale: white foreground on black background
        #   If the LCD filter is enabled then the pixels on border are coloured.
        #   black fragment should be discarded
        #
        # Blending equation for transparency:
        #   O = (1-Sa)*D + Sa*S
        #     if Sa = 1 then O = S overwrite
        #           = 0 then O = D keep the value
        #
        # Grayscale case:
        #   S = luminosity * colour   grayscale = luminosity
        #   Sa = average luminosity * alpha ???
        #
        # LCD case:
        #   white -> red : (1,1,1) -> (1,0,0)

        # Blending: O = Sf*S + Df*D
        #  where S is the colour from the fragment shader and D the colour from the framebuffer
        #   alpha: fully transparent = 0 and fully opaque = 1
        #   Sa = average luminosity * colour aplha
        #
        # Set (Sf, Df) for transparency: O = Sa*S + (1-Sa)*D

        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

        shader_program.bind()
        self._image_texture.bind()
        self.bind()

        shader_program.uniforms.font_atlas = 0
        # shader_program.uniforms.gamma = 1.

        GL.glDrawArrays(GL.GL_POINTS, 0, self._number_of_items)

        self.unbind()
        self._image_texture.unbind()
        shader_program.unbind()

        GL.glDisable(GL.GL_BLEND)