Graphics.Rendering.FTGL
Description
- Author: Jefferson Heard (jefferson.r.heard at gmail.com)
- Copyright 2008 Renaissance Computing Institute http://www.renci.org
- License: GNU LGPL
- Compatibility GHC (I could change the data declarations to not be empty and that would make it more generally compatible, I believe)
- Description:
Use FreeType 2 Fonts in OpenGL. Requires the FTGL library and FreeType libraries. available at http://ftgl.wiki.sourceforge.net/ . The most important functions for everyday use are renderFont and the create*Font family of functions. To render a simple string inside OpenGL, assuming you have OpenGL initialized and a current pen color, all you need is:
do font <- createTextureFont "Font.ttf" setFontFaceSize font 24 72 renderFont font "Hello world!"
Fonts are rendered so that a single point is an OpenGL unit, and a point is 1:72 of an inch.
- createBitmapFont :: String -> IO Font
- createBufferFont :: String -> IO Font
- createOutlineFont :: String -> IO Font
- createPixmapFont :: String -> IO Font
- createPolygonFont :: String -> IO Font
- createTextureFont :: String -> IO Font
- createExtrudeFont :: String -> IO Font
- type Glyph = Ptr Glyph_Opaque
- type Font = Ptr Font_Opaque
- type Layout = Ptr Layout_Opaque
- createSimpleLayout :: IO Layout
- getLayoutFont :: Layout -> Font
- setLayoutFont :: Layout -> Font -> IO ()
- getLayoutAlignment :: Layout -> TextAlignment
- setLayoutAlignment :: Layout -> CInt -> IO ()
- getLayoutLineLength :: Layout -> Float
- setLayoutLineLength :: Layout -> CFloat -> IO ()
- setLayoutLineSpacing :: Layout -> CFloat -> IO ()
- destroyFont :: Font -> IO ()
- attachData :: Font -> Ptr () -> IO ()
- attachFile :: Font -> String -> IO ()
- setFontCharMap :: Font -> CInt -> IO ()
- setFontFaceSize :: Font -> Int -> Int -> IO CInt
- getFontFaceSize :: Font -> Int
- setFontFaceDepth :: Font -> CInt -> IO ()
- getFontBBox :: Font -> String -> [Float]
- getFontAdvance :: Font -> String -> Float
- renderFont :: Font -> String -> RenderMode -> IO ()
- getFontError :: Font -> Int
- destroyLayout :: Layout -> IO ()
- renderLayout :: Layout -> String -> IO ()
- getLayoutError :: Layout -> CInt
- data RenderMode
- data TextAlignment
- = AlignLeft
- | AlignCenter
- | AlignRight
- | Justify
Documentation
createBitmapFont :: String -> IO FontSource
Create a bitmapped version of a TrueType font. Bitmapped versions will not | respond to matrix transformations, but rather must be transformed using the | raster positioning functions in OpenGL
createBufferFont :: String -> IO FontSource
Create a buffered version of a TrueType font. This stores the entirety of | a string in a texture, buffering it before rendering. Very fast if you | will be repeatedly rendering the same strings over and over.
createOutlineFont :: String -> IO FontSource
Create an outline version of a TrueType font. This uses actual geometry | and will scale independently without loss of quality. Faster than polygons | but slower than texture or buffer fonts.
createPixmapFont :: String -> IO FontSource
Create a pixmap version of a TrueType font. Higher quality than the bitmap | font without losing any performance. Use this if you don't mind using | set and get RasterPosition.
createPolygonFont :: String -> IO FontSource
Create polygonal display list fonts. These scale independently without | losing quality, unlike texture or buffer fonts, but can be impractical | for large amounts of text because of the high number of polygons needed. | Additionally, they do not, unlike the textured fonts, create artifacts | within the square formed at the edge of each character.
createTextureFont :: String -> IO FontSource
Create textured display list fonts. These can scale somewhat well, | but lose quality quickly. They are much faster than polygonal fonts, | though, so are suitable for large quantities of text. Especially suited | well to text that changes with most frames, because it doesn't incur the | (normally helpful) overhead of buffering.
createExtrudeFont :: String -> IO FontSource
Create a 3D extruded font. This is the only way of creating 3D fonts | within FTGL. Could be fun to use a geometry shader to get different | effects by warping the otherwise square nature of the font. Polygonal. | Scales without losing quality. Slower than all other fonts.
getLayoutFont :: Layout -> FontSource
getLayoutAlignment :: Layout -> TextAlignmentSource
Get the alignment of text in this layout.
getLayoutLineLength :: Layout -> FloatSource
Get the embedded font from the Layout
Get the line length in points (1:72in) of lines in the layout
destroyFont :: Font -> IO ()Source
getFontFaceSize :: Font -> IntSource
Get the different character mappings available in this font.
Get the current font face size in points.
getFontBBox :: Font -> String -> [Float]Source
Get the text extents of a string as a list of (lower-left,lower-right,upper-left,upper-right)
getFontAdvance :: Font -> String -> FloatSource
Get the horizontal span of a string of text using the current font. Input as the xcoord | in any translate operation
renderFont :: Font -> String -> RenderMode -> IO ()Source
Render a string of text in the current font.
getFontError :: Font -> IntSource
Get any errors associated with loading a font. FIXME return should be a type, not an Int.
destroyLayout :: Layout -> IO ()Source
renderLayout :: Layout -> String -> IO ()Source
getLayoutError :: Layout -> CIntSource
data RenderMode Source
Whether or not in polygonal or extrusion mode, the font will render equally front and back
data TextAlignment Source
In a Layout directed render, the layout mode of the text
Constructors
| AlignLeft | |
| AlignCenter | |
| AlignRight | |
| Justify |