(self, text, coordinates=(0., 0.), font='segoe', fontsize=24,
            color=None, letter_spacing=None, interline=0., autocolor=None,
            background_transparent=True,
            prevent_constrain=False, depth=None, posoffset=None)
Initialize the text template.
Initialize the text template.
Initialize the text template .
def initialize(self, text, coordinates=(0., 0.), font='segoe', fontsize=24,
            color=None, letter_spacing=None, interline=0., autocolor=None,
            background_transparent=True,
            prevent_constrain=False, depth=None, posoffset=None):
        """Initialize the text template."""
        
        if prevent_constrain:
            self.constrain_ratio = False
            
        if autocolor is not None:
            color = get_color(autocolor)
            
        if color is None:
            color = self.default_color
        
        self.size = len(text)
        self.primitive_type = 'POINTS'
        self.interline = interline
        
        text_length = self.size
        self.initialize_font(font, fontsize)
        self.coordinates = coordinates
        
        point_size = float(self.matrix[:,4].max() * self.texture.shape[1])

        # template attributes and varyings
        self.add_attribute("position", vartype="float", ndim=2, data=np.zeros((self.size, 2)))
            
        self.add_attribute("offset", vartype="float", ndim=1)
        self.add_attribute("index", vartype="float", ndim=1)
        self.add_attribute("text_map", vartype="float", ndim=4)
        self.add_varying("flat_text_map", vartype="float", flat=True, ndim=4)
       
        if posoffset is None:
            posoffset = (0., 0.)
        self.add_uniform('posoffset', vartype='float', ndim=2, data=posoffset)
       
        # texture
        self.add_texture("tex_sampler", size=self.texture.shape[:2], ndim=2,
                            ncomponents=self.texture.shape[2],
                            data=self.texture)
        
        # pure heuristic (probably bogus)
        if letter_spacing is None:
            letter_spacing = (100 + 17. * fontsize)
        self.add_uniform("spacing", vartype="float", ndim=2,
                            data=(letter_spacing, interline))
        self.add_uniform("point_size", vartype="float", ndim=1,
                            data=point_size)
        # one color per
        if isinstance(color, np.ndarray) and color.ndim > 1:
            self.add_attribute('color0', vartype="float", ndim=4, data=color)
            self.add_varying('color', vartype="float", ndim=4)
            self.add_vertex_main('color = color0;')
        else:
            self.add_uniform("color", vartype="float", ndim=4, data=color)
        self.add_uniform("text_width", vartype="float", ndim=1)
        
        # compound variables
        self.add_compound("text", fun=self.text_compound, data=text)
        self.add_compound("coordinates", fun=self.position_compound, data=coordinates)

        # vertex shader
        self.add_vertex_main(VS, after='viewport')

        # fragment shader
        self.add_fragment_main(FS(background_transparent))
        
        self.depth = depth
def initialize ( self , text , coordinates = ( 0. , 0. ) , font = 'segoe' , fontsize = 24 , color = None , letter_spacing = None , interline = 0. , autocolor = None , background_transparent = True , prevent_constrain = False , depth = None , posoffset = None ) : if prevent_constrain : self . constrain_ratio = False if autocolor is not None : color = get_color ( autocolor ) if color is None : color = self . default_color self . size = len ( text ) self . primitive_type = 'POINTS' self . interline = interline text_length = self . size self . initialize_font ( font , fontsize ) self . coordinates = coordinates point_size = float ( self . matrix [ : , 4 ] . max ( ) * self . texture . shape [ 1 ] ) # template attributes and varyings self . add_attribute ( "position" , vartype = "float" , ndim = 2 , data = np . zeros ( ( self . size , 2 ) ) ) self . add_attribute ( "offset" , vartype = "float" , ndim = 1 ) self . add_attribute ( "index" , vartype = "float" , ndim = 1 ) self . add_attribute ( "text_map" , vartype = "float" , ndim = 4 ) self . add_varying ( "flat_text_map" , vartype = "float" , flat = True , ndim = 4 ) if posoffset is None : posoffset = ( 0. , 0. ) self . add_uniform ( 'posoffset' , vartype = 'float' , ndim = 2 , data = posoffset ) # texture self . add_texture ( "tex_sampler" , size = self . texture . shape [ : 2 ] , ndim = 2 , ncomponents = self . texture . shape [ 2 ] , data = self . texture ) # pure heuristic (probably bogus) if letter_spacing is None : letter_spacing = ( 100 + 17. * fontsize ) self . add_uniform ( "spacing" , vartype = "float" , ndim = 2 , data = ( letter_spacing , interline ) ) self . add_uniform ( "point_size" , vartype = "float" , ndim = 1 , data = point_size ) # one color per if isinstance ( color , np . ndarray ) and color . ndim > 1 : self . add_attribute ( 'color0' , vartype = "float" , ndim = 4 , data = color ) self . add_varying ( 'color' , vartype = "float" , ndim = 4 ) self . add_vertex_main ( 'color = color0;' ) else : self . add_uniform ( "color" , vartype = "float" , ndim = 4 , data = color ) self . add_uniform ( "text_width" , vartype = "float" , ndim = 1 ) # compound variables self . add_compound ( "text" , fun = self . text_compound , data = text ) self . add_compound ( "coordinates" , fun = self . position_compound , data = coordinates ) # vertex shader self . add_vertex_main ( VS , after = 'viewport' ) # fragment shader self . add_fragment_main ( FS ( background_transparent ) ) self . depth = depth