xref: /haiku/src/libs/glut/glut_bitmap.c (revision 9642f7705b27e5c270c15fa526d14e1848c2c27d)
1 /*
2  * Copyright 1994-1997 Mark Kilgard, All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * GPL licensing not permitted.
6  *
7  * Authors:
8  *	Mark Kilgard
9  */
10 
11 
12 #include "glutint.h"
13 #include "glutbitmap.h"
14 
15 
16 void APIENTRY
17 glutBitmapCharacter(GLUTbitmapFont font, int c)
18 {
19   const BitmapCharRec *ch;
20   BitmapFontPtr fontinfo;
21   GLint swapbytes, lsbfirst, rowlength;
22   GLint skiprows, skippixels, alignment;
23 
24 #if defined(_WIN32)
25   fontinfo = (BitmapFontPtr) __glutFont(font);
26 #else
27   fontinfo = (BitmapFontPtr) font;
28 #endif
29 
30   if (c < fontinfo->first ||
31     c >= fontinfo->first + fontinfo->num_chars)
32     return;
33   ch = fontinfo->ch[c - fontinfo->first];
34   if (ch) {
35     /* Save current modes. */
36     glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes);
37     glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst);
38     glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength);
39     glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows);
40     glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels);
41     glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
42     /* Little endian machines (DEC Alpha for example) could
43        benefit from setting GL_UNPACK_LSB_FIRST to GL_TRUE
44        instead of GL_FALSE, but this would require changing the
45        generated bitmaps too. */
46     glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
47     glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
48     glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
49     glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
50     glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
51     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
52     glBitmap(ch->width, ch->height, ch->xorig, ch->yorig,
53       ch->advance, 0, ch->bitmap);
54     /* Restore saved modes. */
55     glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
56     glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst);
57     glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
58     glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows);
59     glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
60     glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
61   }
62 }
63