27#elif defined(__FreeBSD__)
28#include <machine/endian.h>
30#define BIG_ENDIAN 1234
31#define LITTLE_ENDIAN 4321
32#define BYTE_ORDER LITTLE_ENDIAN
38#include <portability.h>
44const char *
keySize[4] = {
"size big",
"size large",
"size medium",
"size small" };
48#if BYTE_ORDER == BIG_ENDIAN
49void swap32(
unsigned int *
p,
unsigned int size)
52 for (i = 0; i < size; i += 4) {
53 t = (
unsigned int) *
p;
54 *
p = (t & 0xff000000U) >> 24;
55 *
p |= (t & 0x00ff0000U) >> 8;
56 *
p |= (t & 0x0000ff00U) << 8;
57 *
p |= (t & 0x000000ffU) << 24;
70 const int BUFSIZE = 1024;
77 snprintf(buf, BUFSIZE,
"data/fonts/%s", fontName);
79 for(i = 0; i < 4; i++) {
86 snprintf(buf, BUFSIZE,
"data/fonts/%s", fontName);
88 for(i = 0; i < 4; i++) {
95 snprintf(buf, BUFSIZE,
"data/fonts/%s", fontName);
115 if ((Input = fopen(FileName,
"rb")) == NULL) {
125 fread(
font, 24, 1, Input);
128#if BYTE_ORDER == BIG_ENDIAN
134 Num =
font->IntEnd -
font->IntStart + 1;
148#if BYTE_ORDER == BIG_ENDIAN
154 Num =
font->TexWidth *
font->TexHeight * 2;
157 if ((TexBytes = (
char *)malloc(Num)) == NULL) {
162 GfOut(
"font: %s, %d, %d, %d, %d, %d\n",
172 fread(TexBytes,
sizeof(
char), Num, Input);
177 glGenTextures(1, &Tex);
181 glBindTexture(GL_TEXTURE_2D, Tex);
182 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
183 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
184 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
186 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
187 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
190 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA,
font->TexWidth,
191 font->TexHeight, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, TexBytes);
204 glDeleteTextures(1, &
font->Tex);
213 if (
font->TexWidth > 256) {
215 size = point_size/58.0*1024.0f/
font->TexWidth;
233 Length = strlen(text);
236 for (i = 0; i < Length; i++) {
239 if ((
int)text[i] <
font->IntStart || (
int)text[i] >
font->IntEnd)
242 if (text[i] ==
' ' &&
font->TexWidth > 256) {
244 Char = &
font->Char[
'!' -
font->IntStart];
247 Char = &
font->Char[(int)text[i] -
font->IntStart];
250 if (
font->TexWidth > 256) {
263 if (
font == NULL)
return 0;
264 if (
font->TexWidth > 256) {
265 return (
const int)(
font->Char[0].dy*
font->TexHeight *
size);
267 return (
const int)(
font->Char[0].dy *
size);
274 if (
font == NULL)
return 0;
289 if (
font == NULL)
return;
292 Length = strlen(text);
295 glBindTexture(GL_TEXTURE_2D,
font->Tex);
299 for (i = 0; i < Length; i++)
302 if ((
int)text[i] <
font->IntStart || (
int)text[i] >
font->IntEnd)
305 if (text[i] ==
' ' &&
font->TexWidth > 256) {
307 Char = &
font->Char[
'!' -
font->IntStart];
311 Char = &
font->Char[(int)text[i] -
font->IntStart];
314 if (
font->TexWidth > 256) {
323 glTexCoord2f(Char->
tx1, Char->
ty1);
324 glVertex2f(x,
y + height);
325 glTexCoord2f(Char->
tx1, Char->
ty2);
327 glTexCoord2f(Char->
tx2, Char->
ty2);
328 glVertex2f(x + width,
y);
329 glTexCoord2f(Char->
tx2, Char->
ty1);
330 glVertex2f(x + width,
y + height);
void output(int x, int y, const char *text)
int getWidth(const char *text)
GfuiFontClass(char *font)
void create(int point_size)
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
void swap32(unsigned int *p, unsigned int size)
GfuiFontClass * gfuiFont[FONT_NB]
Parameter header structure, a parameter can either carry a numeric or a string value,...
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
#define GFPARM_RMODE_STD
Return a new handle sharing cached data for this filename, if available.
The Gaming Framework API (client part).