The TextProgram extends a Program to display text by using a 8x8 pixels monospace bitmapfont.
It can handle multiple Text-instances and uses a BMFontData with BMFont.data by default.
Constructor
@:value({ growBufferSize : 1024, minBufferSize : 1024 })new(?fontData:BMFontData, ?textOptions:TextOptions, minBufferSize:Int = 1024, growBufferSize:Int = 1024)
Creates a new TextProgram instance.
Parameters:
fontData | the BMFontData what specifies the bitmap-font |
|---|
textOptions | the TextOptions what is used as defaults if not set inside of a Text instance |
|---|
minBufferSize | how many glyphes the buffer should contain as a minimum |
|---|
growBufferSize | the size by which the buffer should grow when it is full |
|---|
Variables
@:value(new Array<Text>())read onlytexts:Array<Text> = new Array<Text>()
Contains all added Text instances.
@:value({ fgColor : 0xf0f0f0ff, bgColor : 0, letterWidth : 8, letterHeight : 8, letterSpace : 0, lineSpace : 0, zIndex : 0 })defaultOptions:TextOptions = { fgColor : 0xf0f0f0ff, bgColor : 0, letterWidth : 8, letterHeight : 8, letterSpace : 0, lineSpace : 0, zIndex : 0 }
These are the default TextOptions values that are used if an option has not been defined within the Text instance.
Methods
create(x:Int, y:Int, textString:String, textOptions:TextOptions):Text
Create a new Text instance automatically by a defined text-string and adds it.
Parameters:
text | the Text instance to update |
|---|
@:value({ updateDefaultOptions : false })add(text:Text, updateDefaultOptions:Bool = false):Text
Adds a Text to the program.
Parameters:
text | the Text instance to add |
|---|
updateDefaultOptions | to force an update of the programs default options |
|---|
@:value({ updateDefaultOptions : false })updateText(text:Text, updateDefaultOptions:Bool = false):Void
Updates the changes of a Text instance that have been added.
Parameters:
text | the Text instance to update |
|---|
updateDefaultOptions | to force an update of the programs default options |
|---|
@:value({ updateDefaultOptions : false })updateAll(updateDefaultOptions:Bool = false):Void
Updates the changes of all Text instances that have been added.
Parameters:
updateDefaultOptions | to force an update of the programs default options |
|---|
Removes a Text from the program.
Parameters:
text | the Text instance to remove |
|---|
Removes all Text instances that have been added.
Inherited Variables
The Display instances in which the program is contained.
read onlybuffer:BufferInterface
@:value(true)isVisible:Bool = true
Shows or hides the program during rendering.
To enable or disable the color/alpha blendmode.
@:value(false)blendSeparate:Bool = false
Use a separate blend-function for the alpha channel if the blendmode is enabled.
Separate blend-function for the alpha channel if blendSeparate is true.
BlendFactor for the destination colors if into blendmode.
BlendFactor for the source alpha channel if into blendmode.
BlendFactor for the destination alpha channel if into blendmode.
BlendFunc for the color channels if into blendmode.
BlendFunc for the alpha channel if into blendmode.
Enable or disable the use of the depth buffer and perform a depth test to write new pixels.
@:value(true)depthMask:Bool = true
If this value is true, new z-values can be written to the depth buffer. This only has an effect if zIndexEnabled is true.
@:value(false)clearDepth:Bool = false
Clears the depth-buffer by clearDepthIndex value before rendering. This only has an effect if zIndexEnabled is true.
Index for initializing the depth buffer when clearDepth is enabled.
@:value(DepthFunc.LESS_EQUAL)depthFunc:DepthFunc = DepthFunc.LESS_EQUAL
To set the equivalent OpenGL DepthFunc for depth-testing. This only has an effect if zIndexEnabled is true.
@:value(true)colorEnabled:Bool = true
Enable or disable color rendering. If enabled, individual channels can be turned on or off using enableColorChannel().
Can be disabled, for example, to render only in the stencil buffer for masking.
@:value(Mask.OFF)mask:Mask = Mask.OFF
To use the stencil-buffer for masking or to draw into it to use it afterwards by another program.
@:value(false)clearMask:Bool = false
Clears the stencil-buffer.
@:value(true)autoUpdate:Bool = true
Enable automatic shader generation for functioncalls what set, add or remove textures (also for snapToPixel, discardAtAlpha, shadercode-injection, formula and precision changes)
Inherited Methods
inlineshow():Void
Shows the program during rendering.
inlinehide():Void
Hides the program during rendering.
Returns true is this program is inside the RenderList of a Display instance.
Parameters:
@:value({ addBefore : false })addToDisplay(display:Display, ?atProgram:Program, addBefore:Bool = false):Void
Adds this program to the RenderList of a Display instance.
Can be also used to change the order (relative to another program) if it is already added.
Parameters:
display | Display instance |
|---|
atProgram | (optional) to add or move before or after another program in the RenderList (by default at start or at end) |
|---|
addBefore | (optional) if 'true' it's added before another program or at start of the Renderlist (by default it's added after atProgram or at end) |
|---|
Removes this program from the RenderList of a Display instance.
Parameters:
inlineenableColorChannel(enableRed:Bool, enableGreen:Bool, enableBlue:Bool, enableAlpha:Bool):Void
Specifies whether the red, green, blue, and alpha channels are enabled for writing to the color buffer.
Only has an effect if colorEnabled is true.
Parameters:
enableRed | true to enable red channel |
|---|
enableGreen | true to enable green channel |
|---|
enableBlue | true to enable blue channel |
|---|
enableAlpha | true to enable alpha channel |
|---|
@:value({ varDefaults : null, formula : "" })setColorFormula(formula:String = "", ?varDefaults:StringMap<Color>, ?autoUpdate:Bool):Void
Set a formula to combine the colors of @texUnits together with the @color attributes of an element.
Parameters:
formula | a String what contains the color formula |
|---|
varDefaults | defines the default colors by a Map with the texUnit identifiers as keys |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
@:value({ uniformFloats : null, uTimeUniformEnabled : false, glslCode : "" })injectIntoVertexShader(glslCode:String = "", uTimeUniformEnabled:Bool = false, ?uniformFloats:Array<UniformFloat>, ?autoUpdate:Bool):Void
Inject custom glsl code into the vertexshader of a program.
Parameters:
glslCode | a String what contains the glsl code |
|---|
uTimeUniformEnabled | if true you can use the global time uiform |
|---|
uniformFloats | an Array of custom UniformFloats |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
@:value({ uniformFloats : null, uTimeUniformEnabled : false, glslCode : "" })injectIntoFragmentShader(glslCode:String = "", uTimeUniformEnabled:Bool = false, ?uniformFloats:Array<UniformFloat>, ?autoUpdate:Bool):Void
Inject custom glsl code into the fragmentshader of a program.
Parameters:
glslCode | a String what contains the glsl code |
|---|
uTimeUniformEnabled | if true you can use the global time uiform |
|---|
uniformFloats | an Array of custom UniformFloats |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
setFormula(name:String, newFormula:String, ?autoUpdate:Bool):Void
Define formulas to change the calculation for element attributes at runtime
Parameters:
name | a String with the attribute identifier |
|---|
newFormula | a String what contains the formula |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
Set the float precision for the fragmentshader
Parameters:
precision | a String what can be "low", "medium" or "high" |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
Set the integer precision for the fragmentshader
Parameters:
precision | a String what can be "low", "medium" or "high" |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
Set the sampler2D precision for the fragmentshader
Parameters:
precision | a String what can be "low", "medium" or "high" |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
Set the float precision for the vertexShader
Parameters:
precision | a String what can be "low", "medium" or "high" |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
Set the integer precision for the vertexShader
Parameters:
precision | a String what can be "low", "medium" or "high" |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
Set the sampler2D precision for the vertexShader
Parameters:
precision | a String what can be "low", "medium" or "high" |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
snapToPixel(?pixelDivisor:Float, ?autoUpdate:Bool):Void
Activate pixelsnapping
Parameters:
pixelDivisor | a Float multiplicator at which snapping is to take place, set it to null to disable pixelsnapping |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
discardAtAlpha(?atAlphaValue:Float, ?autoUpdate:Bool):Void
From which alpha value the pixels are discarded.
Parameters:
atAlphaValue | a Float value for the alpha limit (0.0 to 1.0), set it to null to disable discarding |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
setTexture(texture:Texture, ?identifier:String, ?autoUpdate:Bool):Void
Assign a Texture instance to a texture-layer (by identifier).
Parameters:
texture | Texture instance |
|---|
identifier | texture-layer identifier (optional) - without it, the first available or "default" is used |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
setMultiTexture(textureUnits:Array<Texture>, ?identifier:String, ?autoUpdate:Bool):Void
Assign multiple Texture instances to a texture-layer (by identifier). Can switch between them by using an @texUnit("identifier") integer attribute inside the Element.
Parameters:
textureUnits | an Array of Texture instances |
|---|
identifier | texture-layer identifier (optional) - without it, the first available or "default" is used |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
addTexture(texture:Texture, ?identifier:String, ?autoUpdate:Bool):Void
Adds a Texture to a texture-layer (by identifier). Can switch between them by using an @texUnit("identifier") integer attribute inside the Element.
Parameters:
texture | Texture instance |
|---|
identifier | texture-layer identifier (optional) - without it, the first available or "default" is used |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
removeTexture(texture:Texture, ?identifier:String, ?autoUpdate:Bool):Void
Removes a Texture from a texture-layer (by identifier) or from all layers where it is used.
Parameters:
texture | Texture instance |
|---|
identifier | texture-layer identifier (optional) |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
removeAllTexture(?identifier:String, ?autoUpdate:Bool):Void
Removes all Textures of a texture-layer (by identifier) or removes all textures from all layers.
Parameters:
identifier | texture-layer identifier (optional) |
|---|
autoUpdate | set it to true (update) or false (no update), otherwise the .autoUpdate property is used |
|---|
hasTexture(texture:Texture, ?identifier:String):Bool
Returns true if the program or a specific texture-layer contains a texture.
Parameters:
texture | Texture instance |
|---|
identifier | texture-layer identifier, if set to null it searches into all texture-layers |
|---|
Updates the shader templates and recompiles the shader.
To set the opengl index manually if using multiple textures.
Parameters:
texture | Texture instance |
|---|
index | Integer value for the index (starts by 0) |
|---|