1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/****************************************************************************
GLUI User Interface Toolkit
---------------------------
glui_bitmaps.cpp
Draws the hardcoded images listed in glui_bitmap_img_data with OpenGL.
FIXME: upload the images to a texture. This will allow them to be:
- Drawn with alpha blending
- Drawn at random sizes and angles onscreen
- Drawn much faster than with glDrawPixels
--------------------------------------------------
Copyright (c) 1998 Paul Rademacher
WWW: http://sourceforge.net/projects/glui/
Forums: http://sourceforge.net/forum/?group_id=92496
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
#include "glui.h"
#include "glui_internal.h"
#include <cassert>
/************ Image Bitmap arrays **********/
extern unsigned char glui_img_checkbox_0[];
extern unsigned char glui_img_checkbox_1[];
extern unsigned char glui_img_radiobutton_0[];
extern unsigned char glui_img_radiobutton_1[];
extern unsigned char glui_img_uparrow[];
extern unsigned char glui_img_downarrow[];
extern unsigned char glui_img_leftarrow[];
extern unsigned char glui_img_rightarrow[];
extern unsigned char glui_img_spinup_0[];
extern unsigned char glui_img_spinup_1[];
extern unsigned char glui_img_spindown_0[];
extern unsigned char glui_img_spindown_1[];
extern unsigned char glui_img_checkbox_0_dis[];
extern unsigned char glui_img_checkbox_1_dis[];
extern unsigned char glui_img_radiobutton_0_dis[];
extern unsigned char glui_img_radiobutton_1_dis[];
extern unsigned char glui_img_spinup_dis[];
extern unsigned char glui_img_spindown_dis[];
extern unsigned char glui_img_listbox_up[];
extern unsigned char glui_img_listbox_down[];
extern unsigned char glui_img_listbox_up_dis[];
// These must be in the same order as the GLUI_STDBITMAP enums from glui.h!
unsigned char *bitmap_arrays[] = {
glui_img_checkbox_0,
glui_img_checkbox_1,
glui_img_radiobutton_0,
glui_img_radiobutton_1,
glui_img_uparrow,
glui_img_downarrow,
glui_img_leftarrow,
glui_img_rightarrow,
glui_img_spinup_0,
glui_img_spinup_1,
glui_img_spindown_0,
glui_img_spindown_1,
glui_img_checkbox_0_dis,
glui_img_checkbox_1_dis,
glui_img_radiobutton_0_dis,
glui_img_radiobutton_1_dis,
glui_img_spinup_dis,
glui_img_spindown_dis,
glui_img_listbox_up,
glui_img_listbox_down,
glui_img_listbox_up_dis,
};
/************************************ GLUI_Bitmap::load_from_array() ********/
GLUI_Bitmap::GLUI_Bitmap()
: pixels(NULL),
w(0),
h(0)
{
}
GLUI_Bitmap::~GLUI_Bitmap()
{
if (pixels)
{
free(pixels);
pixels = NULL;
}
}
/* Create bitmap from greyscale byte array */
void GLUI_Bitmap::init_grey(unsigned char *array)
{
w = array[0]; h = array[1];
pixels = (unsigned char *) malloc(w*h*3);
assert(pixels);
for(int i = 0; i<w*h; i++ )
for (int j = 0; j<3; j++) /* copy grey to r,g,b channels */
pixels[i*3+j] = (unsigned char) array[i+2];
}
/* Create bitmap from color int array.
(OSL) This used to be how all GLUI bitmaps were stored, which was horribly
inefficient--three ints per pixel, or 12 bytes per pixel!
*/
void GLUI_Bitmap::init(int *array)
{
w = array[0]; h = array[1];
pixels = (unsigned char *) malloc(w*h*3);
assert(pixels);
for (int i = 0; i<w*h*3; i++)
pixels[i] = (unsigned char) array[i+2];
}
/*********************************** GLUI_StdBitmaps::draw() *****************/
GLUI_StdBitmaps::GLUI_StdBitmaps()
{
for (int i=0; i<GLUI_STDBITMAP_NUM_ITEMS; i++)
bitmaps[i].init_grey(bitmap_arrays[i]);
}
GLUI_StdBitmaps::~GLUI_StdBitmaps()
{
}
int GLUI_StdBitmaps::width(int i) const
{
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
return bitmaps[i].w;
}
int GLUI_StdBitmaps::height(int i) const
{
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
return bitmaps[i].h;
}
void GLUI_StdBitmaps::draw(int i, int x, int y) const
{
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
if (bitmaps[i].pixels != NULL )
{
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glRasterPos2f(0.5f+x, 0.5f+y+bitmaps[i].h);
glDrawPixels(
bitmaps[i].w, bitmaps[i].h,
GL_RGB, GL_UNSIGNED_BYTE, bitmaps[i].pixels);
}
}
|