1
/****************************************************************************
3
GLUI User Interface Toolkit
4
---------------------------
8
Draws the hardcoded images listed in glui_bitmap_img_data with OpenGL.
10
FIXME: upload the images to a texture. This will allow them to be:
11
- Drawn with alpha blending
12
- Drawn at random sizes and angles onscreen
13
- Drawn much faster than with glDrawPixels
15
--------------------------------------------------
17
Copyright (c) 1998 Paul Rademacher
19
WWW: http://sourceforge.net/projects/glui/
20
Forums: http://sourceforge.net/forum/?group_id=92496
22
This library is free software; you can redistribute it and/or
23
modify it under the terms of the GNU Lesser General Public
24
License as published by the Free Software Foundation; either
25
version 2.1 of the License, or (at your option) any later version.
27
This library is distributed in the hope that it will be useful,
28
but WITHOUT ANY WARRANTY; without even the implied warranty of
29
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30
Lesser General Public License for more details.
32
You should have received a copy of the GNU Lesser General Public
33
License along with this library; if not, write to the Free Software
34
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36
*****************************************************************************/
39
#include "glui_internal.h"
42
/************ Image Bitmap arrays **********/
44
extern unsigned char glui_img_checkbox_0[];
45
extern unsigned char glui_img_checkbox_1[];
46
extern unsigned char glui_img_radiobutton_0[];
47
extern unsigned char glui_img_radiobutton_1[];
48
extern unsigned char glui_img_uparrow[];
49
extern unsigned char glui_img_downarrow[];
50
extern unsigned char glui_img_leftarrow[];
51
extern unsigned char glui_img_rightarrow[];
52
extern unsigned char glui_img_spinup_0[];
53
extern unsigned char glui_img_spinup_1[];
54
extern unsigned char glui_img_spindown_0[];
55
extern unsigned char glui_img_spindown_1[];
56
extern unsigned char glui_img_checkbox_0_dis[];
57
extern unsigned char glui_img_checkbox_1_dis[];
58
extern unsigned char glui_img_radiobutton_0_dis[];
59
extern unsigned char glui_img_radiobutton_1_dis[];
60
extern unsigned char glui_img_spinup_dis[];
61
extern unsigned char glui_img_spindown_dis[];
62
extern unsigned char glui_img_listbox_up[];
63
extern unsigned char glui_img_listbox_down[];
64
extern unsigned char glui_img_listbox_up_dis[];
67
// These must be in the same order as the GLUI_STDBITMAP enums from glui.h!
68
unsigned char *bitmap_arrays[] = {
71
glui_img_radiobutton_0,
72
glui_img_radiobutton_1,
81
glui_img_checkbox_0_dis,
82
glui_img_checkbox_1_dis,
83
glui_img_radiobutton_0_dis,
84
glui_img_radiobutton_1_dis,
86
glui_img_spindown_dis,
88
glui_img_listbox_down,
89
glui_img_listbox_up_dis,
93
/************************************ GLUI_Bitmap::load_from_array() ********/
95
GLUI_Bitmap::GLUI_Bitmap()
102
GLUI_Bitmap::~GLUI_Bitmap()
111
/* Create bitmap from greyscale byte array */
112
void GLUI_Bitmap::init_grey(unsigned char *array)
114
w = array[0]; h = array[1];
115
pixels = (unsigned char *) malloc(w*h*3);
118
for(int i = 0; i<w*h; i++ )
119
for (int j = 0; j<3; j++) /* copy grey to r,g,b channels */
120
pixels[i*3+j] = (unsigned char) array[i+2];
124
/* Create bitmap from color int array.
125
(OSL) This used to be how all GLUI bitmaps were stored, which was horribly
126
inefficient--three ints per pixel, or 12 bytes per pixel!
128
void GLUI_Bitmap::init(int *array)
130
w = array[0]; h = array[1];
131
pixels = (unsigned char *) malloc(w*h*3);
134
for (int i = 0; i<w*h*3; i++)
135
pixels[i] = (unsigned char) array[i+2];
139
/*********************************** GLUI_StdBitmaps::draw() *****************/
141
GLUI_StdBitmaps::GLUI_StdBitmaps()
143
for (int i=0; i<GLUI_STDBITMAP_NUM_ITEMS; i++)
144
bitmaps[i].init_grey(bitmap_arrays[i]);
147
GLUI_StdBitmaps::~GLUI_StdBitmaps()
151
int GLUI_StdBitmaps::width(int i) const
153
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
157
int GLUI_StdBitmaps::height(int i) const
159
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
163
void GLUI_StdBitmaps::draw(int i, int x, int y) const
165
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
167
if (bitmaps[i].pixels != NULL )
169
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
170
glRasterPos2f(0.5f+x, 0.5f+y+bitmaps[i].h);
172
bitmaps[i].w, bitmaps[i].h,
173
GL_RGB, GL_UNSIGNED_BYTE, bitmaps[i].pixels);