1 
2 /* Copyright (c) Mark J. Kilgard, 1994. */
3 
4 /* This program is freely distributable without licensing fees
5    and is provided without guarantee or warrantee expressed or
6    implied. This program is -not- in the public domain. */
7 
8 #include <GL/glut_cgx.h>
9 #include "glutint.h"
10 #include "glutbitmap.h"
11 
12 void APIENTRY
glutBitmapCharacter(GLUTbitmapFont font,int c)13 glutBitmapCharacter(GLUTbitmapFont font, int c)
14 {
15   const BitmapCharRec *ch;
16   BitmapFontPtr fontinfo;
17   GLint swapbytes, lsbfirst, rowlength;
18   GLint skiprows, skippixels, alignment;
19 
20 #if defined(WIN32)
21   fontinfo = (BitmapFontPtr) __glutFont(font);
22 #else
23   fontinfo = (BitmapFontPtr) font;
24 #endif
25 
26   if (c < fontinfo->first ||
27     c >= fontinfo->first + fontinfo->num_chars)
28     return;
29   ch = fontinfo->ch[c - fontinfo->first];
30   if (ch) {
31     /* Save current modes. */
32     glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes);
33     glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst);
34     glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength);
35     glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows);
36     glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels);
37     glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
38     /* Little endian machines (DEC Alpha for example) could
39        benefit from setting GL_UNPACK_LSB_FIRST to GL_TRUE
40        instead of GL_FALSE, but this would require changing the
41        generated bitmaps too. */
42     glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
43     glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
44     glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
45     glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
46     glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
47     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
48     glBitmap(ch->width, ch->height, ch->xorig, ch->yorig,
49       ch->advance, 0, ch->bitmap);
50     /* Restore saved modes. */
51     glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
52     glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst);
53     glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
54     glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows);
55     glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
56     glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
57   }
58 }
59