source: NonGTP/glut/FLTK/include/fltk/glut.h @ 814

Revision 814, 16.3 KB checked in by gumbau, 18 years ago (diff)

Glut initial import used by Geometry modules

Line 
1//
2// "$Id: glut.h 3961 2005-01-24 08:07:59Z spitzak $"
3//
4// GLUT emulation header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2003 by Bill Spitzak and others.
7//
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.
12//
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.
17//
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
21// USA.
22//
23// Please report all bugs and problems to "fltk-bugs@fltk.org".
24//
25
26// Emulation of Glut using fltk.
27
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."
32
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.
35
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.
41
42// Commented out lines indicate parts of Glut that are not emulated.
43
44#ifndef __glut_h__
45#define __glut_h__
46
47#include <fltk/run.h>
48#include <fltk/GlWindow.h>
49#include <fltk/gl.h>
50#include <fltk/events.h>
51#include <fltk/visual.h>
52//#include <GL/glu.h>
53
54////////////////////////////////////////////////////////////////
55// Glut is emulated using this window class and these static variables
56// (plus several more static variables hidden in glut.C):
57
58class FL_GLUT_API Fl_Glut_Window : public fltk::GlWindow {
59  void _init();
60  int mouse_down;
61protected:
62  void draw();
63  void draw_overlay();
64  int handle(int);
65public: // so the inline functions work
66  int number;
67  int menu[3];
68  void make_current();
69  void (*display)();
70  void (*overlaydisplay)();
71  void (*reshape)(int w, int h);
72  void (*keyboard)(uchar, int x, int y);
73  void (*mouse)(int b, int state, int x, int y);
74  void (*motion)(int x, int y);
75  void (*passivemotion)(int x, int y);
76  void (*entry)(int);
77  void (*visibility)(int);
78  void (*special)(int, int x, int y);
79  Fl_Glut_Window(int w, int h, const char *);
80  Fl_Glut_Window(int x, int y, int w, int h, const char *);
81  ~Fl_Glut_Window();
82};
83
84extern FL_GLUT_API Fl_Glut_Window *glut_window; // the current window
85extern FL_GLUT_API int glut_menu;                       // the current menu
86
87// function pointers that are not per-window:
88extern FL_GLUT_API void (*glut_idle_function)();
89extern FL_GLUT_API void (*glut_menustate_function)(int);
90extern FL_GLUT_API void (*glut_menustatus_function)(int,int,int);
91
92////////////////////////////////////////////////////////////////
93
94//#define GLUT_API_VERSION This does not match any version of Glut exactly...
95
96FL_GLUT_API void glutInit(int *argcp, char **argv); // creates first window
97
98FL_GLUT_API void glutInitDisplayMode(unsigned int mode);
99// the FL_ symbols have the same value as the GLUT ones:
100enum {
101  GLUT_RGB      = fltk::RGB_COLOR,
102  GLUT_RGBA     = fltk::RGB_COLOR,
103  GLUT_INDEX    = fltk::INDEXED_COLOR,
104  GLUT_SINGLE   = fltk::SINGLE_BUFFER,
105  GLUT_DOUBLE   = fltk::DOUBLE_BUFFER,
106  GLUT_ACCUM    = fltk::ACCUM_BUFFER,
107  GLUT_ALPHA    = fltk::ALPHA_BUFFER,
108  GLUT_DEPTH    = fltk::DEPTH_BUFFER,
109  GLUT_STENCIL  = fltk::STENCIL_BUFFER,
110  GLUT_MULTISAMPLE = fltk::MULTISAMPLE,
111  GLUT_STEREO   = fltk::STEREO
112//GLUT_LUMINANCE = 512
113};
114
115FL_GLUT_API void glutInitWindowPosition(int x, int y);
116
117FL_GLUT_API void glutInitWindowSize(int w, int h);
118
119FL_GLUT_API void glutMainLoop();
120
121FL_GLUT_API int glutCreateWindow(const char *title);
122
123FL_GLUT_API int glutCreateSubWindow(int win, int x, int y, int width, int height);
124
125FL_GLUT_API void glutDestroyWindow(int win);
126
127inline void glutPostRedisplay() {glut_window->redraw();}
128
129FL_GLUT_API void glutSwapBuffers();
130
131inline int glutGetWindow() {return glut_window->number;}
132
133FL_GLUT_API void glutSetWindow(int win);
134
135inline void glutSetWindowTitle(const char *t) {glut_window->label(t);}
136
137inline void glutSetIconTitle(const char *t) {glut_window->iconlabel(t);}
138
139inline void glutPositionWindow(int x, int y) {glut_window->position(x,y);}
140
141inline void glutReshapeWindow(int w, int h) {glut_window->resize(w,h);}
142
143inline void glutPopWindow() {glut_window->show();}
144
145//inline void glutPushWindow();
146
147inline void glutIconifyWindow() {glut_window->iconize();}
148
149inline void glutShowWindow() {glut_window->show();}
150
151inline void glutHideWindow() {glut_window->hide();}
152
153inline void glutFullScreen() {glut_window->fullscreen();}
154
155inline void glutSetCursor(fltk::Cursor* cursor) {glut_window->cursor(cursor);}
156
157//#define GLUT_CURSOR_RIGHT_ARROW
158//#define GLUT_CURSOR_LEFT_ARROW
159#define GLUT_CURSOR_INFO        fltk::CURSOR_HAND
160//#define GLUT_CURSOR_DESTROY
161#define GLUT_CURSOR_HELP        fltk::CURSOR_HELP
162//#define GLUT_CURSOR_CYCLE
163//#define GLUT_CURSOR_SPRAY
164#define GLUT_CURSOR_WAIT        fltk::CURSOR_WAIT
165#define GLUT_CURSOR_TEXT        fltk::CURSOR_INSERT
166#define GLUT_CURSOR_CROSSHAIR   fltk::CURSOR_CROSS
167#define GLUT_CURSOR_UP_DOWN     fltk::CURSOR_NS
168#define GLUT_CURSOR_TOP_SIDE    fltk::CURSOR_NS
169#define GLUT_CURSOR_BOTTOM_SIDE fltk::CURSOR_NS
170#define GLUT_CURSOR_LEFT_RIGHT  fltk::CURSOR_WE
171#define GLUT_CURSOR_LEFT_SIDE   fltk::CURSOR_WE
172#define GLUT_CURSOR_RIGHT_SIDE  fltk::CURSOR_WE
173#define GLUT_CURSOR_TOP_LEFT_CORNER     fltk::CURSOR_NWSE
174#define GLUT_CURSOR_TOP_RIGHT_CORNER    fltk::CURSOR_NESW
175#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER fltk::CURSOR_NWSE
176#define GLUT_CURSOR_BOTTOM_LEFT_CORNER  fltk::CURSOR_NESW
177#define GLUT_CURSOR_INHERIT             fltk::CURSOR_DEFAULT
178#define GLUT_CURSOR_NONE                fltk::CURSOR_NONE
179#define GLUT_CURSOR_FULL_CROSSHAIR      fltk::CURSOR_CROSS
180
181//inline void glutWarpPointer(int x, int y);
182
183inline void glutEstablishOverlay() {glut_window->make_overlay_current();}
184
185inline void glutRemoveOverlay() {glut_window->hide_overlay();}
186
187inline void glutUseLayer(GLenum layer) {
188  layer ? glut_window->make_overlay_current() : glut_window->make_current();}
189enum {GLUT_NORMAL, GLUT_OVERLAY};
190
191inline void glutPostOverlayRedisplay() {glut_window->redraw_overlay();}
192
193inline void glutShowOverlay() {glut_window->redraw_overlay();}
194
195inline void glutHideOverlay() {glut_window->hide_overlay();}
196
197FL_GLUT_API int glutCreateMenu(void (*)(int));
198
199FL_GLUT_API void glutDestroyMenu(int menu);
200
201inline int glutGetMenu() {return glut_menu;}
202
203inline void glutSetMenu(int m) {glut_menu = m;}
204
205FL_GLUT_API void glutAddMenuEntry(const char *label, int value);
206
207FL_GLUT_API void glutAddSubMenu(const char *label, int submenu);
208
209FL_GLUT_API void glutChangeToMenuEntry(int item, const char *label, int value);
210
211FL_GLUT_API void glutChangeToSubMenu(int item, const char *label, int submenu);
212
213FL_GLUT_API void glutRemoveMenuItem(int item);
214
215inline void glutAttachMenu(int b) {glut_window->menu[b] = glut_menu;}
216
217inline void glutDetachMenu(int b) {glut_window->menu[b] = 0;}
218
219inline void glutDisplayFunc(void (*f)()) {glut_window->display = f;}
220
221inline void glutReshapeFunc(void (*f)(int w, int h)) {glut_window->reshape=f;}
222
223inline void glutKeyboardFunc(void (*f)(uchar key, int x, int y)) {
224  glut_window->keyboard = f;}
225
226inline void glutMouseFunc(void (*f)(int b, int state, int x, int y)) {
227  glut_window->mouse = f;}
228enum {
229  GLUT_LEFT_BUTTON      = 0,
230  GLUT_MIDDLE_BUTTON    = 1,
231  GLUT_RIGHT_BUTTON     = 2,
232  GLUT_DOWN             = 0,
233  GLUT_UP               = 1
234};
235
236inline void glutMotionFunc(void (*f)(int x, int y)) {glut_window->motion= f;}
237
238inline void glutPassiveMotionFunc(void (*f)(int x, int y)) {
239  glut_window->passivemotion= f;}
240
241inline void glutEntryFunc(void (*f)(int s)) {glut_window->entry = f;}
242enum {GLUT_LEFT, GLUT_ENTERED};
243
244inline void glutVisibilityFunc(void (*f)(int s)) {glut_window->visibility=f;}
245enum {GLUT_NOT_VISIBLE, GLUT_VISIBLE};
246
247inline void glutIdleFunc(void (*f)()) {fltk::set_idle(f);}
248
249// Warning: this cast may not work on all machines:
250inline void glutTimerFunc(unsigned int msec, void (*f)(int), int value) {
251  fltk::add_timeout(msec*.001f, (fltk::TimeoutHandler)f, (void *)value);
252}
253
254inline void glutMenuStateFunc(void (*f)(int state)) {
255  glut_menustate_function = f;}
256
257inline void glutMenuStatusFunc(void (*f)(int status, int x, int y)) {
258  glut_menustatus_function = f;}
259enum {GLUT_MENU_NOT_IN_USE, GLUT_MENU_IN_USE};
260
261inline void glutSpecialFunc(void (*f)(int key, int x, int y)) {
262  glut_window->special = f;}
263enum {
264  GLUT_KEY_F1           = 1,
265  GLUT_KEY_F2           = 2,
266  GLUT_KEY_F3           = 3,
267  GLUT_KEY_F4           = 4,
268  GLUT_KEY_F5           = 5,
269  GLUT_KEY_F6           = 6,
270  GLUT_KEY_F7           = 7,
271  GLUT_KEY_F8           = 8,
272  GLUT_KEY_F9           = 9,
273  GLUT_KEY_F10          = 10,
274  GLUT_KEY_F11          = 11,
275  GLUT_KEY_F12          = 12,
276// WARNING: Different values than Glut uses:
277  GLUT_KEY_LEFT         = fltk::LeftKey,
278  GLUT_KEY_UP           = fltk::UpKey,
279  GLUT_KEY_RIGHT        = fltk::RightKey,
280  GLUT_KEY_DOWN         = fltk::DownKey,
281  GLUT_KEY_PAGE_UP      = fltk::PageUpKey,
282  GLUT_KEY_PAGE_DOWN    = fltk::PageDownKey,
283  GLUT_KEY_HOME         = fltk::HomeKey,
284  GLUT_KEY_END          = fltk::EndKey,
285  GLUT_KEY_INSERT       = fltk::InsertKey
286};
287
288//inline void glutSpaceballMotionFunc(void (*)(int x, int y, int z));
289
290//inline void glutSpaceballRotateFunc(void (*)(int x, int y, int z));
291
292//inline void glutSpaceballButtonFunc(void (*)(int button, int state));
293
294//inline void glutButtonBoxFunc(void (*)(int button, int state));
295
296//inline void glutDialsFunc(void (*)(int dial, int value));
297
298//inline void glutTabletMotionFunc(void (*)(int x, int y));
299
300//inline void glutTabletButtonFunc(void (*)(int button, int state, int x, int y));
301
302inline void glutOverlayDisplayFunc(void (*f)()) {
303  glut_window->overlaydisplay = f;}
304
305//inline void glutWindowStatusFunc(void (*)(int state));
306//enum {GLUT_HIDDEN, GLUT_FULLY_RETAINED, GLUT_PARTIALLY_RETAINED,
307//      GLUT_FULLY_COVERED};
308
309//inline void glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
310
311//inline GLfloat glutGetColor(int ndx, int component);
312//#define GLUT_RED                      0
313//#define GLUT_GREEN                    1
314//#define GLUT_BLUE                     2
315
316//inline void glutCopyColormap(int win);
317
318// Warning: values are changed from Glut!
319// Also relies on the GL_ symbols having values greater than 100
320FL_GLUT_API int glutGet(GLenum type);
321enum {
322  GLUT_RETURN_ZERO = 0,
323  GLUT_WINDOW_X,
324  GLUT_WINDOW_Y,
325  GLUT_WINDOW_WIDTH,
326  GLUT_WINDOW_HEIGHT,
327  GLUT_WINDOW_PARENT,
328//GLUT_WINDOW_NUM_CHILDREN,
329//GLUT_WINDOW_CURSOR,
330  GLUT_SCREEN_WIDTH,
331  GLUT_SCREEN_HEIGHT,
332//GLUT_SCREEN_WIDTH_MM,
333//GLUT_SCREEN_HEIGHT_MM,
334  GLUT_MENU_NUM_ITEMS,
335  GLUT_DISPLAY_MODE_POSSIBLE,
336  GLUT_INIT_WINDOW_X,
337  GLUT_INIT_WINDOW_Y,
338  GLUT_INIT_WINDOW_WIDTH,
339  GLUT_INIT_WINDOW_HEIGHT,
340  GLUT_INIT_DISPLAY_MODE,
341//GLUT_ELAPSED_TIME,
342  GLUT_WINDOW_BUFFER_SIZE
343};
344
345#define GLUT_WINDOW_STENCIL_SIZE        GL_STENCIL_BITS
346#define GLUT_WINDOW_DEPTH_SIZE          GL_DEPTH_BITS
347#define GLUT_WINDOW_RED_SIZE            GL_RED_BITS
348#define GLUT_WINDOW_GREEN_SIZE          GL_GREEN_BITS
349#define GLUT_WINDOW_BLUE_SIZE           GL_BLUE_BITS
350#define GLUT_WINDOW_ALPHA_SIZE          GL_ALPHA_BITS
351#define GLUT_WINDOW_ACCUM_RED_SIZE      GL_ACCUM_RED_BITS
352#define GLUT_WINDOW_ACCUM_GREEN_SIZE    GL_ACCUM_GREEN_BITS
353#define GLUT_WINDOW_ACCUM_BLUE_SIZE     GL_ACCUM_BLUE_BITS
354#define GLUT_WINDOW_ACCUM_ALPHA_SIZE    GL_ACCUM_ALPHA_BITS
355#define GLUT_WINDOW_DOUBLEBUFFER        GL_DOUBLEBUFFER
356#define GLUT_WINDOW_RGBA                GL_RGBA
357#define GLUT_WINDOW_COLORMAP_SIZE       GL_INDEX_BITS
358#ifdef GL_SAMPLES_SGIS
359#define GLUT_WINDOW_NUM_SAMPLES         GL_SAMPLES_SGIS
360#else
361#define GLUT_WINDOW_NUM_SAMPLES         GLUT_RETURN_ZERO
362#endif
363#define GLUT_WINDOW_STEREO              GL_STEREO
364
365//int glutDeviceGet(GLenum type);
366//#define GLUT_HAS_KEYBOARD             600
367//#define GLUT_HAS_MOUSE                601
368//#define GLUT_HAS_SPACEBALL            602
369//#define GLUT_HAS_DIAL_AND_BUTTON_BOX  603
370//#define GLUT_HAS_TABLET               604
371//#define GLUT_NUM_MOUSE_BUTTONS        605
372//#define GLUT_NUM_SPACEBALL_BUTTONS    606
373//#define GLUT_NUM_BUTTON_BOX_BUTTONS   607
374//#define GLUT_NUM_DIALS                608
375//#define GLUT_NUM_TABLET_BUTTONS       609
376
377// WARNING: these values are different than Glut uses:
378enum {
379  GLUT_ACTIVE_SHIFT     = fltk::SHIFT,
380  GLUT_ACTIVE_CTRL      = fltk::CTRL,
381  GLUT_ACTIVE_ALT       = fltk::ALT
382};
383inline int glutGetModifiers() { return fltk::event_state() & (GLUT_ACTIVE_SHIFT | GLUT_ACTIVE_CTRL | GLUT_ACTIVE_ALT) ;}
384
385FL_GLUT_API int glutLayerGet(GLenum);
386#define GLUT_OVERLAY_POSSIBLE           800
387//#define GLUT_LAYER_IN_USE             801
388//#define GLUT_HAS_OVERLAY              802
389#define GLUT_TRANSPARENT_INDEX          803
390#define GLUT_NORMAL_DAMAGED             804
391#define GLUT_OVERLAY_DAMAGED            805
392
393//inline int glutVideoResizeGet(GLenum param);
394//#define GLUT_VIDEO_RESIZE_POSSIBLE    900
395//#define GLUT_VIDEO_RESIZE_IN_USE      901
396//#define GLUT_VIDEO_RESIZE_X_DELTA     902
397//#define GLUT_VIDEO_RESIZE_Y_DELTA     903
398//#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904
399//#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905
400//#define GLUT_VIDEO_RESIZE_X           906
401//#define GLUT_VIDEO_RESIZE_Y           907
402//#define GLUT_VIDEO_RESIZE_WIDTH       908
403//#define GLUT_VIDEO_RESIZE_HEIGHT      909
404
405//inline void glutSetupVideoResizing();
406
407//inline void glutStopVideoResizing();
408
409//inline void glutVideoResize(int x, int y, int width, int height);
410
411//inline void glutVideoPan(int x, int y, int width, int height);
412
413////////////////////////////////////////////////////////////////
414// Emulated Glut drawing functions:
415
416// Font argument must be a void* for compatability, so...
417extern FL_GLUT_API struct Glut_Bitmap_Font {fltk::Font* font; int size;}
418  glutBitmap9By15, glutBitmap8By13, glutBitmapTimesRoman10,
419  glutBitmapTimesRoman24, glutBitmapHelvetica10, glutBitmapHelvetica12,
420  glutBitmapHelvetica18;
421#define GLUT_BITMAP_9_BY_15             (&glutBitmap9By15)
422#define GLUT_BITMAP_8_BY_13             (&glutBitmap8By13)
423#define GLUT_BITMAP_TIMES_ROMAN_10      (&glutBitmapTimesRoman10)
424#define GLUT_BITMAP_TIMES_ROMAN_24      (&glutBitmapTimesRoman24)
425#define GLUT_BITMAP_HELVETICA_10        (&glutBitmapHelvetica10)
426#define GLUT_BITMAP_HELVETICA_12        (&glutBitmapHelvetica12)
427#define GLUT_BITMAP_HELVETICA_18        (&glutBitmapHelvetica18)
428
429FL_GLUT_API void glutBitmapCharacter(void *font, int character);
430FL_GLUT_API int glutBitmapWidth(void *font, int character);
431
432////////////////////////////////////////////////////////////////
433// Glut drawing functions.  These are NOT emulated but you can
434// link in the glut library to get them.  This assummes the object
435// files in Glut remain as they currently are so that there are
436// not symbol conflicts with the above.
437
438extern "C" {
439#ifndef APIENTRY
440# define APIENTRY
441#endif
442
443extern int APIENTRY glutExtensionSupported(const char *name);
444
445/* Stroke font constants (use these in GLUT program). */
446#ifdef _WIN32
447# define GLUT_STROKE_ROMAN              ((void*)0)
448# define GLUT_STROKE_MONO_ROMAN         ((void*)1)
449#else
450extern void *glutStrokeRoman;
451# define GLUT_STROKE_ROMAN              (&glutStrokeRoman)
452extern void *glutStrokeMonoRoman;
453# define GLUT_STROKE_MONO_ROMAN         (&glutStrokeMonoRoman)
454#endif
455
456/* GLUT font sub-API */
457extern void APIENTRY glutStrokeCharacter(void *font, int character);
458extern int APIENTRY glutStrokeWidth(void *font, int character);
459
460/* GLUT pre-built models sub-API */
461extern void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
462extern void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
463extern void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
464extern void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
465extern void APIENTRY glutWireCube(GLdouble size);
466extern void APIENTRY glutSolidCube(GLdouble size);
467extern void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
468extern void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
469extern void APIENTRY glutWireDodecahedron();
470extern void APIENTRY glutSolidDodecahedron();
471extern void APIENTRY glutWireTeapot(GLdouble size);
472extern void APIENTRY glutSolidTeapot(GLdouble size);
473extern void APIENTRY glutWireOctahedron();
474extern void APIENTRY glutSolidOctahedron();
475extern void APIENTRY glutWireTetrahedron();
476extern void APIENTRY glutSolidTetrahedron();
477extern void APIENTRY glutWireIcosahedron();
478extern void APIENTRY glutSolidIcosahedron();
479
480}
481
482#endif                  /* __glut_h__ */
483
484//
485// End of "$Id: glut.h 3961 2005-01-24 08:07:59Z spitzak $".
486//
Note: See TracBrowser for help on using the repository browser.