Constructor for Text class. The text is rendered using the browser's canvas element and then copyied into a texture, so the parameters are based on what is understood by CanvasRenderingContext2D. Shortcuts are provided for fillStyle, backgroundStyle, and strokeStyle to use the gfx.Color types if that is more convenient for your application.
The text to be rendered
The width of the text canvas
The height of the text canvas
The font style of the text. Can be a gfx.Color or see additional options for canvas.font.
The fill style of the text. Can be a gfx.Color or see additional options for canvas.fillStyle.
The fill style of the background. Can be a gfx.Color or see additional options for canvas.fillStyle.
The stroke style of the text. Can be a gfx.Color or see additional options for canvas.strokeStyle.
The stroke width of the text.
The alignment of the text. See possible values in canvas.textAlign
The baseline of the text. See possible values in canvas.textBaseline.
Protected Readonly glThe height of the original (non-mipmapped) texture image data or 'undefined' if the image has not yet completed loading.
Private textThe internal object used by WebGL to draw this texture -- provides each texture a unique id.
The width of the original (non-mipmapped) texture image data or 'undefined' if the image has not yet completed loading.
Callback function for image loaded events
HTML DOM image element produced by loading the image texture
Original URL the image was loaded from (used as an internal identifier for the image asset)
Load an image into this texture.
URL to load the texture from (can be absolute, e.g. "http://unlikely-url.com/some-image.jpg", or relative, e.g. "./some-image.jpg"). Can be null to start out with, in which case the texture will be empty.
Copies the pixel data from an ImageData source into a portion of the texture, placing it as a sub-image within the texture
An ImageData object with width and height that are the same size or smaller than the texture
An offset in the x-direction within the texture where the top-left corner of imageData should be placed
An offset in the y-direction within the texture where the top-left corner of imageData should be placed
Updates the texture image of the Text class
Sets the width and height of the canvas, font, text alignment, and baseline. Fills the canvas with the background style if specified. Fills the text with the fill style if specified. Strokes the text with the stroke style and stroke width if specified. Binds the texture and generated mipmap.
Generated using TypeDoc
The GopherGfx.Text class is a special type of texture that renders text generated by the text routines built into the browser's canvas into a computer graphics texture with a specified size in pixels. Many options are available for the style of the text because everything that is supported by the browser's built-in text rendering can be used. (See documentation on the constructor for links to relevant options.)
To draw the text, the text texture is applied just like any other texture to a mesh added to the scene. Just as when using any other texture, the mesh must have texture coordinates defined. And, the Text object is simply applied to the mesh material's texture.
In the texture image that is generated, the pixels belonging to letters will colored according to the fill style, and the other pixels will be transparent.
To get the best color mixing when letters overlap on the screen, set the fill style to gfx.Color.WHITE when creating the texture, and then adjust the color using the mesh material's color property, like in the example above, where material.color is set to red.