Merge branch 'master' into drm-gem
[mesa.git] / src / glut / fbdev / bitmap.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 * Copyright (C) 1995-2006 Brian Paul
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 /*
22 * Library for glut using mesa fbdev driver
23 *
24 * Written by Sean D'Epagnier (c) 2006
25 *
26 * To improve on this library, maybe support subwindows or overlays,
27 * I (sean at depagnier dot com) will do my best to help.
28 */
29
30
31 #include "glutbitmap.h"
32
33 void glutBitmapCharacter(GLUTbitmapFont font, int c)
34 {
35 const BitmapCharRec *ch;
36 BitmapFontPtr fi = (BitmapFontPtr) font;
37
38 if (c < fi->first ||
39 c >= fi->first + fi->num_chars)
40 return;
41 ch = fi->ch[c - fi->first];
42 if (!ch)
43 return;
44
45 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
46
47 glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
48 glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
49 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
50 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
51 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
52 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
53 glBitmap(ch->width, ch->height, ch->xorig, ch->yorig,
54 ch->advance, 0, ch->bitmap);
55 glPopClientAttrib();
56 }
57
58 int glutBitmapWidth (GLUTbitmapFont font, int c)
59 {
60 const BitmapCharRec *ch;
61 BitmapFontPtr fi = (BitmapFontPtr) font;
62
63 if (c < fi->first || c >= fi->first + fi->num_chars)
64 return 0;
65 ch = fi->ch[c - fi->first];
66 if (ch)
67 return ch->advance;
68 return 0;
69 }
70
71 int glutBitmapLength(GLUTbitmapFont font, const unsigned char *string)
72 {
73 int length = 0;
74
75 for (; *string; string++)
76 length += glutBitmapWidth(font, *string);
77 return length;
78 }