1 /* Copyright (c) Mark J. Kilgard, 1994, 1998.
3 This program is freely distributable without licensing fees
4 and is provided without guarantee or warrantee expressed or
5 implied. This program is -not- in the public domain. */
11 #if defined(_WIN32) || defined (GLUT_IMPORT_LIB)
14 __glutFont( void *font
)
17 case (long)GLUT_STROKE_ROMAN
:
18 return &glutStrokeRoman
;
19 case (long)GLUT_STROKE_MONO_ROMAN
:
20 return &glutStrokeMonoRoman
;
21 case (long)GLUT_BITMAP_9_BY_15
:
22 return &glutBitmap9By15
;
23 case (long)GLUT_BITMAP_8_BY_13
:
24 return &glutBitmap8By13
;
25 case (long)GLUT_BITMAP_TIMES_ROMAN_10
:
26 return &glutBitmapTimesRoman10
;
27 case (long)GLUT_BITMAP_TIMES_ROMAN_24
:
28 return &glutBitmapTimesRoman24
;
29 case (long)GLUT_BITMAP_HELVETICA_10
:
30 return &glutBitmapHelvetica10
;
31 case (long)GLUT_BITMAP_HELVETICA_12
:
32 return &glutBitmapHelvetica12
;
33 case (long)GLUT_BITMAP_HELVETICA_18
:
34 return &glutBitmapHelvetica18
;
43 __glutFont( void *font
)
52 glutBitmapCharacter( GLUTbitmapFont font
, int c
)
54 const BitmapCharRec
*ch
;
55 BitmapFontPtr fontinfo
;
56 GLint swapbytes
, lsbfirst
, rowlength
;
57 GLint skiprows
, skippixels
, alignment
;
59 fontinfo
= (BitmapFontPtr
) __glutFont( font
);
61 if (!fontinfo
|| c
< fontinfo
->first
||
62 c
>= fontinfo
->first
+ fontinfo
->num_chars
)
65 ch
= fontinfo
->ch
[c
- fontinfo
->first
];
67 /* Save current modes. */
68 glGetIntegerv(GL_UNPACK_SWAP_BYTES
, &swapbytes
);
69 glGetIntegerv(GL_UNPACK_LSB_FIRST
, &lsbfirst
);
70 glGetIntegerv(GL_UNPACK_ROW_LENGTH
, &rowlength
);
71 glGetIntegerv(GL_UNPACK_SKIP_ROWS
, &skiprows
);
72 glGetIntegerv(GL_UNPACK_SKIP_PIXELS
, &skippixels
);
73 glGetIntegerv(GL_UNPACK_ALIGNMENT
, &alignment
);
74 /* Little endian machines (DEC Alpha for example) could
75 benefit from setting GL_UNPACK_LSB_FIRST to GL_TRUE
76 instead of GL_FALSE, but this would require changing the
77 generated bitmaps too. */
78 glPixelStorei(GL_UNPACK_SWAP_BYTES
, GL_FALSE
);
79 glPixelStorei(GL_UNPACK_LSB_FIRST
, GL_FALSE
);
80 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
81 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
82 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
83 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
84 glBitmap(ch
->width
, ch
->height
, ch
->xorig
, ch
->yorig
,
85 ch
->advance
, 0, ch
->bitmap
);
86 /* Restore saved modes. */
87 glPixelStorei(GL_UNPACK_SWAP_BYTES
, swapbytes
);
88 glPixelStorei(GL_UNPACK_LSB_FIRST
, lsbfirst
);
89 glPixelStorei(GL_UNPACK_ROW_LENGTH
, rowlength
);
90 glPixelStorei(GL_UNPACK_SKIP_ROWS
, skiprows
);
91 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, skippixels
);
92 glPixelStorei(GL_UNPACK_ALIGNMENT
, alignment
);
98 glutBitmapWidth( GLUTbitmapFont font
, int c
)
100 BitmapFontPtr fontinfo
;
101 const BitmapCharRec
*ch
;
103 fontinfo
= (BitmapFontPtr
) __glutFont( font
);
105 if (!fontinfo
|| c
< fontinfo
->first
||
106 c
>= fontinfo
->first
+ fontinfo
->num_chars
)
109 ch
= fontinfo
->ch
[c
- fontinfo
->first
];
118 glutBitmapLength( GLUTbitmapFont font
, const unsigned char *string
)
121 BitmapFontPtr fontinfo
;
122 const BitmapCharRec
*ch
;
124 fontinfo
= (BitmapFontPtr
) __glutFont( font
);
128 for (length
= 0; *string
!= '\0'; string
++) {
130 if (c
>= fontinfo
->first
&&
131 c
< fontinfo
->first
+ fontinfo
->num_chars
) {
132 ch
= fontinfo
->ch
[c
- fontinfo
->first
];
134 length
+= ch
->advance
;
143 glutStrokeCharacter( GLUTstrokeFont font
, int c
)
145 const StrokeCharRec
*ch
;
146 const StrokeRec
*stroke
;
147 const CoordRec
*coord
;
148 StrokeFontPtr fontinfo
;
151 fontinfo
= (StrokeFontPtr
) __glutFont( font
);
153 if (!fontinfo
|| c
< 0 || c
>= fontinfo
->num_chars
)
156 ch
= &(fontinfo
->ch
[c
]);
158 for (i
= ch
->num_strokes
, stroke
= ch
->stroke
;
159 i
> 0; i
--, stroke
++) {
160 glBegin(GL_LINE_STRIP
);
161 for (j
= stroke
->num_coords
, coord
= stroke
->coord
;
162 j
> 0; j
--, coord
++) {
163 glVertex2f(coord
->x
, coord
->y
);
167 glTranslatef(ch
->right
, 0.0, 0.0);
173 glutStrokeWidth( GLUTstrokeFont font
, int c
)
175 StrokeFontPtr fontinfo
;
176 const StrokeCharRec
*ch
;
178 fontinfo
= (StrokeFontPtr
) __glutFont( font
);
180 if (!fontinfo
|| c
< 0 || c
>= fontinfo
->num_chars
)
183 ch
= &(fontinfo
->ch
[c
]);
192 glutStrokeLength( GLUTstrokeFont font
, const unsigned char *string
)
195 StrokeFontPtr fontinfo
;
196 const StrokeCharRec
*ch
;
198 fontinfo
= (StrokeFontPtr
) __glutFont( font
);
202 for (length
= 0; *string
!= '\0'; string
++) {
204 if (c
>= 0 && c
< fontinfo
->num_chars
) {
205 ch
= &(fontinfo
->ch
[c
]);