This repository has been archived by the owner on Jul 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfont.cpp
82 lines (61 loc) · 2.08 KB
/
font.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Fairly basic functions from a tutorial:
// http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13
// If these pose a copyright problem, they should be easy to rewrite
#include "main.h"
#include <stdarg.h>
#include <string.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
GLuint base; /* Base Display List For The Font Set */
/* function to build our font list */
void buildFont( ) {
Display *dpy; /* Our current X display */
XFontStruct *fontInfo; /* Our font info */
/* Sotrage for 96 characters */
base = glGenLists( 96 );
/* Get our current display long enough to get the fonts */
dpy = XOpenDisplay( NULL );
/* Get the font information */
fontInfo = XLoadQueryFont( dpy, "-adobe-helvetica-medium-r-normal--18-*-*-*-p-*-iso8859-1" );
/* If the above font didn't exist try one that should */
if ( fontInfo == NULL )
{
fontInfo = XLoadQueryFont( dpy, "fixed" );
/* If that font doesn't exist, something is wrong */
if ( fontInfo == NULL )
{
fprintf( stderr, "no X font available?\n" );
exit(2);
}
}
/* generate the list */
glXUseXFont( fontInfo->fid, 32, 96, base );
/* Recover some memory */
XFreeFont( dpy, fontInfo );
/* close the display now that we're done with it */
XCloseDisplay( dpy );
return;
}
/* Print our GL text to the screen */
void glPrint( const char *fmt, ... ) {
char text[256]; /* Holds our string */
va_list ap; /* Pointer to our list of elements */
/* If there's no text, do nothing */
if ( fmt == NULL )
return;
/* Parses The String For Variables */
va_start( ap, fmt );
/* Converts Symbols To Actual Numbers */
vsprintf( text, fmt, ap );
va_end( ap );
/* Pushes the Display List Bits */
glPushAttrib( GL_LIST_BIT );
/* Sets base character to 32 */
glListBase( base - 32 );
/* Draws the text */
glCallLists( strlen( text ), GL_UNSIGNED_BYTE, text );
// printf("Test: %s\n", text);
/* Pops the Display List Bits */
glPopAttrib( );
}