1/*
2 * Copyright 1994-1997 Mark Kilgard, All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * GPL licensing not permitted.
6 *
7 * Authors:
8 *      Mark Kilgard
9 */
10#ifndef __glutint_h__
11#define __glutint_h__
12
13
14#if defined(__CYGWIN32__)
15#include <sys/time.h>
16#endif
17
18#if defined(_WIN32)
19#include "glutwin32.h"
20#elif !(defined(__BEOS__) || defined(__HAIKU__))
21#ifdef __sgi
22#define SUPPORT_FORTRAN
23#endif
24#include <X11/Xlib.h>
25#include <X11/Xutil.h>
26#include <GL/glx.h>
27#endif
28
29#include <GL/glut.h>
30
31/* Non-Win32 platforms need APIENTRY defined to nothing
32   because all the GLUT routines have the APIENTRY prefix
33   to make Win32 happy. */
34#ifndef APIENTRY
35#define APIENTRY
36#endif
37
38#ifdef __vms
39#if ( __VMS_VER < 70000000 )
40struct timeval {
41  __int64 val;
42};
43extern int sys$gettim(struct timeval *);
44#else
45#include <time.h>
46#endif
47#else
48#include <sys/types.h>
49#if !defined(_WIN32)
50#include <sys/time.h>
51#else
52#include <winsock.h>
53#endif
54#endif
55#if defined(__vms) && ( __VMS_VER < 70000000 )
56
57/* For VMS6.2 or lower :
58   One TICK on VMS is 100 nanoseconds; 0.1 microseconds or
59   0.0001 milliseconds. This means that there are 0.01
60   ticks/ns, 10 ticks/us, 10,000 ticks/ms and 10,000,000
61   ticks/second. */
62
63#define TICKS_PER_MILLISECOND 10000
64#define TICKS_PER_SECOND      10000000
65
66#define GETTIMEOFDAY(_x) (void) sys$gettim (_x);
67
68#define ADD_TIME(dest, src1, src2) { \
69  (dest).val = (src1).val + (src2).val; \
70}
71
72#define TIMEDELTA(dest, src1, src2) { \
73  (dest).val = (src1).val - (src2).val; \
74}
75
76#define IS_AFTER(t1, t2) ((t2).val > (t1).val)
77
78#define IS_AT_OR_AFTER(t1, t2) ((t2).val >= (t1).val)
79
80#else
81#if defined(SVR4) && !defined(sun)  /* Sun claims SVR4, but
82                                       wants 2 args. */
83#define GETTIMEOFDAY(_x) gettimeofday(_x)
84#else
85#define GETTIMEOFDAY(_x) gettimeofday(_x, NULL)
86#endif
87#define ADD_TIME(dest, src1, src2) { \
88  if(((dest).tv_usec = \
89    (src1).tv_usec + (src2).tv_usec) >= 1000000) { \
90    (dest).tv_usec -= 1000000; \
91    (dest).tv_sec = (src1).tv_sec + (src2).tv_sec + 1; \
92  } else { \
93    (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
94    if(((dest).tv_sec >= 1) && (((dest).tv_usec <0))) { \
95      (dest).tv_sec --;(dest).tv_usec += 1000000; \
96    } \
97  } \
98}
99#define TIMEDELTA(dest, src1, src2) { \
100  if(((dest).tv_usec = (src1).tv_usec - (src2).tv_usec) < 0) { \
101    (dest).tv_usec += 1000000; \
102    (dest).tv_sec = (src1).tv_sec - (src2).tv_sec - 1; \
103  } else { \
104     (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
105  } \
106}
107#define IS_AFTER(t1, t2) \
108  (((t2).tv_sec > (t1).tv_sec) || \
109  (((t2).tv_sec == (t1).tv_sec) && \
110  ((t2).tv_usec > (t1).tv_usec)))
111#define IS_AT_OR_AFTER(t1, t2) \
112  (((t2).tv_sec > (t1).tv_sec) || \
113  (((t2).tv_sec == (t1).tv_sec) && \
114  ((t2).tv_usec >= (t1).tv_usec)))
115#endif
116
117#define IGNORE_IN_GAME_MODE() \
118  { if (__glutGameModeWindow) return; }
119
120/* BeOS doesn't need most of this file */
121#if (!defined(__BEOS__) && !defined(__HAIKU__))
122
123#define GLUT_WIND_IS_RGB(x)         (((x) & GLUT_INDEX) == 0)
124#define GLUT_WIND_IS_INDEX(x)       (((x) & GLUT_INDEX) != 0)
125#define GLUT_WIND_IS_SINGLE(x)      (((x) & GLUT_DOUBLE) == 0)
126#define GLUT_WIND_IS_DOUBLE(x)      (((x) & GLUT_DOUBLE) != 0)
127#define GLUT_WIND_HAS_ACCUM(x)      (((x) & GLUT_ACCUM) != 0)
128#define GLUT_WIND_HAS_ALPHA(x)      (((x) & GLUT_ALPHA) != 0)
129#define GLUT_WIND_HAS_DEPTH(x)      (((x) & GLUT_DEPTH) != 0)
130#define GLUT_WIND_HAS_STENCIL(x)    (((x) & GLUT_STENCIL) != 0)
131#define GLUT_WIND_IS_MULTISAMPLE(x) (((x) & GLUT_MULTISAMPLE) != 0)
132#define GLUT_WIND_IS_STEREO(x)      (((x) & GLUT_STEREO) != 0)
133#define GLUT_WIND_IS_LUMINANCE(x)   (((x) & GLUT_LUMINANCE) != 0)
134#define GLUT_MAP_WORK               (1 << 0)
135#define GLUT_EVENT_MASK_WORK        (1 << 1)
136#define GLUT_REDISPLAY_WORK         (1 << 2)
137#define GLUT_CONFIGURE_WORK         (1 << 3)
138#define GLUT_COLORMAP_WORK          (1 << 4)
139#define GLUT_DEVICE_MASK_WORK	    (1 << 5)
140#define GLUT_FINISH_WORK	    (1 << 6)
141#define GLUT_DEBUG_WORK		    (1 << 7)
142#define GLUT_DUMMY_WORK		    (1 << 8)
143#define GLUT_FULL_SCREEN_WORK       (1 << 9)
144#define GLUT_OVERLAY_REDISPLAY_WORK (1 << 10)
145#define GLUT_REPAIR_WORK            (1 << 11)
146#define GLUT_OVERLAY_REPAIR_WORK    (1 << 12)
147
148/* Frame buffer capability macros and types. */
149#define RGBA                    0
150#define BUFFER_SIZE             1
151#define DOUBLEBUFFER            2
152#define STEREO                  3
153#define AUX_BUFFERS             4
154#define RED_SIZE                5  /* Used as mask bit for
155                                      "color selected". */
156#define GREEN_SIZE              6
157#define BLUE_SIZE               7
158#define ALPHA_SIZE              8
159#define DEPTH_SIZE              9
160#define STENCIL_SIZE            10
161#define ACCUM_RED_SIZE          11  /* Used as mask bit for
162                                       "acc selected". */
163#define ACCUM_GREEN_SIZE        12
164#define ACCUM_BLUE_SIZE         13
165#define ACCUM_ALPHA_SIZE        14
166#define LEVEL                   15
167
168#define NUM_GLXCAPS             (LEVEL + 1)
169
170#define XVISUAL                 (NUM_GLXCAPS + 0)
171#define TRANSPARENT             (NUM_GLXCAPS + 1)
172#define SAMPLES                 (NUM_GLXCAPS + 2)
173#define XSTATICGRAY             (NUM_GLXCAPS + 3)  /* Used as
174                                                      mask bit
175                                                      for "any
176                                                      visual type
177                                                      selected". */
178#define XGRAYSCALE              (NUM_GLXCAPS + 4)
179#define XSTATICCOLOR            (NUM_GLXCAPS + 5)
180#define XPSEUDOCOLOR            (NUM_GLXCAPS + 6)
181#define XTRUECOLOR              (NUM_GLXCAPS + 7)
182#define XDIRECTCOLOR            (NUM_GLXCAPS + 8)
183#define SLOW                    (NUM_GLXCAPS + 9)
184#define CONFORMANT              (NUM_GLXCAPS + 10)
185
186#define NUM_CAPS                (NUM_GLXCAPS + 11)
187
188/* Frame buffer capablities that don't have a corresponding
189   FrameBufferMode entry.  These get used as mask bits. */
190#define NUM                     (NUM_CAPS + 0)
191#define RGBA_MODE               (NUM_CAPS + 1)
192#define CI_MODE                 (NUM_CAPS + 2)
193#define LUMINANCE_MODE		(NUM_CAPS + 3)
194
195#define NONE			0
196#define EQ			1
197#define NEQ			2
198#define LTE			3
199#define GTE			4
200#define GT			5
201#define LT			6
202#define MIN			7
203
204typedef struct _Criterion {
205  int capability;
206  int comparison;
207  int value;
208} Criterion;
209
210typedef struct _FrameBufferMode {
211  XVisualInfo *vi;
212#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
213
214  /* fbc is non-NULL when the XVisualInfo* is not OpenGL-capable
215     (ie, GLX_USE_GL is false), but the SGIX_fbconfig extension shows
216     the visual's fbconfig is OpenGL-capable.  The reason for this is typically
217     an RGBA luminance fbconfig such as 16-bit StaticGray that could
218     not be advertised as a GLX visual since StaticGray visuals are
219     required (by the GLX specification) to be color index.  The
220     SGIX_fbconfig allows StaticGray visuals to instead advertised as
221     fbconfigs that can provide RGBA luminance support. */
222
223  GLXFBConfigSGIX fbc;
224#endif
225  int valid;
226  int cap[NUM_CAPS];
227} FrameBufferMode;
228
229/* DisplayMode capability macros for game mode. */
230#define DM_WIDTH        0  /* "width" */
231#define DM_HEIGHT       1  /* "height" */
232#define DM_PIXEL_DEPTH  2  /* "bpp" (bits per pixel) */
233#define DM_HERTZ        3  /* "hertz" */
234#define DM_NUM          4  /* "num" */
235
236#define NUM_DM_CAPS     (DM_NUM+1)
237
238typedef struct _DisplayMode {
239#ifdef _WIN32
240  DEVMODE devmode;
241#else
242  /* XXX The X Window System does not have a standard
243     mechanism for display setting changes.  On SGI
244     systems, GLUT could use the XSGIvc (SGI X video
245     control extension).  Perhaps this can be done in
246     a future release of GLUT. */
247#endif
248  int valid;
249  int cap[NUM_DM_CAPS];
250} DisplayMode;
251
252#endif  /* BeOS */
253
254/* GLUT  function types */
255typedef void (*GLUTdisplayCB) (void);
256typedef void (*GLUTreshapeCB) (int, int);
257typedef void (*GLUTkeyboardCB) (unsigned char, int, int);
258typedef void (*GLUTmouseCB) (int, int, int, int);
259typedef void (*GLUTmotionCB) (int, int);
260typedef void (*GLUTpassiveCB) (int, int);
261typedef void (*GLUTentryCB) (int);
262typedef void (*GLUTvisibilityCB) (int);
263typedef void (*GLUTwindowStatusCB) (int);
264typedef void (*GLUTidleCB) (void);
265typedef void (*GLUTtimerCB) (int);
266typedef void (*GLUTmenuStateCB) (int);  /* DEPRICATED. */
267typedef void (*GLUTmenuStatusCB) (int, int, int);
268typedef void (*GLUTselectCB) (int);
269typedef void (*GLUTspecialCB) (int, int, int);
270typedef void (*GLUTspaceMotionCB) (int, int, int);
271typedef void (*GLUTspaceRotateCB) (int, int, int);
272typedef void (*GLUTspaceButtonCB) (int, int);
273typedef void (*GLUTdialsCB) (int, int);
274typedef void (*GLUTbuttonBoxCB) (int, int);
275typedef void (*GLUTtabletMotionCB) (int, int);
276typedef void (*GLUTtabletButtonCB) (int, int, int, int);
277typedef void (*GLUTjoystickCB) (unsigned int buttonMask, int x, int y, int z);
278#ifdef SUPPORT_FORTRAN
279typedef void (*GLUTdisplayFCB) (void);
280typedef void (*GLUTreshapeFCB) (int *, int *);
281/* NOTE the pressed key is int, not unsigned char for Fortran! */
282typedef void (*GLUTkeyboardFCB) (int *, int *, int *);
283typedef void (*GLUTmouseFCB) (int *, int *, int *, int *);
284typedef void (*GLUTmotionFCB) (int *, int *);
285typedef void (*GLUTpassiveFCB) (int *, int *);
286typedef void (*GLUTentryFCB) (int *);
287typedef void (*GLUTvisibilityFCB) (int *);
288typedef void (*GLUTwindowStatusFCB) (int *);
289typedef void (*GLUTidleFCB) (void);
290typedef void (*GLUTtimerFCB) (int *);
291typedef void (*GLUTmenuStateFCB) (int *);  /* DEPRICATED. */
292typedef void (*GLUTmenuStatusFCB) (int *, int *, int *);
293typedef void (*GLUTselectFCB) (int *);
294typedef void (*GLUTspecialFCB) (int *, int *, int *);
295typedef void (*GLUTspaceMotionFCB) (int *, int *, int *);
296typedef void (*GLUTspaceRotateFCB) (int *, int *, int *);
297typedef void (*GLUTspaceButtonFCB) (int *, int *);
298typedef void (*GLUTdialsFCB) (int *, int *);
299typedef void (*GLUTbuttonBoxFCB) (int *, int *);
300typedef void (*GLUTtabletMotionFCB) (int *, int *);
301typedef void (*GLUTtabletButtonFCB) (int *, int *, int *, int *);
302typedef void (*GLUTjoystickFCB) (unsigned int *buttonMask, int *x, int *y, int *z);
303#endif
304
305#if (!defined(__BEOS__) && !defined(__HAIKU__))
306
307typedef struct _GLUTcolorcell GLUTcolorcell;
308struct _GLUTcolorcell {
309  /* GLUT_RED, GLUT_GREEN, GLUT_BLUE */
310  GLfloat component[3];
311};
312
313typedef struct _GLUTcolormap GLUTcolormap;
314struct _GLUTcolormap {
315  Visual *visual;       /* visual of the colormap */
316  Colormap cmap;        /* X colormap ID */
317  int refcnt;           /* number of windows using colormap */
318  int size;             /* number of cells in colormap */
319  int transparent;      /* transparent pixel, or -1 if opaque */
320  GLUTcolorcell *cells; /* array of cells */
321  GLUTcolormap *next;   /* next colormap in list */
322};
323
324typedef struct _GLUTwindow GLUTwindow;
325typedef struct _GLUToverlay GLUToverlay;
326struct _GLUTwindow {
327  int num;              /* Small integer window id (0-based). */
328
329  /* Window system related state. */
330#if defined(_WIN32)
331  int pf;               /* Pixel format. */
332  HDC hdc;              /* Window's Win32 device context. */
333#endif
334  Window win;           /* X window for GLUT window */
335  GLXContext ctx;       /* OpenGL context GLUT glut window */
336  XVisualInfo *vis;     /* visual for window */
337  Bool visAlloced;      /* if vis needs deallocate on destroy */
338  Colormap cmap;        /* RGB colormap for window; None if CI */
339  GLUTcolormap *colormap;  /* colormap; NULL if RGBA */
340  GLUToverlay *overlay; /* overlay; NULL if no overlay */
341#if defined(_WIN32)
342  HDC renderDc;         /* Win32's device context for rendering. */
343#endif
344  Window renderWin;     /* X window for rendering (might be
345                           overlay) */
346  GLXContext renderCtx; /* OpenGL context for rendering (might
347                           be overlay) */
348  /* GLUT settable or visible window state. */
349  int width;            /* window width in pixels */
350  int height;           /* window height in pixels */
351  int cursor;           /* cursor name */
352  int visState;         /* visibility state (-1 is unknown) */
353  int shownState;       /* if window mapped */
354  int entryState;       /* entry state (-1 is unknown) */
355#define GLUT_MAX_MENUS              3
356
357  int menu[GLUT_MAX_MENUS];  /* attatched menu nums */
358  /* Window relationship state. */
359  GLUTwindow *parent;   /* parent window */
360  GLUTwindow *children; /* list of children */
361  GLUTwindow *siblings; /* list of siblings */
362  /* Misc. non-API visible (hidden) state. */
363  Bool treatAsSingle;   /* treat this window as single-buffered
364                           (it might be "fake" though) */
365  Bool forceReshape;    /* force reshape before display */
366#if !defined(_WIN32)
367  Bool isDirect;        /* if direct context (X11 only) */
368#endif
369  Bool usedSwapBuffers; /* if swap buffers used last display */
370  long eventMask;       /* mask of X events selected for */
371  int buttonUses;       /* number of button uses, ref cnt */
372  int tabletPos[2];     /* tablet position (-1 is invalid) */
373  /* Work list related state. */
374  unsigned int workMask;  /* mask of window work to be done */
375  GLUTwindow *prevWorkWin;  /* link list of windows to work on */
376  Bool desiredMapState; /* how to mapped window if on map work
377                           list */
378  Bool ignoreKeyRepeat;  /* if window ignores autorepeat */
379  int desiredConfMask;  /* mask of desired window configuration
380                         */
381  int desiredX;         /* desired X location */
382  int desiredY;         /* desired Y location */
383  int desiredWidth;     /* desired window width */
384  int desiredHeight;    /* desired window height */
385  int desiredStack;     /* desired window stack */
386  /* Per-window callbacks. */
387  GLUTdisplayCB display;  /* redraw */
388  GLUTreshapeCB reshape;  /* resize (width,height) */
389  GLUTmouseCB mouse;    /* mouse (button,state,x,y) */
390  GLUTmotionCB motion;  /* motion (x,y) */
391  GLUTpassiveCB passive;  /* passive motion (x,y) */
392  GLUTentryCB entry;    /* window entry/exit (state) */
393  GLUTkeyboardCB keyboard;  /* keyboard (ASCII,x,y) */
394  GLUTkeyboardCB keyboardUp;  /* keyboard up (ASCII,x,y) */
395  GLUTwindowStatusCB windowStatus;  /* window status */
396  GLUTvisibilityCB visibility;  /* visibility */
397  GLUTspecialCB special;  /* special key */
398  GLUTspecialCB specialUp;  /* special up key */
399  GLUTbuttonBoxCB buttonBox;  /* button box */
400  GLUTdialsCB dials;    /* dials */
401  GLUTspaceMotionCB spaceMotion;  /* Spaceball motion */
402  GLUTspaceRotateCB spaceRotate;  /* Spaceball rotate */
403  GLUTspaceButtonCB spaceButton;  /* Spaceball button */
404  GLUTtabletMotionCB tabletMotion;  /* tablet motion */
405  GLUTtabletButtonCB tabletButton;  /* tablet button */
406#ifdef _WIN32
407  GLUTjoystickCB joystick;  /* joystick */
408  int joyPollInterval; /* joystick polling interval */
409#endif
410#ifdef SUPPORT_FORTRAN
411  /* Special Fortran display  unneeded since no
412     parameters! */
413  GLUTreshapeFCB freshape;  /* Fortran reshape  */
414  GLUTmouseFCB fmouse;  /* Fortran mouse  */
415  GLUTmotionFCB fmotion;  /* Fortran motion  */
416  GLUTpassiveFCB fpassive;  /* Fortran passive  */
417  GLUTentryFCB fentry;  /* Fortran entry  */
418  GLUTkeyboardFCB fkeyboard;  /* Fortran keyboard  */
419  GLUTkeyboardFCB fkeyboardUp;  /* Fortran keyboard up */
420  GLUTwindowStatusFCB fwindowStatus;  /* Fortran visibility
421                                          */
422  GLUTvisibilityFCB fvisibility;  /* Fortran visibility
423                                      */
424  GLUTspecialFCB fspecial;  /* special key */
425  GLUTspecialFCB fspecialUp;  /* special key up */
426  GLUTbuttonBoxFCB fbuttonBox;  /* button box */
427  GLUTdialsFCB fdials;  /* dials */
428  GLUTspaceMotionFCB fspaceMotion;  /* Spaceball motion
429                                        */
430  GLUTspaceRotateFCB fspaceRotate;  /* Spaceball rotate
431                                        */
432  GLUTspaceButtonFCB fspaceButton;  /* Spaceball button
433                                        */
434  GLUTtabletMotionFCB ftabletMotion;  /* tablet motion
435                                       */
436  GLUTtabletButtonFCB ftabletButton;  /* tablet button
437                                       */
438#ifdef _WIN32
439  GLUTjoystickFCB fjoystick;  /* joystick */
440#endif
441#endif
442};
443
444struct _GLUToverlay {
445#if defined(_WIN32)
446  int pf;
447  HDC hdc;
448#endif
449  Window win;
450  GLXContext ctx;
451  XVisualInfo *vis;     /* visual for window */
452  Bool visAlloced;      /* if vis needs deallocate on destroy */
453  Colormap cmap;        /* RGB colormap for window; None if CI */
454  GLUTcolormap *colormap;  /* colormap; NULL if RGBA */
455  int shownState;       /* if overlay window mapped */
456  Bool treatAsSingle;   /* treat as single-buffered */
457#if !defined(_WIN32)
458  Bool isDirect;        /* if direct context */
459#endif
460  int transparentPixel; /* transparent pixel value */
461  GLUTdisplayCB display;  /* redraw  */
462  /* Special Fortran display  unneeded since no
463     parameters! */
464};
465
466typedef struct _GLUTstale GLUTstale;
467struct _GLUTstale {
468  GLUTwindow *window;
469  Window win;
470  GLUTstale *next;
471};
472
473extern GLUTstale *__glutStaleWindowList;
474
475#define GLUT_OVERLAY_EVENT_FILTER_MASK \
476  (ExposureMask | \
477  StructureNotifyMask | \
478  EnterWindowMask | \
479  LeaveWindowMask)
480#define GLUT_DONT_PROPAGATE_FILTER_MASK \
481  (ButtonReleaseMask | \
482  ButtonPressMask | \
483  KeyPressMask | \
484  KeyReleaseMask | \
485  PointerMotionMask | \
486  Button1MotionMask | \
487  Button2MotionMask | \
488  Button3MotionMask)
489#define GLUT_HACK_STOP_PROPAGATE_MASK \
490  (KeyPressMask | \
491  KeyReleaseMask)
492
493typedef struct _GLUTmenu GLUTmenu;
494typedef struct _GLUTmenuItem GLUTmenuItem;
495struct _GLUTmenu {
496  int id;               /* small integer menu id (0-based) */
497  Window win;           /* X window for the menu */
498  GLUTselectCB select;  /*  function of menu */
499  GLUTmenuItem *list;   /* list of menu entries */
500  int num;              /* number of entries */
501#if !defined(_WIN32)
502  Bool managed;         /* are the InputOnly windows size
503                           validated? */
504  Bool searched;	/* help detect menu loops */
505  int pixheight;        /* height of menu in pixels */
506  int pixwidth;         /* width of menu in pixels */
507#endif
508  int submenus;         /* number of submenu entries */
509  GLUTmenuItem *highlighted;  /* pointer to highlighted menu
510                                 entry, NULL not highlighted */
511  GLUTmenu *cascade;    /* currently cascading this menu  */
512  GLUTmenuItem *anchor; /* currently anchored to this entry */
513  int x;                /* current x origin relative to the
514                           root window */
515  int y;                /* current y origin relative to the
516                           root window */
517#ifdef SUPPORT_FORTRAN
518  GLUTselectFCB fselect;  /*  function of menu */
519#endif
520};
521
522struct _GLUTmenuItem {
523  Window win;           /* InputOnly X window for entry */
524  GLUTmenu *menu;       /* menu entry belongs to */
525  Bool isTrigger;       /* is a submenu trigger? */
526  int value;            /* value to return for selecting this
527                           entry; doubles as submenu id
528                           (0-base) if submenu trigger */
529#if defined(_WIN32)
530  UINT unique;          /* unique menu item id (Win32 only) */
531#endif
532  char *label;          /* __glutStrdup'ed label string */
533  int len;              /* length of label string */
534  int pixwidth;         /* width of X window in pixels */
535  GLUTmenuItem *next;   /* next menu entry on list for menu */
536};
537
538typedef struct _GLUTtimer GLUTtimer;
539struct _GLUTtimer {
540  GLUTtimer *next;      /* list of timers */
541  struct timeval timeout;  /* time to be called */
542  GLUTtimerCB func;     /* timer  (value) */
543  int value;            /*  return value */
544#ifdef SUPPORT_FORTRAN
545  GLUTtimerFCB ffunc;   /* Fortran timer  */
546#endif
547};
548
549typedef struct _GLUTeventParser GLUTeventParser;
550struct _GLUTeventParser {
551  int (*func) (XEvent *);
552  GLUTeventParser *next;
553};
554
555/* Declarations to implement glutFullScreen support with
556   mwm/4Dwm. */
557
558/* The following X property format is defined in Motif 1.1's
559   Xm/MwmUtils.h, but GLUT should not depend on that header
560   file. Note: Motif 1.2 expanded this structure with
561   uninteresting fields (to GLUT) so just stick with the
562   smaller Motif 1.1 structure. */
563typedef struct {
564#define MWM_HINTS_DECORATIONS   2
565  long flags;
566  long functions;
567  long decorations;
568  long input_mode;
569} MotifWmHints;
570
571/* Make current and buffer swap macros. */
572#ifdef _WIN32
573#define MAKE_CURRENT_LAYER(window)                                    \
574  {                                                                   \
575    HGLRC currentContext = wglGetCurrentContext();                    \
576    HDC currentDc = wglGetCurrentDC();                                \
577                                                                      \
578    if (currentContext != window->renderCtx                           \
579      || currentDc != window->renderDc) {                             \
580      wglMakeCurrent(window->renderDc, window->renderCtx);            \
581    }                                                                 \
582  }
583#define MAKE_CURRENT_WINDOW(window)                                   \
584  {                                                                   \
585    HGLRC currentContext = wglGetCurrentContext();                    \
586    HDC currentDc = wglGetCurrentDC();                                \
587                                                                      \
588    if (currentContext != window->ctx || currentDc != window->hdc) {  \
589      wglMakeCurrent(window->hdc, window->ctx);                       \
590    }                                                                 \
591  }
592#define MAKE_CURRENT_OVERLAY(overlay) \
593  wglMakeCurrent(overlay->hdc, overlay->ctx)
594#define UNMAKE_CURRENT() \
595  wglMakeCurrent(NULL, NULL)
596#define SWAP_BUFFERS_WINDOW(window) \
597  SwapBuffers(window->hdc)
598#define SWAP_BUFFERS_LAYER(window) \
599  SwapBuffers(window->renderDc)
600#else
601#define MAKE_CURRENT_LAYER(window) \
602  glXMakeCurrent(__glutDisplay, window->renderWin, window->renderCtx)
603#define MAKE_CURRENT_WINDOW(window) \
604  glXMakeCurrent(__glutDisplay, window->win, window->ctx)
605#define MAKE_CURRENT_OVERLAY(overlay) \
606  glXMakeCurrent(__glutDisplay, overlay->win, overlay->ctx)
607#define UNMAKE_CURRENT() \
608  glXMakeCurrent(__glutDisplay, None, NULL)
609#define SWAP_BUFFERS_WINDOW(window) \
610  glXSwapBuffers(__glutDisplay, window->win)
611#define SWAP_BUFFERS_LAYER(window) \
612  glXSwapBuffers(__glutDisplay, window->renderWin)
613#endif
614
615/* private variables from glut_event.c */
616extern GLUTwindow *__glutWindowWorkList;
617extern int __glutWindowDamaged;
618#ifdef SUPPORT_FORTRAN
619extern GLUTtimer *__glutTimerList;
620extern GLUTtimer *__glutNewTimer;
621#endif
622extern GLUTmenu *__glutMappedMenu;
623
624extern void (*__glutUpdateInputDeviceMaskFunc) (GLUTwindow *);
625#if !defined(_WIN32)
626extern void (*__glutMenuItemEnterOrLeave)(GLUTmenuItem * item,
627  int num, int type);
628extern void (*__glutFinishMenu)(Window win, int x, int y);
629extern void (*__glutPaintMenu)(GLUTmenu * menu);
630extern void (*__glutStartMenu)(GLUTmenu * menu,
631  GLUTwindow * window, int x, int y, int x_win, int y_win);
632extern GLUTmenu * (*__glutGetMenuByNum)(int menunum);
633extern GLUTmenuItem * (*__glutGetMenuItem)(GLUTmenu * menu,
634  Window win, int *which);
635extern GLUTmenu * (*__glutGetMenu)(Window win);
636#endif
637
638/* private variables from glut_init.c */
639extern Atom __glutWMDeleteWindow;
640extern Display *__glutDisplay;
641extern unsigned int __glutDisplayMode;
642extern char *__glutDisplayString;
643extern XVisualInfo *(*__glutDetermineVisualFromString) (char *string, Bool * treatAsSingle,
644  Criterion * requiredCriteria, int nRequired, int requiredMask, void **fbc);
645extern GLboolean __glutDebug;
646extern GLboolean __glutForceDirect;
647extern GLboolean __glutIconic;
648extern GLboolean __glutTryDirect;
649extern Window __glutRoot;
650extern XSizeHints __glutSizeHints;
651extern char **__glutArgv;
652#endif  /* BeOS */
653extern char *__glutProgramName;
654#if (!defined(__BEOS__) && !defined(__HAIKU__))
655extern int __glutArgc;
656extern int __glutConnectionFD;
657extern int __glutInitHeight;
658extern int __glutInitWidth;
659extern int __glutInitX;
660extern int __glutInitY;
661extern int __glutScreen;
662extern int __glutScreenHeight;
663extern int __glutScreenWidth;
664extern Atom __glutMotifHints;
665extern unsigned int __glutModifierMask;
666
667/* private variables from glut_menu.c */
668extern GLUTmenuItem *__glutItemSelected;
669extern GLUTmenu **__glutMenuList;
670extern void (*__glutMenuStatusFunc) (int, int, int);
671extern void __glutMenuModificationError(void);
672extern void __glutSetMenuItem(GLUTmenuItem * item,
673  const char *label, int value, Bool isTrigger);
674
675/* private variables from glut_win.c */
676extern GLUTwindow **__glutWindowList;
677extern GLUTwindow *__glutCurrentWindow;
678extern GLUTwindow *__glutMenuWindow;
679extern GLUTmenu *__glutCurrentMenu;
680extern int __glutWindowListSize;
681extern void (*__glutFreeOverlayFunc) (GLUToverlay *);
682extern XVisualInfo *__glutDetermineWindowVisual(Bool * treatAsSingle,
683  Bool * visAlloced, void **fbc);
684
685/* private variables from glut_mesa.c */
686extern int __glutMesaSwapHackSupport;
687
688/* private variables from glut_gamemode.c */
689extern GLUTwindow *__glutGameModeWindow;
690
691/* private routines from glut_cindex.c */
692extern GLUTcolormap * __glutAssociateNewColormap(XVisualInfo * vis);
693extern void __glutFreeColormap(GLUTcolormap *);
694
695/* private routines from glut_cmap.c */
696extern void __glutSetupColormap(
697  XVisualInfo * vi,
698  GLUTcolormap ** colormap,
699  Colormap * cmap);
700#if !defined(_WIN32)
701extern void __glutEstablishColormapsProperty(
702  GLUTwindow * window);
703extern GLUTwindow *__glutToplevelOf(GLUTwindow * window);
704#endif
705
706/* private routines from glut_cursor.c */
707extern void __glutSetCursor(GLUTwindow *window);
708
709/* private routines from glut_event.c */
710extern void __glutPutOnWorkList(GLUTwindow * window,
711  int work_mask);
712extern void __glutRegisterEventParser(GLUTeventParser * parser);
713extern void __glutPostRedisplay(GLUTwindow * window, int layerMask);
714
715/* private routines from glut_init.c */
716#if !defined(_WIN32)
717extern void __glutOpenXConnection(char *display);
718#else
719extern void __glutOpenWin32Connection(char *display);
720#endif
721extern void __glutInitTime(struct timeval *beginning);
722
723/* private routines for glut_menu.c (or win32_menu.c) */
724#if defined(_WIN32)
725extern GLUTmenu *__glutGetMenu(Window win);
726extern GLUTmenu *__glutGetMenuByNum(int menunum);
727extern GLUTmenuItem *__glutGetMenuItem(GLUTmenu * menu,
728  Window win, int *which);
729extern void __glutStartMenu(GLUTmenu * menu,
730  GLUTwindow * window, int x, int y, int x_win, int y_win);
731extern void __glutFinishMenu(Window win, int x, int y);
732#endif
733extern void __glutSetMenu(GLUTmenu * menu);
734
735#endif  /* BeOS */
736#ifdef __cplusplus
737extern "C" {
738#endif
739/* private routines from glut_util.c */
740extern char * __glutStrdup(const char *string);
741extern void __glutWarning(const char *format,...);
742extern void __glutFatalError(const char *format,...);
743extern void __glutFatalUsage(const char *format,...);
744#ifdef __cplusplus
745}
746#endif
747#if (!defined(__BEOS__) && !defined(__HAIKU__))
748
749/* private routines from glut_win.c */
750extern GLUTwindow *__glutGetWindow(Window win);
751extern void __glutChangeWindowEventMask(long mask, Bool add);
752extern XVisualInfo *__glutDetermineVisual(
753  unsigned int mode,
754  Bool * fakeSingle,
755  XVisualInfo * (getVisualInfo) (unsigned int));
756extern XVisualInfo *__glutGetVisualInfo(unsigned int mode);
757extern void __glutSetWindow(GLUTwindow * window);
758extern void __glutReshapeFunc(GLUTreshapeCB reshapeFunc,
759  int callingConvention);
760extern void  __glutDefaultReshape(int, int);
761extern GLUTwindow *__glutCreateWindow(
762  GLUTwindow * parent,
763  int x, int y, int width, int height, int gamemode);
764extern void __glutDestroyWindow(
765  GLUTwindow * window,
766  GLUTwindow * initialWindow);
767
768#if !defined(_WIN32)
769/* private routines from glut_glxext.c */
770extern int __glutIsSupportedByGLX(char *);
771#endif
772
773/* private routines from glut_input.c */
774extern void  __glutUpdateInputDeviceMask(GLUTwindow * window);
775
776/* private routines from glut_mesa.c */
777extern void __glutDetermineMesaSwapHackSupport(void);
778
779/* private routines from glut_gameglut.c */
780extern void __glutCloseDownGameMode(void);
781
782#if defined(_WIN32)
783/* private routines from win32_*.c */
784extern LONG WINAPI __glutWindowProc(HWND win, UINT msg, WPARAM w, LPARAM l);
785extern HDC XHDC;
786#endif
787
788#else  /* BeOS */
789/* BeOS specific C++ function prototypes */
790#ifdef __cplusplus
791
792#include <SupportDefs.h>
793
794/* private routines from glutInit.cpp */
795void __glutInitTime(bigtime_t *beginning);
796void __glutInit();
797void __glutExitCleanup();
798
799/* private routines from glutMenu.cpp */
800class GlutMenu;         // avoid including glutMenu.h
801GlutMenu *__glutGetMenuByNum(int menunum);
802
803/* private routines from glutWindow.cpp */
804int __glutConvertDisplayMode(unsigned long *options);
805void __glutDefaultReshape(int width, int height);
806class GlutWindow;       // avoid including glutWindow.h in every source file
807void __glutSetWindow(GlutWindow * window);
808void __glutDestroyAllWindows();
809
810/* private routines from glutDstr.cpp */
811int __glutConvertDisplayModeFromString(unsigned long *options);
812
813/* private routines from glutCursor.cpp */
814void __glutSetCursor(int cursor);
815
816#endif /* __cplusplus */
817#endif  /* BeOS */
818
819#endif /* __glutint_h__ */
820