2 // "$Id: glut.H 8623 2011-04-24 17:09:41Z AlbrechtS $"
4 // GLUT emulation header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2011 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 on the following page:
25 // http://www.fltk.org/str.php
28 // Emulation of GLUT using fltk.
30 // GLUT is Copyright (c) Mark J. Kilgard, 1994, 1995, 1996:
31 // "This program is freely distributable without licensing fees and is
32 // provided without guarantee or warrantee expressed or implied. This
33 // program is -not- in the public domain."
35 // Although I have copied the GLUT API, none of my code is based on
36 // any GLUT implementation details and is therefore covered by the LGPL.
38 // Commented out lines indicate parts of GLUT that are not emulated.
47 # include "Fl_Gl_Window.H"
50 GLUT is emulated using this window class and these static variables
51 (plus several more static variables hidden in glut_compatability.cxx):
53 class FL_EXPORT Fl_Glut_Window : public Fl_Gl_Window {
60 public: // so the inline functions work
65 void (*overlaydisplay)();
66 void (*reshape)(int w, int h);
67 void (*keyboard)(uchar, int x, int y);
68 void (*mouse)(int b, int state, int x, int y);
69 void (*motion)(int x, int y);
70 void (*passivemotion)(int x, int y);
72 void (*visibility)(int);
73 void (*special)(int, int x, int y);
74 Fl_Glut_Window(int w, int h, const char *);
75 Fl_Glut_Window(int x, int y, int w, int h, const char *);
79 extern FL_EXPORT Fl_Glut_Window *glut_window; // the current window
80 extern FL_EXPORT int glut_menu; // the current menu
82 // function pointers that are not per-window:
83 extern FL_EXPORT void (*glut_idle_function)();
84 extern FL_EXPORT void (*glut_menustate_function)(int);
85 extern FL_EXPORT void (*glut_menustatus_function)(int,int,int);
87 ////////////////////////////////////////////////////////////////
89 //# define GLUT_API_VERSION This does not match any version of GLUT exactly...
91 FL_EXPORT void glutInit(int *argcp, char **argv); // creates first window
93 FL_EXPORT void glutInitDisplayMode(unsigned int mode);
94 // the FL_ symbols have the same value as the GLUT ones:
95 # define GLUT_RGB FL_RGB
96 # define GLUT_RGBA FL_RGB
97 # define GLUT_INDEX FL_INDEX
98 # define GLUT_SINGLE FL_SINGLE
99 # define GLUT_DOUBLE FL_DOUBLE
100 # define GLUT_ACCUM FL_ACCUM
101 # define GLUT_ALPHA FL_ALPHA
102 # define GLUT_DEPTH FL_DEPTH
103 # define GLUT_STENCIL FL_STENCIL
104 # define GLUT_MULTISAMPLE FL_MULTISAMPLE
105 # define GLUT_STEREO FL_STEREO
106 // # define GLUT_LUMINANCE 512
108 FL_EXPORT void glutInitWindowPosition(int x, int y);
110 FL_EXPORT void glutInitWindowSize(int w, int h);
112 FL_EXPORT void glutMainLoop();
114 FL_EXPORT int glutCreateWindow(char *title);
115 FL_EXPORT int glutCreateWindow(const char *title);
117 FL_EXPORT int glutCreateSubWindow(int win, int x, int y, int width, int height);
119 FL_EXPORT void glutDestroyWindow(int win);
121 inline void glutPostRedisplay() {glut_window->redraw();}
123 FL_EXPORT void glutPostWindowRedisplay(int win);
125 FL_EXPORT void glutSwapBuffers();
127 inline int glutGetWindow() {return glut_window->number;}
129 FL_EXPORT void glutSetWindow(int win);
131 inline void glutSetWindowTitle(char *t) {glut_window->label(t);}
133 inline void glutSetIconTitle(char *t) {glut_window->iconlabel(t);}
135 inline void glutPositionWindow(int x, int y) {glut_window->position(x,y);}
137 inline void glutReshapeWindow(int w, int h) {glut_window->size(w,h);}
139 inline void glutPopWindow() {glut_window->show();}
141 inline void glutPushWindow() { /* do nothing */ }
143 inline void glutIconifyWindow() {glut_window->iconize();}
145 inline void glutShowWindow() {glut_window->show();}
147 inline void glutHideWindow() {glut_window->hide();}
149 inline void glutFullScreen() {glut_window->fullscreen();}
151 inline void glutSetCursor(Fl_Cursor cursor) {glut_window->cursor(cursor);}
152 // notice that the numeric values are different than glut:
153 # define GLUT_CURSOR_RIGHT_ARROW ((Fl_Cursor)2)
154 # define GLUT_CURSOR_LEFT_ARROW ((Fl_Cursor)67)
155 # define GLUT_CURSOR_INFO FL_CURSOR_HAND
156 # define GLUT_CURSOR_DESTROY ((Fl_Cursor)45)
157 # define GLUT_CURSOR_HELP FL_CURSOR_HELP
158 # define GLUT_CURSOR_CYCLE ((Fl_Cursor)26)
159 # define GLUT_CURSOR_SPRAY ((Fl_Cursor)63)
160 # define GLUT_CURSOR_WAIT FL_CURSOR_WAIT
161 # define GLUT_CURSOR_TEXT FL_CURSOR_INSERT
162 # define GLUT_CURSOR_CROSSHAIR FL_CURSOR_CROSS
163 # define GLUT_CURSOR_UP_DOWN FL_CURSOR_NS
164 # define GLUT_CURSOR_LEFT_RIGHT FL_CURSOR_WE
165 # define GLUT_CURSOR_TOP_SIDE FL_CURSOR_N
166 # define GLUT_CURSOR_BOTTOM_SIDE FL_CURSOR_S
167 # define GLUT_CURSOR_LEFT_SIDE FL_CURSOR_W
168 # define GLUT_CURSOR_RIGHT_SIDE FL_CURSOR_E
169 # define GLUT_CURSOR_TOP_LEFT_CORNER FL_CURSOR_NW
170 # define GLUT_CURSOR_TOP_RIGHT_CORNER FL_CURSOR_NE
171 # define GLUT_CURSOR_BOTTOM_RIGHT_CORNER FL_CURSOR_SE
172 # define GLUT_CURSOR_BOTTOM_LEFT_CORNER FL_CURSOR_SW
173 # define GLUT_CURSOR_INHERIT FL_CURSOR_DEFAULT
174 # define GLUT_CURSOR_NONE FL_CURSOR_NONE
175 # define GLUT_CURSOR_FULL_CROSSHAIR FL_CURSOR_CROSS
177 inline void glutWarpPointer(int, int) { /* do nothing */ }
179 inline void glutEstablishOverlay() {glut_window->make_overlay_current();}
181 inline void glutRemoveOverlay() {glut_window->hide_overlay();}
183 inline void glutUseLayer(GLenum layer) {
184 layer ? glut_window->make_overlay_current() : glut_window->make_current();}
185 enum {GLUT_NORMAL, GLUT_OVERLAY};
187 inline void glutPostOverlayRedisplay() {glut_window->redraw_overlay();}
189 inline void glutShowOverlay() {glut_window->redraw_overlay();}
191 inline void glutHideOverlay() {glut_window->hide_overlay();}
193 FL_EXPORT int glutCreateMenu(void (*)(int));
195 FL_EXPORT void glutDestroyMenu(int menu);
197 inline int glutGetMenu() {return glut_menu;}
199 inline void glutSetMenu(int m) {glut_menu = m;}
201 FL_EXPORT void glutAddMenuEntry(char *label, int value);
203 FL_EXPORT void glutAddSubMenu(char *label, int submenu);
205 FL_EXPORT void glutChangeToMenuEntry(int item, char *labela, int value);
207 FL_EXPORT void glutChangeToSubMenu(int item, char *label, int submenu);
209 FL_EXPORT void glutRemoveMenuItem(int item);
211 inline void glutAttachMenu(int b) {glut_window->menu[b] = glut_menu;}
213 inline void glutDetachMenu(int b) {glut_window->menu[b] = 0;}
215 inline void glutDisplayFunc(void (*f)()) {glut_window->display = f;}
217 inline void glutReshapeFunc(void (*f)(int w, int h)) {glut_window->reshape=f;}
219 inline void glutKeyboardFunc(void (*f)(uchar key, int x, int y)) {
220 glut_window->keyboard = f;}
222 inline void glutMouseFunc(void (*f)(int b, int state, int x, int y)) {
223 glut_window->mouse = f;}
224 # define GLUT_LEFT_BUTTON 0
225 # define GLUT_MIDDLE_BUTTON 1
226 # define GLUT_RIGHT_BUTTON 2
230 inline void glutMotionFunc(void (*f)(int x, int y)) {glut_window->motion= f;}
232 inline void glutPassiveMotionFunc(void (*f)(int x, int y)) {
233 glut_window->passivemotion= f;}
235 inline void glutEntryFunc(void (*f)(int s)) {glut_window->entry = f;}
236 enum {GLUT_LEFT, GLUT_ENTERED};
238 inline void glutVisibilityFunc(void (*f)(int s)) {glut_window->visibility=f;}
239 enum {GLUT_NOT_VISIBLE, GLUT_VISIBLE};
241 FL_EXPORT void glutIdleFunc(void (*f)());
243 // Warning: this cast may not work on all machines:
244 inline void glutTimerFunc(unsigned int msec, void (*f)(int), int value) {
245 Fl::add_timeout(msec*.001, (void (*)(void *))f, (void *)value);
248 inline void glutMenuStateFunc(void (*f)(int state)) {
249 glut_menustate_function = f;}
251 inline void glutMenuStatusFunc(void (*f)(int status, int x, int y)) {
252 glut_menustatus_function = f;}
253 enum {GLUT_MENU_NOT_IN_USE, GLUT_MENU_IN_USE};
255 inline void glutSpecialFunc(void (*f)(int key, int x, int y)) {
256 glut_window->special = f;}
257 # define GLUT_KEY_F1 1
258 # define GLUT_KEY_F2 2
259 # define GLUT_KEY_F3 3
260 # define GLUT_KEY_F4 4
261 # define GLUT_KEY_F5 5
262 # define GLUT_KEY_F6 6
263 # define GLUT_KEY_F7 7
264 # define GLUT_KEY_F8 8
265 # define GLUT_KEY_F9 9
266 # define GLUT_KEY_F10 10
267 # define GLUT_KEY_F11 11
268 # define GLUT_KEY_F12 12
269 // WARNING: Different values than GLUT uses:
270 # define GLUT_KEY_LEFT FL_Left
271 # define GLUT_KEY_UP FL_Up
272 # define GLUT_KEY_RIGHT FL_Right
273 # define GLUT_KEY_DOWN FL_Down
274 # define GLUT_KEY_PAGE_UP FL_Page_Up
275 # define GLUT_KEY_PAGE_DOWN FL_Page_Down
276 # define GLUT_KEY_HOME FL_Home
277 # define GLUT_KEY_END FL_End
278 # define GLUT_KEY_INSERT FL_Insert
280 //inline void glutSpaceballMotionFunc(void (*)(int x, int y, int z));
282 //inline void glutSpaceballRotateFunc(void (*)(int x, int y, int z));
284 //inline void glutSpaceballButtonFunc(void (*)(int button, int state));
286 //inline void glutButtonBoxFunc(void (*)(int button, int state));
288 //inline void glutDialsFunc(void (*)(int dial, int value));
290 //inline void glutTabletMotionFunc(void (*)(int x, int y));
292 //inline void glutTabletButtonFunc(void (*)(int button, int state, int x, int y));
294 inline void glutOverlayDisplayFunc(void (*f)()) {
295 glut_window->overlaydisplay = f;}
297 //inline void glutWindowStatusFunc(void (*)(int state));
298 //enum {GLUT_HIDDEN, GLUT_FULLY_RETAINED, GLUT_PARTIALLY_RETAINED,
299 // GLUT_FULLY_COVERED};
301 //inline void glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
303 //inline GLfloat glutGetColor(int ndx, int component);
305 //#define GLUT_GREEN 1
306 //#define GLUT_BLUE 2
308 //inline void glutCopyColormap(int win);
310 // Warning: values are changed from GLUT!
311 // Also relies on the GL_ symbols having values greater than 100
312 FL_EXPORT int glutGet(GLenum type);
314 GLUT_RETURN_ZERO = 0,
323 GLUT_DISPLAY_MODE_POSSIBLE,
326 GLUT_INIT_WINDOW_WIDTH,
327 GLUT_INIT_WINDOW_HEIGHT,
328 GLUT_INIT_DISPLAY_MODE,
329 GLUT_WINDOW_BUFFER_SIZE,
331 //GLUT_WINDOW_NUM_CHILDREN,
332 //GLUT_WINDOW_CURSOR,
333 //GLUT_SCREEN_WIDTH_MM,
334 //GLUT_SCREEN_HEIGHT_MM,
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 # define GLUT_HAS_KEYBOARD 600
359 # define GLUT_HAS_MOUSE 601
360 # define GLUT_HAS_SPACEBALL 602
361 # define GLUT_HAS_DIAL_AND_BUTTON_BOX 603
362 # define GLUT_HAS_TABLET 604
363 # define GLUT_NUM_MOUSE_BUTTONS 605
364 # define GLUT_NUM_SPACEBALL_BUTTONS 606
365 # define GLUT_NUM_BUTTON_BOX_BUTTONS 607
366 # define GLUT_NUM_DIALS 608
367 # define GLUT_NUM_TABLET_BUTTONS 609
368 FL_EXPORT int glutDeviceGet(GLenum type);
370 // WARNING: these values are different than GLUT uses:
371 # define GLUT_ACTIVE_SHIFT FL_SHIFT
372 # define GLUT_ACTIVE_CTRL FL_CTRL
373 # define GLUT_ACTIVE_ALT FL_ALT
374 inline int glutGetModifiers() {return Fl::event_state() & (GLUT_ACTIVE_SHIFT | GLUT_ACTIVE_CTRL | GLUT_ACTIVE_ALT);}
376 FL_EXPORT 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
385 typedef void (*GLUTproc)();
388 FL_EXPORT GLUTproc glutGetProcAddress(const char *procName);
390 //inline int glutVideoResizeGet(GLenum param);
391 //#define GLUT_VIDEO_RESIZE_POSSIBLE 900
392 //#define GLUT_VIDEO_RESIZE_IN_USE 901
393 //#define GLUT_VIDEO_RESIZE_X_DELTA 902
394 //#define GLUT_VIDEO_RESIZE_Y_DELTA 903
395 //#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904
396 //#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905
397 //#define GLUT_VIDEO_RESIZE_X 906
398 //#define GLUT_VIDEO_RESIZE_Y 907
399 //#define GLUT_VIDEO_RESIZE_WIDTH 908
400 //#define GLUT_VIDEO_RESIZE_HEIGHT 909
402 //inline void glutSetupVideoResizing();
404 //inline void glutStopVideoResizing();
406 //inline void glutVideoResize(int x, int y, int width, int height);
408 //inline void glutVideoPan(int x, int y, int width, int height);
410 // Font argument must be a void* for compatibility, so...
411 /** fltk glut font/size attributes used in the glutXXX functions */
412 struct Fl_Glut_Bitmap_Font {Fl_Font font; Fl_Fontsize size;};
414 extern FL_EXPORT struct Fl_Glut_Bitmap_Font
415 glutBitmap9By15, glutBitmap8By13, glutBitmapTimesRoman10,
416 glutBitmapTimesRoman24, glutBitmapHelvetica10, glutBitmapHelvetica12,
417 glutBitmapHelvetica18;
418 # define GLUT_BITMAP_9_BY_15 (&glutBitmap9By15)
419 # define GLUT_BITMAP_8_BY_13 (&glutBitmap8By13)
420 # define GLUT_BITMAP_TIMES_ROMAN_10 (&glutBitmapTimesRoman10)
421 # define GLUT_BITMAP_TIMES_ROMAN_24 (&glutBitmapTimesRoman24)
422 # define GLUT_BITMAP_HELVETICA_10 (&glutBitmapHelvetica10)
423 # define GLUT_BITMAP_HELVETICA_12 (&glutBitmapHelvetica12)
424 # define GLUT_BITMAP_HELVETICA_18 (&glutBitmapHelvetica18)
426 FL_EXPORT void glutBitmapCharacter(void *font, int character);
427 FL_EXPORT int glutBitmapHeight(void *font);
428 FL_EXPORT int glutBitmapLength(void *font, const unsigned char *string);
429 FL_EXPORT void glutBitmapString(void *font, const unsigned char *string);
430 FL_EXPORT int glutBitmapWidth(void *font, int character);
432 FL_EXPORT int glutExtensionSupported(char *name);
434 /* GLUT stroked font sub-API */
435 struct Fl_Glut_StrokeVertex {
439 struct Fl_Glut_StrokeStrip {
441 const Fl_Glut_StrokeVertex* Vertices;
444 struct Fl_Glut_StrokeChar {
447 const Fl_Glut_StrokeStrip* Strips;
450 struct Fl_Glut_StrokeFont {
451 char* Name; // The source font name
452 int Quantity; // Number of chars in font
453 GLfloat Height; // Height of the characters
454 const Fl_Glut_StrokeChar** Characters;// The characters mapping
456 extern FL_EXPORT Fl_Glut_StrokeFont glutStrokeRoman;
457 extern FL_EXPORT Fl_Glut_StrokeFont glutStrokeMonoRoman;
458 # define GLUT_STROKE_ROMAN (&glutStrokeRoman)
459 # define GLUT_STROKE_MONO_ROMAN (&glutStrokeMonoRoman)
461 FL_EXPORT void glutStrokeCharacter(void *font, int character);
462 FL_EXPORT GLfloat glutStrokeHeight(void *font);
463 FL_EXPORT int glutStrokeLength(void *font, const unsigned char *string);
464 FL_EXPORT void glutStrokeString(void *font, const unsigned char *string);
465 FL_EXPORT int glutStrokeWidth(void *font, int character);
467 /* GLUT pre-built models sub-API */
468 FL_EXPORT void glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
469 FL_EXPORT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
470 FL_EXPORT void glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
471 FL_EXPORT void glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
472 FL_EXPORT void glutWireCube(GLdouble size);
473 FL_EXPORT void glutSolidCube(GLdouble size);
474 FL_EXPORT void glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
475 FL_EXPORT void glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
476 FL_EXPORT void glutWireDodecahedron();
477 FL_EXPORT void glutSolidDodecahedron();
478 FL_EXPORT void glutWireTeapot(GLdouble size);
479 FL_EXPORT void glutSolidTeapot(GLdouble size);
480 FL_EXPORT void glutWireOctahedron();
481 FL_EXPORT void glutSolidOctahedron();
482 FL_EXPORT void glutWireTetrahedron();
483 FL_EXPORT void glutSolidTetrahedron();
484 FL_EXPORT void glutWireIcosahedron();
485 FL_EXPORT void glutSolidIcosahedron();
490 // End of "$Id: glut.H 8623 2011-04-24 17:09:41Z AlbrechtS $".