Function:font2tex

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 22:06, 16 December 2007
S2plot admin (Talk | contribs)

← Previous diff
Current revision
S2plot admin (Talk | contribs)

Line 1: Line 1:
==font2tex== ==font2tex==
-Use a named freetype2 font to create a texture map.+Use a named freetype font to create a texture map.
==Prototype== ==Prototype==
Line 9: Line 9:
==Description== ==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 [[+This function is only available if the [[S2PLOT:Environment_Variables | S2FREETYPE]] environment variable has been set to 'yes'.
== See Also == == See Also ==
Line 22: Line 23:
#include "s2plot.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[]) int main(int argc, char *argv[])
{ {
- fprintf(stderr,"Press <shift>-<w> to write VRML\n");+ s2opend("/?",argc,argv); /* Open the display */
- fprintf(stderr,"Creates VRML file: test.wrl\n");+ 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 */
- s2opend("/s2mono", argc, argv); /* Open in mono mode */+ char font[64]; /* Allocate font name string */
- s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */+
- pushVRMLname("BOX"); /* Create a new VRML object name */+ sprintf(font,"/Library/Fonts/Arial Black"); /* Path to font */
- s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0);+ /* NOTE: This depends on your local system config */
- /* This will not appear in the VRML */+
- int i, N = 100; /* Loop variables */+ tid = font2tex(font,"s2plot",32,4); /* Create the texture */
- XYZ xyz; /* Point location */+
- COLOUR col; /* Point colour */+
- pushVRMLname("POINTS"); /* Create a new VRML object name */+ cs2scb(&cb); /* Install a callback */
- for (i=0;i<N;i++) {+
- xyz.x = drand48()*2.0 - 1.0; /* Random positions */+
- xyz.y = drand48()*2.0 - 1.0;+
- xyz.z = drand48()*2.0 - 1.0;+
- col.r = drand48()*2.0 - 1.0; /* Random colours */+
- col.g = drand48()*2.0 - 1.0;+
- col.b = drand48()*2.0 - 1.0;+
- ns2vthpoint(xyz, col, 2); /* Draw current point */+
- }+
- pushVRMLname("ANON"); /* Restore default VRML object name */+
- s2show(1); /* Open the s2plot window */+ s2show(1); /* Open the s2plot window */
return 1; return 1;

Current revision

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