Function:font2tex

From S2PLOT

Jump to: navigation, search

font2tex

Use a named freetype font to create a texture map.

Prototype

unsigned int font2tex(char *fontfilename, char *text, int fontsizepx, int border);

Description

Load a named freetype font, where fontfilename includes the full pathname to the font, to generate a texture map from the input text. Argument fontsizepx controls the font size, and an optional border can be drawn around the text using border > 0.

This function is only available if the S2FREETYPE environment variable has been set to 'yes'.

See Also

Code Example

#include <stdio.h>
#include <stdlib.h>
#include "s2plot.h"

unsigned int tid;

void cb(double *t, int *kc)
{
   XYZ xyz = {0.0, 0.3, 0.4};                           /* Location */
   float isize = 0.02;                                  /* Texture scale */
   XYZ str = { 0.0, 0.0, 0.0};                          /* No stretch */
   COLOUR col = { 1.0, 1.0, 0.0 };                      /* Yellow */
   float alpha = 0.9;                                   /* Alpha channel */
   char trans = 's';                                    /* Transparency */

   ds2vbb(xyz, str, isize, col, tid, alpha, trans);     /* Draw the billboard */
}

int main(int argc, char *argv[])
{
   s2opend("/?",argc,argv);                     /* Open the display */
   s2svp(-1.0,1.0, -1.0,1.0, -1.0,1.0);         /* Set the viewport coords */
   s2swin(-1.0,1.0, -1.0,1.0, -1.0,1.0);        /* Set the window coordinates */
   s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0);     /* Draw a bounding box */

   char font[64];                               /* Allocate font name string */

   sprintf(font,"/Library/Fonts/Arial Black");  /* Path to font */
                        /* NOTE: This depends on your local system config */

   tid = font2tex(font,"s2plot",32,4);          /* Create the texture */

   cs2scb(&cb);                                 /* Install a callback */

   s2show(1);                                   /* Open the s2plot window */

   return 1;
}

Back to S2PLOT function list.


Personal tools