-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.c
executable file
·155 lines (119 loc) · 3.59 KB
/
font.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Hostile Takeover:
* CS248 Final Project, Fall 2004
*
* Written by Jonathan Reeves
*
* A simple 3D video game demonstrating the use of OpenGL for graphics
* rendering with a number of advanced techniques and optimizations to make
* it interesting. See the README file which came with this package for more
* details. It also includes a list of sources which were consulted while
* building this software package.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "font.h"
GLuint base0; /* Base Display List For first Font Set */
GLuint base1; /* Base Display List For second Font Set */
/* function to recover memory form our list of characters */
GLvoid FontDestroyAll(GLvoid){
glDeleteLists(base0, 96);
glDeleteLists(base1, 96);
return;
}
GLvoid FontDestroySmall(GLvoid){
glDeleteLists(base0, 96);
return;
}
GLvoid FontDestroyLarge(GLvoid){
glDeleteLists(base1, 96);
return;
}
GLvoid FontBuildAll(GLvoid){
FontBuildSmall();
FontBuildLarge();
}
/* function to build our font list */
GLvoid FontBuildSmall(GLvoid){
Display *dpy; /* Our current X display */
XFontStruct *fontInfo; /* Our font info */
/* Storage for 96 characters */
base0 = 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" );
}
}
/* generate the list */
glXUseXFont(fontInfo->fid, 32, 96, base0);
/* Recover some memory */
XFreeFont( dpy, fontInfo );
/* close the display now that we're done with it */
XCloseDisplay( dpy );
return;
}
/* function to build our font list */
GLvoid FontBuildLarge(GLvoid){
Display *dpy; /* Our current X display */
XFontStruct *fontInfo; /* Our font info */
/* Storage for 96 characters */
base1 = glGenLists(96);
/* Get our current display long enough to get the fonts */
dpy = XOpenDisplay(NULL);
/* Get the font information */
fontInfo = XLoadQueryFont( dpy,
"-adobe-helvetica-bold-r-normal--60-*-*-*-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" );
}
}
/* generate the list */
glXUseXFont(fontInfo->fid, 32, 96, base1);
/* 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 */
GLvoid glPrint(int fontNum, 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 */
if(fontNum == 0){
glListBase(base0 - 32);
}
else{
glListBase(base1 - 32);
}
/* Draws the text */
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
/* Pops the Display List Bits */
glPopAttrib();
}