2 // "$Id: glut.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $"
4 // GLUT emulation header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2002 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems to "fltk-bugs@fltk.org".
26 // Emulation of Glut using fltk.
28 // GLUT is Copyright (c) Mark J. Kilgard, 1994, 1995, 1996:
29 // "This program is freely distributable without licensing fees and is
30 // provided without guarantee or warrantee expressed or implied. This
31 // program is -not- in the public domain."
33 // Although I have copied the GLUT API, none of my code is based on
34 // any Glut implementation details and is therefore covered by the LGPL.
36 // Fltk does not include the Glut drawing functions (such as
37 // glutWireTeapot()) or the stroke fonts but the declarations for the
38 // drawing functions are included here because otherwise there is no
39 // way to get them along with this. To use them you will have to
40 // link in the original Glut library, put -lglut *after* -lfltk.
42 // Commented out lines indicate parts of Glut that are not emulated.
50 ////////////////////////////////////////////////////////////////
51 // Glut is emulated using this window class and these static variables
52 // (plus several more static variables hidden in glut.C):
55 #include "Fl_Gl_Window.H"
57 class FL_EXPORT Fl_Glut_Window : public Fl_Gl_Window {
64 public: // so the inline functions work
69 void (*overlaydisplay)();
70 void (*reshape)(int w, int h);
71 void (*keyboard)(uchar, int x, int y);
72 void (*mouse)(int b, int state, int x, int y);
73 void (*motion)(int x, int y);
74 void (*passivemotion)(int x, int y);
76 void (*visibility)(int);
77 void (*special)(int, int x, int y);
78 Fl_Glut_Window(int w, int h, const char *);
79 Fl_Glut_Window(int x, int y, int w, int h, const char *);
83 extern FL_EXPORT Fl_Glut_Window *glut_window; // the current window
84 extern FL_EXPORT int glut_menu; // the current menu
86 // function pointers that are not per-window:
87 extern FL_EXPORT void (*glut_idle_function)();
88 extern FL_EXPORT void (*glut_menustate_function)(int);
89 extern FL_EXPORT void (*glut_menustatus_function)(int,int,int);
91 ////////////////////////////////////////////////////////////////
93 //#define GLUT_API_VERSION This does not match any version of Glut exactly...
95 FL_EXPORT void glutInit(int *argcp, char **argv); // creates first window
97 FL_EXPORT void glutInitDisplayMode(unsigned int mode);
98 // the FL_ symbols have the same value as the GLUT ones:
99 #define GLUT_RGB FL_RGB
100 #define GLUT_RGBA FL_RGB
101 #define GLUT_INDEX FL_INDEX
102 #define GLUT_SINGLE FL_SINGLE
103 #define GLUT_DOUBLE FL_DOUBLE
104 #define GLUT_ACCUM FL_ACCUM
105 #define GLUT_ALPHA FL_ALPHA
106 #define GLUT_DEPTH FL_DEPTH
107 #define GLUT_STENCIL FL_STENCIL
108 #define GLUT_MULTISAMPLE FL_MULTISAMPLE
109 #define GLUT_STEREO FL_STEREO
110 // #define GLUT_LUMINANCE 512
112 FL_EXPORT void glutInitWindowPosition(int x, int y);
114 FL_EXPORT void glutInitWindowSize(int w, int h);
116 FL_EXPORT void glutMainLoop();
118 FL_EXPORT int glutCreateWindow(char *title);
120 FL_EXPORT int glutCreateSubWindow(int win, int x, int y, int width, int height);
122 FL_EXPORT void glutDestroyWindow(int win);
124 inline void glutPostRedisplay() {glut_window->redraw();}
126 FL_EXPORT void glutSwapBuffers();
128 inline int glutGetWindow() {return glut_window->number;}
130 FL_EXPORT void glutSetWindow(int win);
132 inline void glutSetWindowTitle(char *t) {glut_window->label(t);}
134 inline void glutSetIconTitle(char *t) {glut_window->iconlabel(t);}
136 inline void glutPositionWindow(int x, int y) {glut_window->position(x,y);}
138 inline void glutReshapeWindow(int w, int h) {glut_window->size(w,h);}
140 inline void glutPopWindow() {glut_window->show();}
142 //inline void glutPushWindow();
144 inline void glutIconifyWindow() {glut_window->iconize();}
146 inline void glutShowWindow() {glut_window->show();}
148 inline void glutHideWindow() {glut_window->hide();}
150 inline void glutFullScreen() {glut_window->fullscreen();}
152 inline void glutSetCursor(Fl_Cursor cursor) {glut_window->cursor(cursor);}
153 // notice that the numeric values are different than glut:
154 #define GLUT_CURSOR_RIGHT_ARROW ((Fl_Cursor)2)
155 #define GLUT_CURSOR_LEFT_ARROW ((Fl_Cursor)67)
156 #define GLUT_CURSOR_INFO FL_CURSOR_HAND
157 #define GLUT_CURSOR_DESTROY ((Fl_Cursor)45)
158 #define GLUT_CURSOR_HELP FL_CURSOR_HELP
159 #define GLUT_CURSOR_CYCLE ((Fl_Cursor)26)
160 #define GLUT_CURSOR_SPRAY ((Fl_Cursor)63)
161 #define GLUT_CURSOR_WAIT FL_CURSOR_WAIT
162 #define GLUT_CURSOR_TEXT FL_CURSOR_INSERT
163 #define GLUT_CURSOR_CROSSHAIR FL_CURSOR_CROSS
164 #define GLUT_CURSOR_UP_DOWN FL_CURSOR_NS
165 #define GLUT_CURSOR_LEFT_RIGHT FL_CURSOR_WE
166 #define GLUT_CURSOR_TOP_SIDE FL_CURSOR_N
167 #define GLUT_CURSOR_BOTTOM_SIDE FL_CURSOR_S
168 #define GLUT_CURSOR_LEFT_SIDE FL_CURSOR_W
169 #define GLUT_CURSOR_RIGHT_SIDE FL_CURSOR_E
170 #define GLUT_CURSOR_TOP_LEFT_CORNER FL_CURSOR_NW
171 #define GLUT_CURSOR_TOP_RIGHT_CORNER FL_CURSOR_NE
172 #define GLUT_CURSOR_BOTTOM_RIGHT_CORNER FL_CURSOR_SE
173 #define GLUT_CURSOR_BOTTOM_LEFT_CORNER FL_CURSOR_SW
174 #define GLUT_CURSOR_INHERIT FL_CURSOR_DEFAULT
175 #define GLUT_CURSOR_NONE FL_CURSOR_NONE
176 #define GLUT_CURSOR_FULL_CROSSHAIR FL_CURSOR_CROSS
178 //inline void glutWarpPointer(int x, int y);
180 inline void glutEstablishOverlay() {glut_window->make_overlay_current();}
182 inline void glutRemoveOverlay() {glut_window->hide_overlay();}
184 inline void glutUseLayer(GLenum layer) {
185 layer ? glut_window->make_overlay_current() : glut_window->make_current();}
186 enum {GLUT_NORMAL, GLUT_OVERLAY};
188 inline void glutPostOverlayRedisplay() {glut_window->redraw_overlay();}
190 inline void glutShowOverlay() {glut_window->redraw_overlay();}
192 inline void glutHideOverlay() {glut_window->hide_overlay();}
194 FL_EXPORT int glutCreateMenu(void (*)(int));
196 FL_EXPORT void glutDestroyMenu(int menu);
198 inline int glutGetMenu() {return glut_menu;}
200 inline void glutSetMenu(int m) {glut_menu = m;}
202 FL_EXPORT void glutAddMenuEntry(char *label, int value);
204 FL_EXPORT void glutAddSubMenu(char *label, int submenu);
206 FL_EXPORT void glutChangeToMenuEntry(int item, char *label, int value);
208 FL_EXPORT void glutChangeToSubMenu(int item, char *label, int submenu);
210 FL_EXPORT void glutRemoveMenuItem(int item);
212 inline void glutAttachMenu(int b) {glut_window->menu[b] = glut_menu;}
214 inline void glutDetachMenu(int b) {glut_window->menu[b] = 0;}
216 inline void glutDisplayFunc(void (*f)()) {glut_window->display = f;}
218 inline void glutReshapeFunc(void (*f)(int w, int h)) {glut_window->reshape=f;}
220 inline void glutKeyboardFunc(void (*f)(uchar key, int x, int y)) {
221 glut_window->keyboard = f;}
223 inline void glutMouseFunc(void (*f)(int b, int state, int x, int y)) {
224 glut_window->mouse = f;}
225 #define GLUT_LEFT_BUTTON 0
226 #define GLUT_MIDDLE_BUTTON 1
227 #define GLUT_RIGHT_BUTTON 2
231 inline void glutMotionFunc(void (*f)(int x, int y)) {glut_window->motion= f;}
233 inline void glutPassiveMotionFunc(void (*f)(int x, int y)) {
234 glut_window->passivemotion= f;}
236 inline void glutEntryFunc(void (*f)(int s)) {glut_window->entry = f;}
237 enum {GLUT_LEFT, GLUT_ENTERED};
239 inline void glutVisibilityFunc(void (*f)(int s)) {glut_window->visibility=f;}
240 enum {GLUT_NOT_VISIBLE, GLUT_VISIBLE};
242 inline void glutIdleFunc(void (*f)()) {Fl::set_idle(f);}
244 // Warning: this cast may not work on all machines:
245 inline void glutTimerFunc(unsigned int msec, void (*f)(int), int value) {
246 Fl::add_timeout(msec*.001, (void (*)(void *))f, (void *)value);
249 inline void glutMenuStateFunc(void (*f)(int state)) {
250 glut_menustate_function = f;}
252 inline void glutMenuStatusFunc(void (*f)(int status, int x, int y)) {
253 glut_menustatus_function = f;}
254 enum {GLUT_MENU_NOT_IN_USE, GLUT_MENU_IN_USE};
256 inline void glutSpecialFunc(void (*f)(int key, int x, int y)) {
257 glut_window->special = f;}
258 #define GLUT_KEY_F1 1
259 #define GLUT_KEY_F2 2
260 #define GLUT_KEY_F3 3
261 #define GLUT_KEY_F4 4
262 #define GLUT_KEY_F5 5
263 #define GLUT_KEY_F6 6
264 #define GLUT_KEY_F7 7
265 #define GLUT_KEY_F8 8
266 #define GLUT_KEY_F9 9
267 #define GLUT_KEY_F10 10
268 #define GLUT_KEY_F11 11
269 #define GLUT_KEY_F12 12
270 // WARNING: Different values than Glut uses:
271 #define GLUT_KEY_LEFT FL_Left
272 #define GLUT_KEY_UP FL_Up
273 #define GLUT_KEY_RIGHT FL_Right
274 #define GLUT_KEY_DOWN FL_Down
275 #define GLUT_KEY_PAGE_UP FL_Page_Up
276 #define GLUT_KEY_PAGE_DOWN FL_Page_Down
277 #define GLUT_KEY_HOME FL_Home
278 #define GLUT_KEY_END FL_End
279 #define GLUT_KEY_INSERT FL_Insert
281 //inline void glutSpaceballMotionFunc(void (*)(int x, int y, int z));
283 //inline void glutSpaceballRotateFunc(void (*)(int x, int y, int z));
285 //inline void glutSpaceballButtonFunc(void (*)(int button, int state));
287 //inline void glutButtonBoxFunc(void (*)(int button, int state));
289 //inline void glutDialsFunc(void (*)(int dial, int value));
291 //inline void glutTabletMotionFunc(void (*)(int x, int y));
293 //inline void glutTabletButtonFunc(void (*)(int button, int state, int x, int y));
295 inline void glutOverlayDisplayFunc(void (*f)()) {
296 glut_window->overlaydisplay = f;}
298 //inline void glutWindowStatusFunc(void (*)(int state));
299 //enum {GLUT_HIDDEN, GLUT_FULLY_RETAINED, GLUT_PARTIALLY_RETAINED,
300 // GLUT_FULLY_COVERED};
302 //inline void glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
304 //inline GLfloat glutGetColor(int ndx, int component);
306 //#define GLUT_GREEN 1
307 //#define GLUT_BLUE 2
309 //inline void glutCopyColormap(int win);
311 // Warning: values are changed from Glut!
312 // Also relies on the GL_ symbols having values greater than 100
313 int glutGet(GLenum type);
315 GLUT_RETURN_ZERO = 0,
321 //GLUT_WINDOW_NUM_CHILDREN,
322 //GLUT_WINDOW_CURSOR,
325 //GLUT_SCREEN_WIDTH_MM,
326 //GLUT_SCREEN_HEIGHT_MM,
328 GLUT_DISPLAY_MODE_POSSIBLE,
331 GLUT_INIT_WINDOW_WIDTH,
332 GLUT_INIT_WINDOW_HEIGHT,
333 GLUT_INIT_DISPLAY_MODE,
335 GLUT_WINDOW_BUFFER_SIZE
338 #define GLUT_WINDOW_STENCIL_SIZE GL_STENCIL_BITS
339 #define GLUT_WINDOW_DEPTH_SIZE GL_DEPTH_BITS
340 #define GLUT_WINDOW_RED_SIZE GL_RED_BITS
341 #define GLUT_WINDOW_GREEN_SIZE GL_GREEN_BITS
342 #define GLUT_WINDOW_BLUE_SIZE GL_BLUE_BITS
343 #define GLUT_WINDOW_ALPHA_SIZE GL_ALPHA_BITS
344 #define GLUT_WINDOW_ACCUM_RED_SIZE GL_ACCUM_RED_BITS
345 #define GLUT_WINDOW_ACCUM_GREEN_SIZE GL_ACCUM_GREEN_BITS
346 #define GLUT_WINDOW_ACCUM_BLUE_SIZE GL_ACCUM_BLUE_BITS
347 #define GLUT_WINDOW_ACCUM_ALPHA_SIZE GL_ACCUM_ALPHA_BITS
348 #define GLUT_WINDOW_DOUBLEBUFFER GL_DOUBLEBUFFER
349 #define GLUT_WINDOW_RGBA GL_RGBA
350 #define GLUT_WINDOW_COLORMAP_SIZE GL_INDEX_BITS
351 #ifdef GL_SAMPLES_SGIS
352 #define GLUT_WINDOW_NUM_SAMPLES GL_SAMPLES_SGIS
354 #define GLUT_WINDOW_NUM_SAMPLES GLUT_RETURN_ZERO
356 #define GLUT_WINDOW_STEREO GL_STEREO
358 //int glutDeviceGet(GLenum type);
359 //#define GLUT_HAS_KEYBOARD 600
360 //#define GLUT_HAS_MOUSE 601
361 //#define GLUT_HAS_SPACEBALL 602
362 //#define GLUT_HAS_DIAL_AND_BUTTON_BOX 603
363 //#define GLUT_HAS_TABLET 604
364 //#define GLUT_NUM_MOUSE_BUTTONS 605
365 //#define GLUT_NUM_SPACEBALL_BUTTONS 606
366 //#define GLUT_NUM_BUTTON_BOX_BUTTONS 607
367 //#define GLUT_NUM_DIALS 608
368 //#define GLUT_NUM_TABLET_BUTTONS 609
370 inline int glutGetModifiers() {return Fl::event_state();}
371 // WARNING: these values are different than Glut uses:
372 #define GLUT_ACTIVE_SHIFT FL_SHIFT
373 #define GLUT_ACTIVE_CTRL FL_CTRL
374 #define GLUT_ACTIVE_ALT FL_ALT
376 int glutLayerGet(GLenum);
377 #define GLUT_OVERLAY_POSSIBLE 800
378 //#define GLUT_LAYER_IN_USE 801
379 //#define GLUT_HAS_OVERLAY 802
380 #define GLUT_TRANSPARENT_INDEX 803
381 #define GLUT_NORMAL_DAMAGED 804
382 #define GLUT_OVERLAY_DAMAGED 805
384 //inline int glutVideoResizeGet(GLenum param);
385 //#define GLUT_VIDEO_RESIZE_POSSIBLE 900
386 //#define GLUT_VIDEO_RESIZE_IN_USE 901
387 //#define GLUT_VIDEO_RESIZE_X_DELTA 902
388 //#define GLUT_VIDEO_RESIZE_Y_DELTA 903
389 //#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904
390 //#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905
391 //#define GLUT_VIDEO_RESIZE_X 906
392 //#define GLUT_VIDEO_RESIZE_Y 907
393 //#define GLUT_VIDEO_RESIZE_WIDTH 908
394 //#define GLUT_VIDEO_RESIZE_HEIGHT 909
396 //inline void glutSetupVideoResizing();
398 //inline void glutStopVideoResizing();
400 //inline void glutVideoResize(int x, int y, int width, int height);
402 //inline void glutVideoPan(int x, int y, int width, int height);
404 ////////////////////////////////////////////////////////////////
405 // Emulated Glut drawing functions:
407 // Font argument must be a void* for compatability, so...
408 extern FL_EXPORT struct Glut_Bitmap_Font {uchar font; int size;}
409 glutBitmap9By15, glutBitmap8By13, glutBitmapTimesRoman10,
410 glutBitmapTimesRoman24, glutBitmapHelvetica10, glutBitmapHelvetica12,
411 glutBitmapHelvetica18;
412 #define GLUT_BITMAP_9_BY_15 (&glutBitmap9By15)
413 #define GLUT_BITMAP_8_BY_13 (&glutBitmap8By13)
414 #define GLUT_BITMAP_TIMES_ROMAN_10 (&glutBitmapTimesRoman10)
415 #define GLUT_BITMAP_TIMES_ROMAN_24 (&glutBitmapTimesRoman24)
416 #define GLUT_BITMAP_HELVETICA_10 (&glutBitmapHelvetica10)
417 #define GLUT_BITMAP_HELVETICA_12 (&glutBitmapHelvetica12)
418 #define GLUT_BITMAP_HELVETICA_18 (&glutBitmapHelvetica18)
420 FL_EXPORT void glutBitmapCharacter(void *font, int character);
421 FL_EXPORT int glutBitmapWidth(void *font, int character);
423 ////////////////////////////////////////////////////////////////
424 // Glut drawing functions. These are NOT emulated but you can
425 // link in the glut library to get them. This assummes the object
426 // files in Glut remain as they currently are so that there are
427 // not symbol conflicts with the above.
431 extern int APIENTRY glutExtensionSupported(char *name);
433 /* Stroke font constants (use these in GLUT program). */
435 # define GLUT_STROKE_ROMAN ((void*)0)
436 # define GLUT_STROKE_MONO_ROMAN ((void*)1)
438 extern void *glutStrokeRoman;
439 # define GLUT_STROKE_ROMAN (&glutStrokeRoman)
440 extern void *glutStrokeMonoRoman;
441 # define GLUT_STROKE_MONO_ROMAN (&glutStrokeMonoRoman)
444 /* GLUT font sub-API */
445 extern void APIENTRY glutStrokeCharacter(void *font, int character);
446 extern int APIENTRY glutStrokeWidth(void *font, int character);
448 /* GLUT pre-built models sub-API */
449 extern void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
450 extern void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
451 extern void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
452 extern void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
453 extern void APIENTRY glutWireCube(GLdouble size);
454 extern void APIENTRY glutSolidCube(GLdouble size);
455 extern void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
456 extern void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
457 extern void APIENTRY glutWireDodecahedron();
458 extern void APIENTRY glutSolidDodecahedron();
459 extern void APIENTRY glutWireTeapot(GLdouble size);
460 extern void APIENTRY glutSolidTeapot(GLdouble size);
461 extern void APIENTRY glutWireOctahedron();
462 extern void APIENTRY glutSolidOctahedron();
463 extern void APIENTRY glutWireTetrahedron();
464 extern void APIENTRY glutSolidTetrahedron();
465 extern void APIENTRY glutWireIcosahedron();
466 extern void APIENTRY glutSolidIcosahedron();
470 #endif /* __glut_h__ */
473 // End of "$Id: glut.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $".