69401d0f89931bdd8570f75274daaf825ff27841
[freeglut] / src / fg_internal.h
1 /*
2  * fg_internal.h
3  *
4  * The freeglut library private include file.
5  *
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8  * Creation date: Thu Dec 2 1999
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #ifndef  FREEGLUT_INTERNAL_H
29 #define  FREEGLUT_INTERNAL_H
30
31 #ifdef HAVE_CONFIG_H
32 #    include "config.h"
33 #endif
34
35 #include "fg_version.h"
36
37 /* Freeglut is intended to function under all Unix/X11 and Win32 platforms. */
38 /* XXX: Don't all MS-Windows compilers (except Cygwin) have _WIN32 defined?
39  * XXX: If so, remove the first set of defined()'s below.
40  */
41 #if !defined(TARGET_HOST_POSIX_X11) && !defined(TARGET_HOST_MS_WINDOWS) && !defined(TARGET_HOST_MAC_OSX) && !defined(TARGET_HOST_SOLARIS)
42 #if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__) \
43     || defined(_WIN32) || defined(_WIN32_WCE) \
44     || ( defined(__CYGWIN__) && defined(X_DISPLAY_MISSING) )
45 #   define  TARGET_HOST_MS_WINDOWS 1
46
47 #elif defined (__ANDROID__)
48 #   define  TARGET_HOST_ANDROID  1
49
50 #elif defined (__QNXNTO__) || defined (__PLAYBOOK__)
51 #   define  TARGET_HOST_BLACKBERRY  1
52
53 #elif defined(__posix__) || defined(__unix__) || defined(__linux__) || defined(__sun)
54 #   if defined(FREEGLUT_WAYLAND)
55 #      define  TARGET_HOST_POSIX_WAYLAND  1
56 #   else
57 #      define  TARGET_HOST_POSIX_X11  1
58 #   endif
59
60 #elif defined(__APPLE__)
61 /* This is a placeholder until we get native OSX support ironed out -- JFF 11/18/09 */
62 #   define  TARGET_HOST_POSIX_X11  1
63 /* #   define  TARGET_HOST_MAC_OSX    1 */
64
65 #else
66 #   error "Unrecognized target host!"
67
68 #endif
69 #endif
70
71 /* Detect both SunPro and gcc compilers on Sun Solaris */
72 #if defined (__SVR4) && defined (__sun)
73 #   define TARGET_HOST_SOLARIS 1
74 #endif
75
76 #ifndef TARGET_HOST_MS_WINDOWS
77 #   define  TARGET_HOST_MS_WINDOWS     0
78 #endif
79
80 #ifndef TARGET_HOST_ANDROID
81 #   define  TARGET_HOST_ANDROID        0
82 #endif
83
84 #ifndef TARGET_HOST_BLACKBERRY
85 #   define  TARGET_HOST_BLACKBERRY     0
86 #endif
87
88 #ifndef  TARGET_HOST_POSIX_WAYLAND
89 #   define  TARGET_HOST_POSIX_WAYLAND  0
90 #endif
91
92 #ifndef  TARGET_HOST_POSIX_X11
93 #   define  TARGET_HOST_POSIX_X11      0
94 #endif
95
96 #ifndef  TARGET_HOST_MAC_OSX
97 #   define  TARGET_HOST_MAC_OSX        0
98 #endif
99
100 #ifndef  TARGET_HOST_SOLARIS
101 #   define  TARGET_HOST_SOLARIS        0
102 #endif
103
104 /* -- FIXED CONFIGURATION LIMITS ------------------------------------------- */
105
106 #define  FREEGLUT_MAX_MENUS            3
107
108 /* These files should be available on every platform. */
109 #include <stdio.h>
110 #include <string.h>
111 #include <math.h>
112 #include <stdlib.h>
113 #include <stdarg.h>
114
115 /* These are included based on autoconf directives. */
116 #ifdef HAVE_SYS_TYPES_H
117 #    include <sys/types.h>
118 #endif
119 #ifdef HAVE_UNISTD_H
120 #    include <unistd.h>
121 #endif
122 #ifdef TIME_WITH_SYS_TIME
123 #    include <sys/time.h>
124 #    include <time.h>
125 #elif defined(HAVE_SYS_TIME_H)
126 #    include <sys/time.h>
127 #else
128 #    include <time.h>
129 #endif
130
131 /* -- AUTOCONF HACKS --------------------------------------------------------*/
132
133 /* XXX: Update autoconf to avoid these.
134  * XXX: Are non-POSIX platforms intended not to use autoconf?
135  * If so, perhaps there should be a config_guess.h for them. Alternatively,
136  * config guesses could be placed above, just after the config.h exclusion.
137  */
138 #if defined(__FreeBSD__) || defined(__NetBSD__)
139 #    define HAVE_USB_JS 1
140 #    if defined(__NetBSD__) || ( defined(__FreeBSD__) && __FreeBSD_version >= 500000)
141 #        define HAVE_USBHID_H 1
142 #    endif
143 #endif
144
145 #if defined(_MSC_VER) || defined(__WATCOMC__)
146 /* strdup() is non-standard, for all but POSIX-2001 */
147 #define strdup   _strdup
148 #endif
149
150 /* M_PI is non-standard (defined by BSD, not ISO-C) */
151 #ifndef M_PI
152 #    define  M_PI  3.14159265358979323846
153 #endif
154
155 #ifdef HAVE_STDBOOL_H
156 #    include <stdbool.h>
157 #    ifndef TRUE
158 #        define TRUE true
159 #    endif
160 #    ifndef FALSE
161 #        define FALSE false
162 #    endif
163 #else
164 #    ifndef TRUE
165 #        define  TRUE  1
166 #    endif
167 #    ifndef FALSE
168 #        define  FALSE  0
169 #    endif
170 #endif
171
172 /* General defines */
173 #define INVALID_MODIFIERS 0xffffffff
174
175 /* FreeGLUT internal time type */
176 #if defined(HAVE_STDINT_H)
177 #   include <stdint.h>
178     typedef uint64_t fg_time_t;
179 #elif defined(HAVE_INTTYPES_H)
180 #   include <inttypes.h>
181     typedef uint64_t fg_time_t;
182 #elif defined(HAVE_U__INT64)
183     typedef unsigned __int64 fg_time_t;
184 #elif defined(HAVE_ULONG_LONG)
185     typedef unsigned long long fg_time_t;
186 #else
187     typedef unsigned long fg_time_t;
188 #endif
189
190 #ifndef __fg_unused
191 # ifdef __GNUC__
192 #  define __fg_unused __attribute__((unused))
193 # else
194 #  define __fg_unused
195 # endif
196 #endif
197
198 /* Platform-specific includes */
199 #if TARGET_HOST_POSIX_WAYLAND
200 #include "wayland/fg_internal_wl.h"
201 #endif
202 #if TARGET_HOST_POSIX_X11
203 #include "x11/fg_internal_x11.h"
204 #endif
205 #if TARGET_HOST_MS_WINDOWS
206 #include "mswin/fg_internal_mswin.h"
207 #endif
208 #if TARGET_HOST_ANDROID
209 #include "android/fg_internal_android.h"
210 #endif
211 #if TARGET_HOST_BLACKBERRY
212 #include "blackberry/fg_internal_blackberry.h"
213 #endif
214
215
216 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
217
218 /* Freeglut callbacks type definitions */
219 typedef void* FGCBUserData;
220
221 typedef void (* FGCBDisplay         )( void );
222 typedef void (* FGCBDisplayUC       )( FGCBUserData );
223 typedef void (* FGCBReshape         )( int, int );
224 typedef void (* FGCBReshapeUC       )( int, int, FGCBUserData );
225 typedef void (* FGCBPosition        )( int, int );
226 typedef void (* FGCBPositionUC      )( int, int, FGCBUserData );
227 typedef void (* FGCBVisibility      )( int );
228 typedef void (* FGCBVisibilityUC    )( int, FGCBUserData );
229 typedef void (* FGCBKeyboard        )( unsigned char, int, int );
230 typedef void (* FGCBKeyboardUC      )( unsigned char, int, int, FGCBUserData );
231 typedef void (* FGCBKeyboardUp      )( unsigned char, int, int );
232 typedef void (* FGCBKeyboardUpUC    )( unsigned char, int, int, FGCBUserData );
233 typedef void (* FGCBSpecial         )( int, int, int );
234 typedef void (* FGCBSpecialUC       )( int, int, int, FGCBUserData );
235 typedef void (* FGCBSpecialUp       )( int, int, int );
236 typedef void (* FGCBSpecialUpUC     )( int, int, int, FGCBUserData );
237 typedef void (* FGCBMouse           )( int, int, int, int );
238 typedef void (* FGCBMouseUC         )( int, int, int, int, FGCBUserData );
239 typedef void (* FGCBMouseWheel      )( int, int, int, int );
240 typedef void (* FGCBMouseWheelUC    )( int, int, int, int, FGCBUserData );
241 typedef void (* FGCBMotion          )( int, int );
242 typedef void (* FGCBMotionUC        )( int, int, FGCBUserData );
243 typedef void (* FGCBPassive         )( int, int );
244 typedef void (* FGCBPassiveUC       )( int, int, FGCBUserData );
245 typedef void (* FGCBEntry           )( int );
246 typedef void (* FGCBEntryUC         )( int, FGCBUserData );
247 typedef void (* FGCBWindowStatus    )( int );
248 typedef void (* FGCBWindowStatusUC  )( int, FGCBUserData );
249 typedef void (* FGCBJoystick        )( unsigned int, int, int, int );
250 typedef void (* FGCBJoystickUC      )( unsigned int, int, int, int, FGCBUserData );
251 typedef void (* FGCBOverlayDisplay  )( void );
252 typedef void (* FGCBOverlayDisplayUC)( FGCBUserData );
253 typedef void (* FGCBSpaceMotion     )( int, int, int );
254 typedef void (* FGCBSpaceMotionUC   )( int, int, int, FGCBUserData );
255 typedef void (* FGCBSpaceRotation   )( int, int, int );
256 typedef void (* FGCBSpaceRotationUC )( int, int, int, FGCBUserData );
257 typedef void (* FGCBSpaceButton     )( int, int );
258 typedef void (* FGCBSpaceButtonUC   )( int, int, FGCBUserData );
259 typedef void (* FGCBDials           )( int, int );
260 typedef void (* FGCBDialsUC         )( int, int, FGCBUserData );
261 typedef void (* FGCBButtonBox       )( int, int );
262 typedef void (* FGCBButtonBoxUC     )( int, int, FGCBUserData );
263 typedef void (* FGCBTabletMotion    )( int, int );
264 typedef void (* FGCBTabletMotionUC  )( int, int, FGCBUserData );
265 typedef void (* FGCBTabletButton    )( int, int, int, int );
266 typedef void (* FGCBTabletButtonUC  )( int, int, int, int, FGCBUserData );
267 typedef void (* FGCBDestroy         )( void );    /* Used for both window and menu destroy callbacks */
268 typedef void (* FGCBDestroyUC       )( FGCBUserData );
269
270 typedef void (* FGCBMultiEntry      )( int, int );
271 typedef void (* FGCBMultiEntryUC    )( int, int, FGCBUserData );
272 typedef void (* FGCBMultiButton     )( int, int, int, int, int );
273 typedef void (* FGCBMultiButtonUC   )( int, int, int, int, int, FGCBUserData );
274 typedef void (* FGCBMultiMotion     )( int, int, int );
275 typedef void (* FGCBMultiMotionUC   )( int, int, int, FGCBUserData );
276 typedef void (* FGCBMultiPassive    )( int, int, int );
277 typedef void (* FGCBMultiPassiveUC  )( int, int, int, FGCBUserData );
278
279 typedef void (* FGCBInitContext     )( void );
280 typedef void (* FGCBInitContextUC   )( FGCBUserData );
281 typedef void (* FGCBAppStatus       )( int );
282 typedef void (* FGCBAppStatusUC     )( int, FGCBUserData );
283
284 /* The global callbacks type definitions */
285 typedef void (* FGCBIdle            )( void ); \
286 typedef void (* FGCBIdleUC          )( FGCBUserData );
287 typedef void (* FGCBTimer           )( int );
288 typedef void (* FGCBTimerUC         )( int, FGCBUserData );
289 typedef void (* FGCBMenuState       )( int );
290 typedef void (* FGCBMenuStatus      )( int, int, int );
291 typedef void (* FGCBMenuStatusUC    )( int, int, int, FGCBUserData );
292
293 /* The callback used when creating/using menus */
294 typedef void (* FGCBMenu            )( int );
295 typedef void (* FGCBMenuUC          )( int, FGCBUserData );
296
297 /* The FreeGLUT error/warning handler type definition */
298 typedef void (* FGError             )( const char *fmt, va_list ap );
299 typedef void (* FGErrorUC           )( const char *fmt, va_list ap, FGCBUserData userData );
300 typedef void (* FGWarning           )( const char *fmt, va_list ap );
301 typedef void (* FGWarningUC         )( const char *fmt, va_list ap, FGCBUserData userData );
302
303
304 /* A list structure */
305 typedef struct tagSFG_List SFG_List;
306 struct tagSFG_List
307 {
308     void *First;
309     void *Last;
310 };
311
312 /* A list node structure */
313 typedef struct tagSFG_Node SFG_Node;
314 struct tagSFG_Node
315 {
316     void *Next;
317     void *Prev;
318 };
319
320 /* A helper structure holding two ints and a boolean */
321 typedef struct tagSFG_XYUse SFG_XYUse;
322 struct tagSFG_XYUse
323 {
324     GLint           X, Y;               /* The two integers...               */
325     GLboolean       Use;                /* ...and a single boolean.          */
326 };
327
328 /*
329  * An enumeration containing the state of the GLUT execution:
330  * initializing, running, or stopping
331  */
332 typedef enum
333 {
334   GLUT_EXEC_STATE_INIT,
335   GLUT_EXEC_STATE_RUNNING,
336   GLUT_EXEC_STATE_STOP
337 } fgExecutionState ;
338
339 /* This structure holds different freeglut settings */
340 typedef struct tagSFG_State SFG_State;
341 struct tagSFG_State
342 {
343     SFG_XYUse        Position;             /* The default windows' position  */
344     SFG_XYUse        Size;                 /* The default windows' size      */
345     unsigned int     DisplayMode;          /* Display mode for new windows   */
346
347     GLboolean        Initialised;          /* freeglut has been initialised  */
348
349     int              DirectContext;        /* Direct rendering state         */
350
351     GLboolean        ForceIconic;          /* New top windows are iconified  */
352     GLboolean        UseCurrentContext;    /* New windows share with current */
353
354     GLboolean        GLDebugSwitch;        /* OpenGL state debugging switch  */
355     GLboolean        XSyncSwitch;          /* X11 sync protocol switch       */
356
357     int              KeyRepeat;            /* Global key repeat mode.        */
358     int              Modifiers;            /* Current ALT/SHIFT/CTRL state   */
359
360     GLuint           FPSInterval;          /* Interval between FPS printfs   */
361     GLuint           SwapCount;            /* Count of glutSwapBuffer calls  */
362     GLuint           SwapTime;             /* Time of last SwapBuffers       */
363
364     fg_time_t        Time;                 /* Time that glutInit was called  */
365     SFG_List         Timers;               /* The freeglut timer hooks       */
366     SFG_List         FreeTimers;           /* The unused timer hooks         */
367
368     FGCBIdleUC       IdleCallback;         /* The global idle callback       */
369     FGCBUserData     IdleCallbackData;     /* The global idle callback data  */
370
371     int              ActiveMenus;          /* Num. of currently active menus */
372     FGCBMenuState    MenuStateCallback;    /* Menu callbacks are global      */
373     FGCBMenuStatusUC MenuStatusCallback;
374     FGCBUserData     MenuStatusCallbackData;
375     void*            MenuFont;             /* Font to be used for newly created menus */
376
377     SFG_XYUse        GameModeSize;         /* Game mode screen's dimensions  */
378     int              GameModeDepth;        /* The pixel depth for game mode  */
379     int              GameModeRefresh;      /* The refresh rate for game mode */
380
381     int              ActionOnWindowClose;  /* Action when user closes window  */
382
383     fgExecutionState ExecState;            /* Used for GLUT termination       */
384     char            *ProgramName;          /* Name of the invoking program    */
385     GLboolean        JoysticksInitialised; /* Only initialize if application calls for them */
386     int              NumActiveJoysticks;   /* Number of active joysticks (callback defined and positive pollrate) -- if zero, don't poll joysticks */
387     GLboolean        InputDevsInitialised; /* Only initialize if application calls for them */
388
389         int              MouseWheelTicks;      /* Number of ticks the mouse wheel has turned */
390
391     int              AuxiliaryBufferNumber;/* Number of auxiliary buffers */
392     int              SampleNumber;         /*  Number of samples per pixel  */
393
394     GLboolean        SkipStaleMotion;      /* skip stale motion events */
395
396     GLboolean        StrokeFontDrawJoinDots;/* Draw dots between line segments of stroke fonts? */
397     GLboolean        AllowNegativeWindowPosition; /* GLUT, by default, doesn't allow negative window positions. Enable it? */
398
399     int              MajorVersion;         /* Major OpenGL context version  */
400     int              MinorVersion;         /* Minor OpenGL context version  */
401     int              ContextFlags;         /* OpenGL context flags          */
402     int              ContextProfile;       /* OpenGL context profile        */
403     int              HasOpenGL20;          /* fgInitGL2 could find all OpenGL 2.0 functions */
404     FGErrorUC        ErrorFunc;            /* User defined error handler    */
405     FGCBUserData     ErrorFuncData;        /* User defined error handler user data */
406     FGWarningUC      WarningFunc;          /* User defined warning handler  */
407     FGCBUserData     WarningFuncData;      /* User defined warning handler user data */
408 };
409
410 /* The structure used by display initialization in fg_init.c */
411 typedef struct tagSFG_Display SFG_Display;
412 struct tagSFG_Display
413 {
414         SFG_PlatformDisplay pDisplay;
415
416     int             ScreenWidth;        /* The screen's width in pixels      */
417     int             ScreenHeight;       /* The screen's height in pixels     */
418     int             ScreenWidthMM;      /* The screen's width in milimeters  */
419     int             ScreenHeightMM;     /* The screen's height in milimeters */
420 };
421
422
423 /* The user can create any number of timer hooks */
424 typedef struct tagSFG_Timer SFG_Timer;
425 struct tagSFG_Timer
426 {
427     SFG_Node        Node;
428     int             ID;                 /* The timer ID integer              */
429     FGCBTimerUC     Callback;           /* The timer callback                */
430     FGCBUserData    CallbackData;       /* The timer callback user data      */
431     fg_time_t       TriggerTime;        /* The timer trigger time            */
432 };
433
434 /*
435  * A window and its OpenGL context. The contents of this structure
436  * are highly dependent on the target operating system we aim at...
437  */
438 typedef struct tagSFG_Context SFG_Context;
439 struct tagSFG_Context
440 {
441     SFG_WindowHandleType  Handle;    /* The window's handle                 */
442     SFG_WindowContextType Context;   /* The window's OpenGL/WGL context     */
443
444         SFG_PlatformContext pContext;    /* The window's FBConfig (X11) or device context (Windows) */
445
446     int             DoubleBuffered;  /* Treat the window as double-buffered */
447
448     /* When drawing geometry to vertex attribute buffers, user specifies
449      * the attribute indices for vertices, normals and/or texture coords
450      * to freeglut. Those are stored here
451      */
452     GLint           attribute_v_coord;
453     GLint           attribute_v_normal;
454     GLint           attribute_v_texture;
455 };
456
457
458 /*
459  * Bitmasks indicating the different kinds of
460  * actions that can be scheduled for a window.
461  */
462 #define GLUT_INIT_WORK        (1<<0)
463 #define GLUT_VISIBILITY_WORK  (1<<1)
464 #define GLUT_POSITION_WORK    (1<<2)
465 #define GLUT_SIZE_WORK        (1<<3)
466 #define GLUT_ZORDER_WORK      (1<<4)
467 #define GLUT_FULL_SCREEN_WORK (1<<5)
468 #define GLUT_DISPLAY_WORK     (1<<6)
469
470 /*
471  * An enumeration containing the desired mapping state of a window
472  */
473 typedef enum
474 {
475   DesireHiddenState,
476   DesireIconicState,
477   DesireNormalState
478 } fgDesiredVisibility ;
479
480 /*
481  *  There is considerable confusion about the "right thing to
482  *  do" concerning window  size and position.  GLUT itself is
483  *  not consistent between Windows and UNIX/X11; since
484  *  platform independence is a virtue for "freeglut", we
485  *  decided to break with GLUT's behaviour.
486  *
487  *  Under UNIX/X11, it is apparently not possible to get the
488  *  window border sizes in order to subtract them off the
489  *  window's initial position until some time after the window
490  *  has been created.  Therefore we decided on the following
491  *  behaviour, both under Windows and under UNIX/X11:
492  *  - When you create a window with position (x,y) and size
493  *    (w,h), the upper left hand corner of the outside of the
494  *    window is at (x,y) and the size of the drawable area is
495  *    (w,h).
496  *  - When you query the size and position of the window--as
497  *    is happening here for Windows--"freeglut" will return
498  *    the size of the drawable area--the (w,h) that you
499  *    specified when you created the window--and the coordinates
500  *    of the upper left hand corner of the drawable area, i.e.
501  *    of the client rect--which is NOT the (x,y) you specified.
502  */
503 typedef struct tagSFG_WindowState SFG_WindowState;
504 struct tagSFG_WindowState   /* as per notes above, sizes always refer to the client area (thus without the window decorations) */
505 {
506     /* window state - size, position, look */
507     int             Xpos;               /* Window's top-left of client area, X-coordinate */
508     int             Ypos;               /* Window's top-left of client area, Y-coordinate */
509     int             Width;              /* Window's width in pixels          */
510     int             Height;             /* The same about the height         */
511     GLboolean       Visible;            /* Is the window visible now? Not using fgVisibilityState as we only care if visible or not */
512     int             Cursor;             /* The currently selected cursor style */
513     GLboolean       IsFullscreen;       /* is the window fullscreen?         */
514
515     /* FreeGLUT operations are deferred, that is, window moving, resizing,
516      * Z-order changing, making full screen or not do not happen immediately
517      * upon the user's request, but only in the next iteration of the main
518      * loop, before the display callback is called. This allows multiple
519      * reshape, position, etc requests to be combined into one and is
520      * compatible with the way GLUT does things. Callbacks get triggered
521      * based on the feedback/messages/notifications from the window manager.
522      * Below here we define what work should be done, as well as the relevant
523      * parameters for this work.
524      */
525     unsigned int    WorkMask;           /* work (resize, etc) to be done on the window */
526     int             DesiredXpos;        /* desired X location */
527     int             DesiredYpos;        /* desired Y location */
528     int             DesiredWidth;       /* desired window width */
529     int             DesiredHeight;      /* desired window height */
530     int             DesiredZOrder;      /* desired window Z Order position */
531     fgDesiredVisibility DesiredVisibility;/* desired visibility (hidden, iconic, shown/normal) */
532
533         SFG_PlatformWindowState pWState;    /* Window width/height (X11) or rectangle/style (Windows) from before a resize, and other stuff only needed on specific platforms */
534
535     long            JoystickPollRate;   /* The joystick polling rate         */
536     fg_time_t       JoystickLastPoll;   /* When the last poll happened       */
537
538     int             MouseX, MouseY;     /* The most recent mouse position    */
539
540     GLboolean       IgnoreKeyRepeat;    /* Whether to ignore key repeat.     */
541
542     GLboolean       VisualizeNormals;   /* When drawing objects, draw vectors representing the normals as well? */
543 };
544
545
546 /*
547  * A generic function pointer.  We should really use the GLUTproc type
548  * defined in freeglut_ext.h, but if we include that header in this file
549  * a bunch of other stuff (font-related) blows up!
550  */
551 typedef void (*SFG_Proc)();
552
553
554 /*
555  * SET_WCB() is used as:
556  *
557  *     SET_WCB( window, cbname, func, udata );
558  *
559  * ...where {window} is the freeglut window to set the callback,
560  *          {cbname} is the window-specific callback to set,
561  *          {func} is a function-pointer,
562  *          {udata} is a void* pointer for user data.
563  *
564  * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,
565  * but this can cause warnings because the FETCH_WCB() macro type-
566  * casts its result, and a type-cast value shouldn't be an lvalue.
567  *
568  * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking
569  * and for no other reason.  Since it's hidden in the macro, the
570  * ugliness is felt to be rather benign.
571  */
572 #define SET_WCB(window,cbname,func,udata)                      \
573 do                                                             \
574 {                                                              \
575     if( FETCH_WCB( window, cbname ) != (SFG_Proc)(func) )      \
576     {                                                          \
577         (((window).CallBacks[WCB_ ## cbname]) = (SFG_Proc)(func)); \
578         (((window).CallbackDatas[WCB_ ## cbname]) = (udata));  \
579     }                                                          \
580 } while( 0 )
581
582 /*
583  * FETCH_WCB() is used as:
584  *
585  *     FETCH_WCB( window, cbname );
586  *
587  * ...where {window} is the freeglut window to fetch the callback from,
588  *          {cbname} is the window-specific callback to fetch.
589  *
590  * The result is correctly type-cast to the callback function pointer
591  * type.
592  */
593 #define FETCH_WCB(window,cbname) \
594     ((window).CallBacks[WCB_ ## cbname])
595
596 /*
597  * FETCH_USER_DATA_WCB() is used as:
598  * 
599  *     FETCH_USER_DATA_WCB( window, cbname );
600  *
601  * ...where {window} is the freeglut window,
602  *          {cbname} is the window-specific callback to be invoked,
603  *
604  * This expects a variable named "window" of type tagSFG_Window to exist.
605  */
606 /*
607  * FETCH_USER_DATA_WCB() is used as:
608  *
609  *     FETCH_USER_DATA_WCB( window, cbname );
610  *
611  * ...where {window} is the freeglut window to fetch the callback data from,
612  *          {cbname} is the window-specific callback data to fetch.
613  *
614  * The result is the callback data pointer.
615  */
616 #define FETCH_USER_DATA_WCB(window,cbname) \
617     ((window).CallbackDatas[WCB_ ## cbname])
618
619 /*
620  * EXPAND_WCB() is used as:
621  * 
622  *     EXPAND_WCB arg_list
623  * 
624  * ... where {(arg_list)} is the parameter list.
625  *
626  * This will take the arg_list and extend it by one argument, adding
627  * the argument "userData" to the end of the list.
628  * 
629  * All additional args are to get around trailing ',', argument counts,
630  * and not needing a GCC extension to make this work.
631  *
632  * Minor modification of:
633  * http://stackoverflow.com/questions/5355241/generating-function-declaration-using-a-macro-iteration/5355946#5355946
634  *
635  * Supports up to five arguments
636  */
637 #if TARGET_HOST_MS_WINDOWS
638
639 /* FIXME: Does VC6 support variadic macros? I don't think so (variadic macros came with C99. VC6 came out in 1998) */
640
641 /* FIXME: VC++ has a greedy preprocessor.
642  * The preprocessor resolves the macros on use instead of after on argument completion/token usage.
643  * e.g.: PP_HAS_ARGS_IMPL2(ONE_OR_MORE, ...) -> PP_HAS_ARGS_IMPL2(, ...) -> "Error, not enough tokens for PP_HAS_ARGS_IMPL2"
644  */
645 #define EXPAND_WCB(...) (__VA_ARGS__)
646
647 #else // #if TARGET_HOST_MS_WINDOWS
648
649 #define PP_HAS_ARGS_IMPL2(_0, _1, _2, _3, _4, _5, N, ...) N
650 #define PP_HAS_ARGS_SOURCE() \
651     ONE_OR_MORE, ONE_OR_MORE, ONE_OR_MORE, ONE_OR_MORE, ONE_OR_MORE, ZERO
652
653 #define PP_HAS_ARGS_IMPL(...) \
654     PP_HAS_ARGS_IMPL2(__VA_ARGS__)
655 #define PP_HAS_ARGS(...) \
656     PP_HAS_ARGS_IMPL(NOT_EXIST, ##__VA_ARGS__, PP_HAS_ARGS_SOURCE())
657
658 #define EXPAND_WCB_ZERO(x) \
659     (userData)
660 #define EXPAND_WCB_ONE_OR_MORE(...) \
661     (__VA_ARGS__, userData)
662
663 #define EXPAND_WCB_DISAMBIGUATE2(has_args, ...) \
664     EXPAND_WCB_ ## has_args (__VA_ARGS__)
665 #define EXPAND_WCB_DISAMBIGUATE(has_args, ...) \
666     EXPAND_WCB_DISAMBIGUATE2(has_args, __VA_ARGS__)
667 #define EXPAND_WCB(...) \
668     EXPAND_WCB_DISAMBIGUATE(PP_HAS_ARGS(__VA_ARGS__), __VA_ARGS__)
669
670 #endif // #if TARGET_HOST_MS_WINDOWS
671
672 /*
673  * INVOKE_WCB() is used as:
674  *
675  *     INVOKE_WCB( window, cbname, ( arg_list ) );
676  *
677  * ...where {window} is the freeglut window,
678  *          {cbname} is the window-specific callback to be invoked,
679  *          {(arg_list)} is the parameter list.
680  *
681  * The callback is invoked as:
682  *
683  *    callback( arg_list );
684  *
685  * ...so the parentheses are REQUIRED in the {arg_list}.
686  *
687  * NOTE that it does a sanity-check and also sets the
688  * current window.
689  *
690  */
691 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: also WinCE? */
692 #define INVOKE_WCB(window,cbname,arg_list)    \
693 do                                            \
694 {                                             \
695     if( FETCH_WCB( window, cbname ) )         \
696     {                                         \
697         FGCB ## cbname ## UC func = (FGCB ## cbname ## UC)(FETCH_WCB( window, cbname )); \
698         FGCBUserData userData = FETCH_USER_DATA_WCB( window, cbname ); \
699         fgSetWindow( &window );               \
700         func EXPAND_WCB arg_list;             \
701     }                                         \
702 } while( 0 )
703 #else
704 #define INVOKE_WCB(window,cbname,arg_list)    \
705 do                                            \
706 {                                             \
707     if( FETCH_WCB( window, cbname ) )         \
708     {                                         \
709         fgSetWindow( &window );               \
710         FGCBUserData userData = FETCH_USER_DATA_WCB( window, cbname ); \
711         ((FGCB ## cbname ## UC)FETCH_WCB( window, cbname )) EXPAND_WCB arg_list; \
712     }                                         \
713 } while( 0 )
714 #endif
715
716 /*
717  * The window callbacks the user can supply us with. Should be kept portable.
718  *
719  * This enumeration provides the freeglut CallBack numbers.
720  * The symbolic constants are indices into a window's array of
721  * function callbacks.  The names are formed by splicing a common
722  * prefix onto the callback's base name.  (This was originally
723  * done so that an early stage of development could live side-by-
724  * side with the old callback code.  The old callback code used
725  * the bare callback's name as a structure member, so I used a
726  * prefix for the array index name.)
727  */
728 enum
729 {
730     WCB_Display,
731     WCB_Reshape,
732     WCB_Position,
733     WCB_Keyboard,
734     WCB_KeyboardUp,
735     WCB_Special,
736     WCB_SpecialUp,
737     WCB_Mouse,
738     WCB_MouseWheel,
739     WCB_Motion,
740     WCB_Passive,
741     WCB_Entry,
742     WCB_Visibility,
743     WCB_WindowStatus,
744     WCB_Joystick,
745     WCB_Destroy,
746
747     /* Multi-Pointer X and touch related */
748     WCB_MultiEntry,
749     WCB_MultiButton,
750     WCB_MultiMotion,
751     WCB_MultiPassive,
752
753     /* Mobile platforms LifeCycle */
754     WCB_InitContext,
755     WCB_AppStatus,
756
757     /* Presently ignored */
758     WCB_Select,
759     WCB_OverlayDisplay,
760     WCB_SpaceMotion,     /* presently implemented only on UNIX/X11 and Windows */
761     WCB_SpaceRotation,   /* presently implemented only on UNIX/X11 and Windows */
762     WCB_SpaceButton,     /* presently implemented only on UNIX/X11 and Windows */
763     WCB_Dials,
764     WCB_ButtonBox,
765     WCB_TabletMotion,
766     WCB_TabletButton,
767
768     /* Always make this the LAST one */
769     TOTAL_CALLBACKS
770 };
771
772
773 /* This structure holds the OpenGL rendering context for all the menu windows */
774 typedef struct tagSFG_MenuContext SFG_MenuContext;
775 struct tagSFG_MenuContext
776 {
777     SFG_WindowContextType MContext;       /* The menu window's WGL context   */
778 };
779
780 /* This structure describes a menu */
781 typedef struct tagSFG_Window SFG_Window;
782 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
783 typedef struct tagSFG_Menu SFG_Menu;
784 struct tagSFG_Menu
785 {
786     SFG_Node            Node;
787     void               *UserData;     /* User data passed back at callback   */
788     int                 ID;           /* The global menu ID                  */
789     SFG_List            Entries;      /* The menu entries list               */
790     FGCBMenuUC          Callback;     /* The menu callback                   */
791     FGCBUserData        CallbackData; /* The menu callback user data         */
792     FGCBDestroyUC       Destroy;      /* Destruction callback                */
793     FGCBUserData        DestroyData;  /* Destruction callback user data      */
794     GLboolean           IsActive;     /* Is the menu selected?               */
795     void*               Font;         /* Font to be used for displaying this menu */
796     int                 Width;        /* Menu box width in pixels            */
797     int                 Height;       /* Menu box height in pixels           */
798     int                 X, Y;         /* Menu box raster position            */
799
800     SFG_MenuEntry      *ActiveEntry;  /* Currently active entry in the menu  */
801     SFG_Window         *Window;       /* Window for menu                     */
802     SFG_Window         *ParentWindow; /* Window in which the menu is invoked */
803 };
804
805 /* This is a menu entry */
806 struct tagSFG_MenuEntry
807 {
808     SFG_Node            Node;
809     int                 ID;                     /* The menu entry ID (local) */
810     int                 Ordinal;                /* The menu's ordinal number */
811     char*               Text;                   /* The text to be displayed  */
812     SFG_Menu*           SubMenu;                /* Optional sub-menu tree    */
813     GLboolean           IsActive;               /* Is the entry highlighted? */
814     int                 Width;                  /* Label's width in pixels   */
815 };
816
817 /*
818  * A window, making part of freeglut windows hierarchy.
819  * Should be kept portable.
820  *
821  * NOTE that ActiveMenu is set to menu itself if the window is a menu.
822  */
823 struct tagSFG_Window
824 {
825     SFG_Node            Node;
826     int                 ID;                     /* Window's ID number        */
827
828     SFG_Context         Window;                 /* Window and OpenGL context */
829     SFG_WindowState     State;                  /* The window state          */
830     SFG_Proc            CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
831     FGCBUserData        CallbackDatas[ TOTAL_CALLBACKS ]; /* Array of window callback datas */
832     void               *UserData ;              /* For use by user           */
833
834     SFG_Menu*           Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window  */
835     SFG_Menu*           ActiveMenu;             /* The window's active menu  */
836
837     SFG_Window*         Parent;                 /* The parent to this window */
838     SFG_List            Children;               /* The subwindows d.l. list  */
839
840     GLboolean           IsMenu;                 /* Set to 1 if we are a menu */
841 };
842
843
844 /* A linked list structure of windows */
845 typedef struct tagSFG_WindowList SFG_WindowList ;
846 struct tagSFG_WindowList
847 {
848     SFG_Node node;
849     SFG_Window *window ;
850 };
851
852 /* This holds information about all the windows, menus etc. */
853 typedef struct tagSFG_Structure SFG_Structure;
854 struct tagSFG_Structure
855 {
856     SFG_List        Windows;         /* The global windows list            */
857     SFG_List        Menus;           /* The global menus list              */
858     SFG_List        WindowsToDestroy;
859
860     SFG_Window*     CurrentWindow;   /* The currently set window          */
861     SFG_Menu*       CurrentMenu;     /* Same, but menu...                 */
862
863     SFG_MenuContext* MenuContext;    /* OpenGL rendering context for menus */
864
865     SFG_Window*      GameModeWindow; /* The game mode window               */
866
867     int              WindowID;       /* The window ID for the next window to be created */
868     int              MenuID;         /* The menu ID for the next menu to be created */
869 };
870
871 /*
872  * This structure is used for the enumeration purposes.
873  * You can easily extend its functionalities by declaring
874  * a structure containing enumerator's contents and custom
875  * data, then casting its pointer to (SFG_Enumerator *).
876  */
877 typedef struct tagSFG_Enumerator SFG_Enumerator;
878 struct tagSFG_Enumerator
879 {
880     GLboolean   found;                          /* Used to terminate search  */
881     void*       data;                           /* Custom data pointer       */
882 };
883 typedef void (* FGCBWindowEnumerator  )( SFG_Window *, SFG_Enumerator * );
884 typedef void (* FGCBMenuEnumerator  )( SFG_Menu *, SFG_Enumerator * );
885
886 /* The bitmap font structure */
887 typedef struct tagSFG_Font SFG_Font;
888 struct tagSFG_Font
889 {
890     char*           Name;         /* The source font name             */
891     int             Quantity;     /* Number of chars in font          */
892     int             Height;       /* Height of the characters         */
893     const GLubyte** Characters;   /* The characters mapping           */
894
895     float           xorig, yorig; /* Relative origin of the character */
896 };
897
898 /* The stroke font structures */
899
900 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
901 struct tagSFG_StrokeVertex
902 {
903     GLfloat         X, Y;
904 };
905
906 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
907 struct tagSFG_StrokeStrip
908 {
909     int             Number;
910     const SFG_StrokeVertex* Vertices;
911 };
912
913 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
914 struct tagSFG_StrokeChar
915 {
916     GLfloat         Right;
917     int             Number;
918     const SFG_StrokeStrip* Strips;
919 };
920
921 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
922 struct tagSFG_StrokeFont
923 {
924     char*           Name;                       /* The source font name      */
925     int             Quantity;                   /* Number of chars in font   */
926     GLfloat         Height;                     /* Height of the characters  */
927     const SFG_StrokeChar** Characters;          /* The characters mapping    */
928 };
929
930
931 /* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */
932 /*
933  * Initial defines from "js.h" starting around line 33 with the existing "fg_joystick.c"
934  * interspersed
935  */
936
937 #if TARGET_HOST_MACINTOSH
938 #    include <InputSprocket.h>
939 #endif
940
941 #if TARGET_HOST_MAC_OSX
942 #    include <mach/mach.h>
943 #    include <IOKit/IOkitLib.h>
944 #    include <IOKit/hid/IOHIDLib.h>
945 #endif
946
947 /* XXX It might be better to poll the operating system for the numbers of buttons and
948  * XXX axes and then dynamically allocate the arrays.
949  */
950 #define _JS_MAX_BUTTONS 32
951
952 #if TARGET_HOST_MACINTOSH
953 #    define _JS_MAX_AXES  9
954 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
955 struct tagSFG_PlatformJoystick
956 {
957 #define  ISP_NUM_AXIS    9
958 #define  ISP_NUM_NEEDS  41
959     ISpElementReference isp_elem  [ ISP_NUM_NEEDS ];
960     ISpNeed             isp_needs [ ISP_NUM_NEEDS ];
961 };
962 #endif
963
964 #if TARGET_HOST_MAC_OSX
965 #    define _JS_MAX_AXES 16
966 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
967 struct tagSFG_PlatformJoystick
968 {
969     IOHIDDeviceInterface ** hidDev;
970     IOHIDElementCookie buttonCookies[41];
971     IOHIDElementCookie axisCookies[_JS_MAX_AXES];
972 /* The next two variables are not used anywhere */
973 /*    long minReport[_JS_MAX_AXES],
974  *         maxReport[_JS_MAX_AXES];
975  */
976 };
977 #endif
978
979
980 /*
981  * Definition of "SFG_Joystick" structure -- based on JS's "jsJoystick" object class.
982  * See "js.h" lines 80-178.
983  */
984 typedef struct tagSFG_Joystick SFG_Joystick;
985 struct tagSFG_Joystick
986 {
987         SFG_PlatformJoystick pJoystick;
988
989     int          id;
990     GLboolean    error;
991     char         name [ 128 ];
992     int          num_axes;
993     int          num_buttons;
994
995     float dead_band[ _JS_MAX_AXES ];
996     float saturate [ _JS_MAX_AXES ];
997     float center   [ _JS_MAX_AXES ];
998     float max      [ _JS_MAX_AXES ];
999     float min      [ _JS_MAX_AXES ];
1000 };
1001
1002
1003
1004 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
1005
1006 /* Freeglut display related stuff (initialized once per session) */
1007 extern SFG_Display fgDisplay;
1008
1009 /* Freeglut internal structure */
1010 extern SFG_Structure fgStructure;
1011
1012 /* The current freeglut settings */
1013 extern SFG_State fgState;
1014
1015
1016 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
1017
1018 /*
1019  * A call to this function makes us sure that the Display and Structure
1020  * subsystems have been properly initialized and are ready to be used
1021  */
1022 #define  FREEGLUT_EXIT_IF_NOT_INITIALISED( string )               \
1023   if ( ! fgState.Initialised )                                    \
1024   {                                                               \
1025     fgError ( " ERROR:  Function <%s> called"                     \
1026               " without first calling 'glutInit'.", (string) ) ;  \
1027   }
1028
1029 #define  FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED( string )  \
1030   if ( ! fgState.Initialised )                                      \
1031   {                                                                 \
1032     fgError ( " ERROR:  Internal <%s> function called"              \
1033               " without first calling 'glutInit'.", (string) ) ;    \
1034   }
1035
1036 #define  FREEGLUT_INTERNAL_ERROR_EXIT( cond, string, function )  \
1037   if ( ! ( cond ) )                                              \
1038   {                                                              \
1039     fgError ( " ERROR:  Internal error <%s> in function %s",     \
1040               (string), (function) ) ;                           \
1041   }
1042
1043 /*
1044  * Following definitions are somewhat similar to GLib's,
1045  * but do not generate any log messages:
1046  */
1047 #define  freeglut_return_if_fail( expr ) \
1048     if( !(expr) )                        \
1049         return;
1050 #define  freeglut_return_val_if_fail( expr, val ) \
1051     if( !(expr) )                                 \
1052         return val ;
1053
1054 /*
1055  * A call to those macros assures us that there is a current
1056  * window set, respectively:
1057  */
1058 #define  FREEGLUT_EXIT_IF_NO_WINDOW( string )                               \
1059   if ( ! fgStructure.CurrentWindow &&                                       \
1060        ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION ) )  \
1061   {                                                                         \
1062     fgError ( " ERROR:  Function <%s> called"                               \
1063               " with no current window defined.", (string) ) ;              \
1064   }
1065
1066 /*
1067  * The deinitialize function gets called on glutMainLoop() end. It should clean up
1068  * everything inside of the freeglut
1069  */
1070 void fgDeinitialize( void );
1071
1072 /*
1073  * Those two functions are used to create/destroy the freeglut internal
1074  * structures. This actually happens when calling glutInit() and when
1075  * quitting the glutMainLoop() (which actually happens, when all windows
1076  * have been closed).
1077  */
1078 void fgCreateStructure( void );
1079 void fgDestroyStructure( void );
1080
1081 /*
1082  * Window creation, opening, closing and destruction.
1083  * Also CallBack clearing/initialization.
1084  * Defined in fg_structure.c, fg_window.c.
1085  */
1086 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
1087                             GLboolean positionUse, int x, int y,
1088                             GLboolean sizeUse, int w, int h,
1089                             GLboolean gameMode, GLboolean isMenu );
1090 void        fgSetWindow ( SFG_Window *window );
1091 void        fgOpenWindow( SFG_Window* window, const char* title,
1092                           GLboolean positionUse, int x, int y,
1093                           GLboolean sizeUse, int w, int h,
1094                           GLboolean gameMode, GLboolean isSubWindow );
1095 void        fgCloseWindow( SFG_Window* window );
1096 void        fgAddToWindowDestroyList ( SFG_Window* window );
1097 void        fgCloseWindows ();
1098 void        fgDestroyWindow( SFG_Window* window );
1099
1100 /* Menu creation and destruction. Defined in fg_structure.c */
1101 SFG_Menu*   fgCreateMenu( FGCBMenuUC menuCallback, FGCBUserData userData );
1102 void        fgDestroyMenu( SFG_Menu* menu );
1103
1104 /* Joystick device management functions, defined in fg_joystick.c */
1105 int         fgJoystickDetect( void );
1106 void        fgInitialiseJoysticks( void );
1107 void        fgJoystickClose( void );
1108 void        fgJoystickPollWindow( SFG_Window* window );
1109
1110 /* InputDevice Initialisation and Closure */
1111 int         fgInputDeviceDetect( void );
1112 void        fgInitialiseInputDevices( void );
1113 void        fgInputDeviceClose( void );
1114
1115 /* spaceball device functions, defined in fg_spaceball.c */
1116 void        fgInitialiseSpaceball( void );
1117 void        fgSpaceballClose( void );
1118 void        fgSpaceballSetWindow( SFG_Window *window );
1119
1120 int         fgHasSpaceball( void );
1121 int         fgSpaceballNumButtons( void );
1122
1123 /* Setting the cursor for a given window */
1124 void fgSetCursor ( SFG_Window *window, int cursorID );
1125
1126 /*
1127  * Helper function to enumerate through all registered windows
1128  * and one to enumerate all of a window's subwindows...
1129  *
1130  * The GFunc callback for those functions will be defined as:
1131  *
1132  *      void enumCallback( gpointer window, gpointer enumerator );
1133  *
1134  * where window is the enumerated (sub)window pointer (SFG_Window *),
1135  * and userData is the a custom user-supplied pointer. Functions
1136  * are defined and exported from fg_structure.c file.
1137  */
1138 void fgEnumWindows( FGCBWindowEnumerator enumCallback, SFG_Enumerator* enumerator );
1139 void fgEnumSubWindows( SFG_Window* window, FGCBWindowEnumerator enumCallback,
1140                        SFG_Enumerator* enumerator );
1141
1142 /*
1143  * fgWindowByHandle returns a (SFG_Window *) value pointing to the
1144  * first window in the queue matching the specified window handle.
1145  * The function is defined in fg_structure.c file.
1146  */
1147 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
1148
1149 /*
1150  * This function is similar to the previous one, except it is
1151  * looking for a specified (sub)window identifier. The function
1152  * is defined in fg_structure.c file.
1153  */
1154 SFG_Window* fgWindowByID( int windowID );
1155
1156 /*
1157  * Looks up a menu given its ID. This is easier than fgWindowByXXX
1158  * as all menus are placed in a single doubly linked list...
1159  */
1160 SFG_Menu* fgMenuByID( int menuID );
1161
1162 /*
1163  * Returns active menu, if any. Assumption: only one menu active throughout application at any one time.
1164  * This is easier than fgWindowByXXX as all menus are placed in one doubly linked list...
1165  */
1166 SFG_Menu* fgGetActiveMenu( );
1167
1168 /*
1169  * The menu activation and deactivation the code. This is the meat
1170  * of the menu user interface handling code...
1171  */
1172 void fgUpdateMenuHighlight ( SFG_Menu *menu );
1173 GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
1174                               int mouse_x, int mouse_y );
1175 void fgDeactivateMenu( SFG_Window *window );
1176
1177 /*
1178  * This function gets called just before the buffers swap, so that
1179  * freeglut can display the pull-down menus via OpenGL. The function
1180  * is defined in fg_menu.c file.
1181  */
1182 void fgDisplayMenu( void );
1183
1184 /* Elapsed time as per glutGet(GLUT_ELAPSED_TIME). */
1185 fg_time_t fgElapsedTime( void );
1186
1187 /* System time in milliseconds */
1188 fg_time_t fgSystemTime(void);
1189
1190 /* List functions */
1191 void fgListInit(SFG_List *list);
1192 void fgListAppend(SFG_List *list, SFG_Node *node);
1193 void fgListRemove(SFG_List *list, SFG_Node *node);
1194 int fgListLength(SFG_List *list);
1195 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);
1196
1197 /* Error Message functions */
1198 void fgError( const char *fmt, ... );
1199 void fgWarning( const char *fmt, ... );
1200
1201 SFG_Proc fgPlatformGetProcAddress( const char *procName );
1202
1203 /* pushing attribute/value pairs into an array */
1204 #define ATTRIB(a) attributes[where++]=(a)
1205 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
1206
1207 int fghMapBit( int mask, int from, int to );
1208 int fghIsLegacyContextRequested( void );
1209 void fghContextCreationError( void );
1210 int fghNumberOfAuxBuffersRequested( void );
1211
1212 #endif /* FREEGLUT_INTERNAL_H */
1213
1214 /*** END OF FILE ***/