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