Cairo-Dock  3.4.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cairo-dock-opengl-font.h File Reference

Data Structures

struct  _CairoDockGLFont
 Structure used to load a font for OpenGL text rendering. More...
 

Functions

GLuint cairo_dock_create_texture_from_text_simple (const gchar *cText, const gchar *cFontDescription, cairo_t *pSourceContext, int *iWidth, int *iHeight)
 
CairoDockGLFontcairo_dock_load_textured_font (const gchar *cFontDescription, int first, int count)
 
CairoDockGLFontcairo_dock_load_textured_font_from_image (const gchar *cImagePath)
 
void cairo_dock_free_gl_font (CairoDockGLFont *pFont)
 
void cairo_dock_get_gl_text_extent (const gchar *cText, CairoDockGLFont *pFont, int *iWidth, int *iHeight)
 
void cairo_dock_draw_gl_text (const guchar *cText, CairoDockGLFont *pFont)
 
void cairo_dock_draw_gl_text_at_position (const guchar *cText, CairoDockGLFont *pFont, int x, int y)
 
void cairo_dock_draw_gl_text_in_area (const guchar *cText, CairoDockGLFont *pFont, int iWidth, int iHeight, gboolean bCentered)
 
void cairo_dock_draw_gl_text_at_position_in_area (const guchar *cText, CairoDockGLFont *pFont, int x, int y, int iWidth, int iHeight, gboolean bCentered)
 

Detailed Description

This class provides different ways to draw text directly in OpenGL. cairo_dock_create_texture_from_text_simple lets you draw any text in any font, by creating a texture from a Pango font description. This is a convenient function but not very fast. For a more efficient way, you load a font into a CairoDockGLFont with either : cairo_dock_load_textured_font to load a subset of a Mono font into textures. You then use cairo_dock_draw_gl_text_at_position to draw the text.

Function Documentation

GLuint cairo_dock_create_texture_from_text_simple ( const gchar *  cText,
const gchar *  cFontDescription,
cairo_t *  pSourceContext,
int *  iWidth,
int *  iHeight 
)

Create a texture from a text. The text is drawn in white, so that you can later colorize it with a mere glColor.

Parameters
cTextthe text
cFontDescriptiona description of the font, for instance "Monospace Bold 12"
pSourceContexta cairo context, not altered by the function.
iWidtha pointer that will be filled with the width of the texture.
iHeighta pointer that will be filled with the height of the texture.
Returns
a newly allocated texture.
CairoDockGLFont* cairo_dock_load_textured_font ( const gchar *  cFontDescription,
int  first,
int  count 
)

Load a font into textures. You can then render your text like a normal texture (zoom, etc). The drawback is that only a mono font can be used with this function.

Parameters
cFontDescriptiona description of the font, for instance "Monospace Bold 12"
firstfirst character to load.
countnumber of characters to load.
Returns
a newly allocated opengl font.
CairoDockGLFont* cairo_dock_load_textured_font_from_image ( const gchar *  cImagePath)

Like the previous function, but loads the characters from an image. The image must be squared and contain the 256 extended ASCII characters in the alphabetic order.

Parameters
cImagePathpath to the image.
Returns
a newly allocated opengl font.
void cairo_dock_free_gl_font ( CairoDockGLFont pFont)

Free an opengl font.

Parameters
pFontthe font.
void cairo_dock_get_gl_text_extent ( const gchar *  cText,
CairoDockGLFont pFont,
int *  iWidth,
int *  iHeight 
)

Compute the size a text will take for a given font.

Parameters
cTextthe text
pFontthe font.
iWidtha pointer that will be filled with the width of the text.
iHeighta pointer that will be filled with the height of the text.
void cairo_dock_draw_gl_text ( const guchar *  cText,
CairoDockGLFont pFont 
)

Render a text for a given font. In the case of a bitmap font, the current raster position is used. In the case of a texture font, the current model view is used.

Parameters
cTextthe text
pFontthe font.
void cairo_dock_draw_gl_text_at_position ( const guchar *  cText,
CairoDockGLFont pFont,
int  x,
int  y 
)

Like /ref cairo_dock_draw_gl_text but at a given position.

Parameters
cTextthe text
pFontthe font.
xx position of the left bottom corner of the text.
yy position of the left bottom corner of the text.
void cairo_dock_draw_gl_text_in_area ( const guchar *  cText,
CairoDockGLFont pFont,
int  iWidth,
int  iHeight,
gboolean  bCentered 
)

Like /ref cairo_dock_draw_gl_text but resize the text so that it fits into a given area. Only works for a texture font.

Parameters
cTextthe text
pFontthe font.
iWidthiWidth of the area.
iHeightiHeight of the area
bCenteredwhether the text is centered on the current position or not.
void cairo_dock_draw_gl_text_at_position_in_area ( const guchar *  cText,
CairoDockGLFont pFont,
int  x,
int  y,
int  iWidth,
int  iHeight,
gboolean  bCentered 
)

Like /ref cairo_dock_draw_gl_text_in_area and /ref cairo_dock_draw_gl_text_at_position.

Parameters
cTextthe text
pFontthe font.
xx position of the left bottom corner of the text.
yy position of the left bottom corner of the text.
iWidthiWidth of the area.
iHeightiHeight of the area
bCenteredwhether the text is centered on the given position or not.