Copyright | (c) 2017 Schell Scivally |
---|---|
License | MIT |
Maintainer | Schell Scivally <schell@takt.com> |
Safe Haskell | None |
Language | Haskell2010 |
This module provides font string rendering through the legendary freetype2. It automatically manages a texture atlas and word atlas to speed up rendering.
- freetypeRenderer2 :: MonadIO m => Backend GLuint e V2V2 (V2 Float) Float Raster -> Atlas -> V4 Float -> String -> m (Renderer2, V2 Float, Atlas)
- freetypePicture :: MonadIO m => Atlas -> String -> TexturePictureT m ()
- allocAtlas :: MonadIO m => FilePath -> GlyphSize -> String -> m (Maybe Atlas)
- asciiChars :: String
- freeAtlas :: MonadIO m => Atlas -> m ()
- loadWords :: MonadIO m => Backend GLuint e V2V2 (V2 Float) Float Raster -> Atlas -> String -> m Atlas
- unloadMissingWords :: MonadIO m => Atlas -> String -> m Atlas
- data Atlas = Atlas {}
- data GlyphSize
- glyphWidth :: GlyphSize -> Float
- glyphHeight :: GlyphSize -> Float
- data GlyphMetrics = GlyphMetrics {
- glyphTexBB :: (V2 Int, V2 Int)
- glyphTexSize :: V2 Int
- glyphSize :: V2 Int
- glyphHoriBearing :: V2 Int
- glyphVertBearing :: V2 Int
- glyphAdvance :: V2 Int
Getting straight to rendering
:: MonadIO m | |
=> Backend GLuint e V2V2 (V2 Float) Float Raster | The V2V2 backend to use for compilation. |
-> Atlas | The |
-> V4 Float | The solid color to render the string with. |
-> String | The string to render. This string can contain newlines, which will be respected. |
-> m (Renderer2, V2 Float, Atlas) | Returns the |
Constructs a Renderer2
from the given color and string. The WordMap
record of the given Atlas
is used to construct the string geometry, greatly
improving performance and allowing longer strings to be compiled and renderered
in real time. To create a new Atlas
see allocAtlas
.
Note that since word geometries are stored in the Atlas
WordMap
and multiple
renderers can reference the same Atlas
, the returned Renderer2
contains a
clean up operation that does nothing. It is expected that the programmer
will call freeAtlas
manually when the Atlas
is no longer needed.
Creating a gelatin picture
:: MonadIO m | |
=> Atlas | The |
-> String | The word to render. |
-> TexturePictureT m () | Returns a textured picture computation representing the texture and geometry of the input word. |
Constructs a TexturePictureT
of one word in all red.
Colorization can then be done using setReplacementColor
in the picture
computation, or by using redChannelReplacement
and passing that to the
renderer after compilation, at render time. Keep in mind that any new word
geometry will be discarded, since this computation does not return a new Atlas
.
For that reason it is advised that you load the needed words before using this
function. For loading words, see loadWords
.
This is used in freetypeRenderer2
to construct the geometry of each word.
freetypeRenderer2
goes further and stores these geometries, looking them up
and constructing a string of word renderers for each input String
.
Creating an Atlas
asciiChars :: String Source #
A string containing all standard ASCII characters.
This is often passed as the String
parameter in allocAtlas
.
freeAtlas :: MonadIO m => Atlas -> m () Source #
Releases all resources associated with the given Atlas
.
:: MonadIO m | |
=> Backend GLuint e V2V2 (V2 Float) Float Raster | The V2V2 backend needed to render font glyphs. |
-> Atlas | The atlas to load the words into. |
-> String | The string of words to load, with each word separated by spaces. |
-> m Atlas |
Load a string of words into the Atlas
.
Unload any words not contained in the source string.
Going deeper
Glyphs
glyphWidth :: GlyphSize -> Float Source #
glyphHeight :: GlyphSize -> Float Source #
Measuring glyphs
data GlyphMetrics Source #
GlyphMetrics | |
|