[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 for AIX: Graphics Library (GL) Technical Reference

xfonts.c Example C Language Program

/*
xfonts.c
This program demonstrates how to use Enhanced X-Windows
fonts in a
GL application
*/
#include <gl/gl.h>
#include <X11/Xlib.h>
#include <stdio.h>
main()
{
  Int32 wid;                   /* the GL window ID */
  Display *dpy;                /* structure describing X session*/
  int num_fonts;               /* number of fonts X server found */
  char **fontlist;             /* array of strings
                                  (available font names) */
  prefsize (150,150);
  wid = winopen ("xfonts");
  color (BLACK);
  clear();
  /* get the connection to X */
  /* Normally, the default display is unix:0 */
  dpy = XOpenDisplay ("unix:0");
   /* Get the names of all fonts that might be Helvetica fonts */
   /* (have "helv" appearing in their font name) */
  fontlist = XListFonts (dpy, "*helv*", 1000, &num_fonts);
   /* other useful X font subroutines are:
    * XListFonts
    * XListFontsWithInfo
    * XFreeFontNames
    * XFreeFontInfo
    * XSetFontPath
    * XGetFontPath
    * XFreeFontPath
    */
  /* We have decided, by some criteria, to use the fifth
   * available Helvetica font (assuming that at least five
   * Helvetica fonts are found). We will give it an id of 433.
   */
  if ( num_fonts < 4 ) {
    fprintf (stderr,"Not enough fonts found!!!\n");
    exit (-1);
  }
  loadXfont (433, fontlist[4]);
   /* get rid of the font name list */
  XFreeFontNames (fontlist);
   /* we want to use this font to draw a string */
  font (433);   /* do it */
  cmov2 (43.0, 56.0);
  color (RED);
  charstr ("Hello, World");   
  sleep (5);
}
/*
  Changes: 
     -  from wid = winopen "xfonts"); to wid = winopen ("xfonts");
*/

Related Information

The loadXfont subroutine loads an Enhanced X-Windows font into the font table.

Fonts in GL3.2 Version 4 for AIX: Programming Concepts describes font assignment in GL, and discusses relevant subroutines.


[ Previous | Next | Contents | Glossary | Home | Search ]