Fix a game mode crashing bug, conditional compilation for Windows, and comment out...
[freeglut] / src / freeglut_internal.h
1 /*
2  * freeglut_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 /* XXX Update these for each release! */
32 #define  VERSION_MAJOR 2
33 #define  VERSION_MINOR 2
34 #define  VERSION_PATCH 0
35
36 /*
37  * Freeglut is meant to be available under all Unix/X11 and Win32 platforms.
38  */
39 #if defined(_WIN32_WCE)
40 #   define  TARGET_HOST_UNIX_X11    0
41 #   define  TARGET_HOST_WIN32       0
42 #   define  TARGET_HOST_WINCE       1
43 #elif defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)
44 #   define  TARGET_HOST_UNIX_X11    0
45 #   define  TARGET_HOST_WIN32       1
46 #   define  TARGET_HOST_WINCE       0
47 #else
48 #   define  TARGET_HOST_UNIX_X11    1
49 #   define  TARGET_HOST_WIN32       0
50 #   define  TARGET_HOST_WINCE       0
51 #endif
52
53 #define  FREEGLUT_MAX_MENUS         3
54
55 /*
56  * Somehow all Win32 include headers depend on this one:
57  */
58 #if TARGET_HOST_WIN32
59 #include <windows.h>
60 #include <windowsx.h>
61 #include <mmsystem.h>
62 #include <TCHAR.H>
63 #endif
64
65 #if defined(_MSC_VER)
66 #define strdup   _strdup
67 #endif
68
69 /*
70  * Those files should be available on every platform.
71  */
72 #include <GL/gl.h>
73 #include <GL/glu.h>
74 #include <stdio.h>
75 #include <string.h>
76 #include <math.h>
77 #include <stdlib.h>
78 #include <assert.h>
79 #include <stdarg.h>
80 #if TARGET_HOST_UNIX_X11
81 #include <unistd.h>
82 #include <sys/time.h>
83 #endif
84
85 /*
86  * The system-dependant include files should go here:
87  */
88 #if TARGET_HOST_UNIX_X11
89     #include <GL/glx.h>
90     #include <X11/Xlib.h>
91     #include <X11/Xatom.h>
92     #include <X11/keysym.h>
93
94     #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
95     #include <X11/extensions/xf86vmode.h>
96     #endif
97 #endif
98
99 /*
100  * Microsoft VisualC++ 5.0's <math.h> does not define the PI
101  */
102 #ifndef M_PI
103 #    define  M_PI  3.14159265358979323846
104 #endif
105
106 #ifndef TRUE
107 #    define  TRUE  1
108 #endif
109
110 #ifndef FALSE
111 #    define  FALSE  0
112 #endif
113
114 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
115
116 /*
117  * Freeglut callbacks type definitions
118  */
119 typedef void (* FGCBDisplay       )( void );
120 typedef void (* FGCBReshape       )( int, int );
121 typedef void (* FGCBVisibility    )( int );
122 typedef void (* FGCBKeyboard      )( unsigned char, int, int );
123 typedef void (* FGCBSpecial       )( int, int, int );
124 typedef void (* FGCBMouse         )( int, int, int, int );
125 typedef void (* FGCBMouseWheel    )( int, int, int, int );
126 typedef void (* FGCBMotion        )( int, int );
127 typedef void (* FGCBPassive       )( int, int );
128 typedef void (* FGCBEntry         )( int );
129 typedef void (* FGCBWindowStatus  )( int );
130 typedef void (* FGCBSelect        )( int, int, int );
131 typedef void (* FGCBJoystick      )( unsigned int, int, int, int );
132 typedef void (* FGCBKeyboardUp    )( unsigned char, int, int );
133 typedef void (* FGCBSpecialUp     )( int, int, int );
134 typedef void (* FGCBOverlayDisplay)( void );
135 typedef void (* FGCBSpaceMotion   )( int, int, int );
136 typedef void (* FGCBSpaceRotation )( int, int, int );
137 typedef void (* FGCBSpaceButton   )( int, int );
138 typedef void (* FGCBDials         )( int, int );
139 typedef void (* FGCBButtonBox     )( int, int );
140 typedef void (* FGCBTabletMotion  )( int, int );
141 typedef void (* FGCBTabletButton  )( int, int, int, int );
142 typedef void (* FGCBDestroy       )( void );
143
144 /*
145  * The global callbacks type definitions
146  */
147 typedef void (* FGCBIdle          )( void );
148 typedef void (* FGCBTimer         )( int );
149 typedef void (* FGCBMenuState     )( int );
150 typedef void (* FGCBMenuStatus    )( int, int, int );
151
152 /*
153  * The callback used when creating/using menus
154  */
155 typedef void (* FGCBMenu          )( int );
156
157
158 /*
159  * A list structure
160  */
161 typedef struct tagSFG_List SFG_List;
162 struct tagSFG_List
163 {
164     void *First;
165     void *Last;
166 };
167
168 /*
169  * A list node structure
170  */
171 typedef struct tagSFG_Node SFG_Node;
172 struct tagSFG_Node
173 {
174     void *Next;
175     void *Prev;
176 };
177
178 /*
179  * A helper structure holding two ints and a boolean
180  */
181 typedef struct tagSFG_XYUse SFG_XYUse;
182 struct tagSFG_XYUse
183 {
184     GLint           X, Y;               /* The two integers...               */
185     GLboolean       Use;                /* ...and a single boolean.          */
186 };
187
188 /*
189  * A helper structure holding a timeval and a boolean
190  */
191 typedef struct tagSFG_Time SFG_Time;
192 struct tagSFG_Time
193 {
194 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
195     DWORD Value;
196 #else
197     struct timeval  Value;
198 #endif
199     GLboolean       Set;
200 };
201
202 /*
203  * An enumeration containing the state of the GLUT execution:
204  * initializing, running, or stopping
205  */
206 typedef enum
207 {
208   GLUT_EXEC_STATE_INIT,
209   GLUT_EXEC_STATE_RUNNING,
210   GLUT_EXEC_STATE_STOP
211 } fgExecutionState ;
212
213 /*
214  * This structure holds different freeglut settings
215  */
216 typedef struct tagSFG_State SFG_State;
217 struct tagSFG_State
218 {
219     SFG_XYUse        Position;             /* The default windows' position  */
220     SFG_XYUse        Size;                 /* The default windows' size      */
221     unsigned int     DisplayMode;          /* Display mode for new windows   */
222
223     GLboolean        Initialised;          /* freeglut has been initialised  */
224
225     int              DirectContext;        /* Direct rendering state         */
226
227     GLboolean        ForceIconic;          /* New top windows are iconified  */
228     GLboolean        UseCurrentContext;    /* New windows share with current */
229
230     GLboolean        GLDebugSwitch;        /* OpenGL state debugging switch  */
231     GLboolean        XSyncSwitch;          /* X11 sync protocol switch       */
232
233     int              KeyRepeat;            /* Global key repeat mode.        */
234     int              Modifiers;            /* Current ALT/SHIFT/CTRL state   */
235
236     GLuint           FPSInterval;          /* Interval between FPS printfs   */
237     GLuint           SwapCount;            /* Count of glutSwapBuffer calls  */
238     GLuint           SwapTime;             /* Time of last SwapBuffers       */
239
240     SFG_Time         Time;                 /* Time that glutInit was called  */
241     SFG_List         Timers;               /* The freeglut timer hooks       */
242     SFG_List         FreeTimers;           /* The unused timer hooks         */
243
244     FGCBIdle         IdleCallback;         /* The global idle callback       */
245
246     int              ActiveMenus;          /* Num. of currently active menus */
247     FGCBMenuState    MenuStateCallback;    /* Menu callbacks are global      */
248     FGCBMenuStatus   MenuStatusCallback;
249
250     SFG_XYUse        GameModeSize;         /* Game mode screen's dimensions  */
251     int              GameModeDepth;        /* The pixel depth for game mode  */
252     int              GameModeRefresh;      /* The refresh rate for game mode */
253
254     int              ActionOnWindowClose; /* Action when user closes window  */
255
256     fgExecutionState ExecState;           /* Used for GLUT termination       */
257     char            *ProgramName;         /* Name of the invoking program    */
258 };
259
260 /*
261  * The structure used by display initialization in freeglut_init.c
262  */
263 typedef struct tagSFG_Display SFG_Display;
264 struct tagSFG_Display
265 {
266 #if TARGET_HOST_UNIX_X11
267     Display*        Display;            /* The display we are being run in.  */
268     int             Screen;             /* The screen we are about to use.   */
269     Window          RootWindow;         /* The screen's root window.         */
270     int             Connection;         /* The display's connection number   */
271     Atom            DeleteWindow;       /* The window deletion atom          */
272
273 #ifdef X_XF86VidModeGetModeLine
274     /*
275      * XF86VidMode may be compilable even if it fails at runtime.  Therefore,
276      * the validity of the VidMode has to be tracked
277      */
278     int             DisplayModeValid;   /* Flag that indicates runtime status*/
279     XF86VidModeModeLine DisplayMode;    /* Current screen's display settings */
280     int             DisplayModeClock;   /* The display mode's refresh rate   */
281     int             DisplayViewPortX;   /* saved X location of the viewport  */
282     int             DisplayViewPortY;   /* saved Y location of the viewport  */
283     int             DisplayPointerX;    /* saved X location of the pointer   */
284     int             DisplayPointerY;    /* saved Y location of the pointer   */
285
286 #endif
287
288 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
289     HINSTANCE        Instance;          /* The application's instance        */
290     DEVMODE         DisplayMode;        /* Desktop's display settings        */
291
292 #endif
293
294     int             ScreenWidth;        /* The screen's width in pixels      */
295     int             ScreenHeight;       /* The screen's height in pixels     */
296     int             ScreenWidthMM;      /* The screen's width in milimeters  */
297     int             ScreenHeightMM;     /* The screen's height in milimeters */
298 };
299
300
301 /*
302  * The user can create any number of timer hooks
303  */
304 typedef struct tagSFG_Timer SFG_Timer;
305 struct tagSFG_Timer
306 {
307     SFG_Node        Node;
308     int             ID;                 /* The timer ID integer              */
309     FGCBTimer       Callback;           /* The timer callback                */
310     long            TriggerTime;        /* The timer trigger time            */
311 };
312
313 /*
314  * Make "freeglut" window handle and context types so that we don't need so
315  * much conditionally-compiled code later in the library.
316  */
317 #if TARGET_HOST_UNIX_X11
318
319 typedef Window     SFG_WindowHandleType ;
320 typedef GLXContext SFG_WindowContextType ;
321
322 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
323
324 typedef HWND    SFG_WindowHandleType ;
325 typedef HGLRC   SFG_WindowContextType ;
326
327 #endif
328
329 /*
330  * A window and its OpenGL context. The contents of this structure
331  * are highly dependant on the target operating system we aim at...
332  */
333 typedef struct tagSFG_Context SFG_Context;
334 struct tagSFG_Context
335 {
336     SFG_WindowHandleType  Handle;    /* The window's handle                 */
337     SFG_WindowContextType Context;   /* The window's OpenGL/WGL context     */
338
339 #if TARGET_HOST_UNIX_X11
340     XVisualInfo*    VisualInfo;      /* The window's visual information     */
341     Pixmap          Pixmap;          /* Used for offscreen rendering        */
342     /* GLXPixmap      GLXPixMap; */  /* Used for offscreen rendering        */
343 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
344     HDC             Device;          /* The window's device context         */
345 #endif
346
347     int             DoubleBuffered;  /* Treat the window as double-buffered */
348 };
349
350 /*
351  * Window's state description. This structure should be kept portable.
352  */
353 typedef struct tagSFG_WindowState SFG_WindowState;
354 struct tagSFG_WindowState
355 {
356     int             Width;              /* Window's width in pixels          */
357     int             Height;             /* The same about the height         */
358     int             OldWidth;           /* Window width from before a resize */
359     int             OldHeight;          /*   "    height  "    "    "   "    */
360
361     GLboolean       Redisplay;          /* Do we have to redisplay?          */
362     GLboolean       Visible;            /* Is the window visible now         */
363
364     int             Cursor;             /* The currently selected cursor     */
365
366     long            JoystickPollRate;   /* The joystick polling rate         */
367     long            JoystickLastPoll;   /* When the last poll happened       */
368
369     int             MouseX, MouseY;     /* The most recent mouse position    */
370
371     GLboolean       IgnoreKeyRepeat;    /* Whether to ignore key repeat.     */
372     GLboolean       KeyRepeating;       /* Currently in repeat mode          */
373
374     GLboolean       IsGameMode;         /* Is this the game mode window?     */
375     GLboolean       NeedToResize;       /* Do we need to resize the window?  */
376 };
377
378
379 /*
380  * SET_WCB() is used as:
381  *
382  *     SET_WCB( window, Visibility, func );
383  *
384  * ...where {window} is the freeglut window to set the callback,
385  *          {Visibility} is the window-specific callback to set,
386  *          {func} is a function-pointer.
387  *
388  * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,
389  * but this can cause warnings because the FETCH_WCB() macro type-
390  * casts its result, and a type-cast value shouldn't be an lvalue.
391  *
392  * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking
393  * and for no other reason.  Since it's hidden in the macro, the
394  * ugliness is felt to be rather benign.
395  */
396 #define SET_WCB(window,cbname,func)                            \
397 do                                                             \
398 {                                                              \
399     if( FETCH_WCB( window, cbname ) != func )                  \
400         (((window).CallBacks[CB_ ## cbname]) = (void *) func); \
401 } while( 0 )                                                   \
402
403 /*
404  * FETCH_WCB() is used as:
405  *
406  *     FETCH_WCB( window, Visibility );
407  *
408  * ...where {window} is the freeglut window to fetch the callback from,
409  *          {Visibility} is the window-specific callback to fetch.
410  *
411  * The result is correctly type-cast to the callback function pointer
412  * type.
413  */
414 #define FETCH_WCB(window,cbname) \
415     ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
416
417 /*
418  * INVOKE_WCB() is used as:
419  *
420  *     INVOKE_WCB( window, Visibility, ( status ) );
421  *
422  * ...where {window} is the freeglut window,
423  *          {Visibility} is the window-specific callback,
424  *          {(status)} is the parameter list.
425  *
426  * The callback is invoked as:
427  *
428  *    callback( status );
429  *
430  * ...so the parentheses are REQUIRED in the {arg_list}.
431  *
432  * NOTE that it does a sanity-check and also sets the
433  * current window.
434  *
435  */
436 #define INVOKE_WCB(window,cbname,arg_list)    \
437 do                                            \
438 {                                             \
439     if( FETCH_WCB( window, cbname ) )         \
440     {                                         \
441         fgSetWindow( &window );               \
442         FETCH_WCB( window, cbname ) arg_list; \
443     }                                         \
444 } while( 0 )
445
446 /*
447  * The window callbacks the user can supply us with. Should be kept portable.
448  *
449  * This enumeration provides the freeglut CallBack numbers.
450  * The symbolic constants are indices into a window's array of
451  * function callbacks.  The names are formed by splicing a common
452  * prefix onto the callback's base name.  (This was originally
453  * done so that an early stage of development could live side-by-
454  * side with the old callback code.  The old callback code used
455  * the bare callback's name as a structure member, so I used a
456  * prefix for the array index name.)
457  *
458  * XXX For consistancy, perhaps the prefix should match the
459  * XXX FETCH* and INVOKE* macro suffices.  I.e., WCB_, rather than
460  * XXX CB_.
461  */
462 enum
463 {
464     CB_Display,
465     CB_Reshape,
466     CB_Keyboard,
467     CB_KeyboardUp,
468     CB_Special,
469     CB_SpecialUp,
470     CB_Mouse,
471     CB_MouseWheel,
472     CB_Motion,
473     CB_Passive,
474     CB_Entry,
475     CB_Visibility,
476     CB_WindowStatus,
477     CB_Joystick,
478     CB_Destroy,
479
480     /* Presently ignored */
481     CB_Select,
482     CB_OverlayDisplay,
483     CB_SpaceMotion,
484     CB_SpaceRotation,
485     CB_SpaceButton,
486     CB_Dials,
487     CB_ButtonBox,
488     CB_TabletMotion,
489     CB_TabletButton,
490
491     /* Always make this the LAST one */
492     TOTAL_CALLBACKS
493 };
494
495
496 /*
497  * This structure holds the OpenGL rendering context for all the menu windows
498  */
499 typedef struct tagSFG_MenuContext SFG_MenuContext;
500 struct tagSFG_MenuContext
501 {
502 #if TARGET_HOST_UNIX_X11
503     XVisualInfo*        VisualInfo;       /* The window's visual information */
504 #endif
505
506     SFG_WindowContextType Context;        /* The menu window's WGL context   */
507 };
508
509 /*
510  * This structure describes a menu
511  */
512 typedef struct tagSFG_Window SFG_Window;
513 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
514 typedef struct tagSFG_Menu SFG_Menu;
515 struct tagSFG_Menu
516 {
517     SFG_Node            Node;
518     void               *UserData;     /* User data passed back at callback   */
519     int                 ID;           /* The global menu ID                  */
520     SFG_List            Entries;      /* The menu entries list               */
521     FGCBMenu            Callback;     /* The menu callback                   */
522     FGCBDestroy         Destroy;      /* Destruction callback                */
523     GLboolean           IsActive;     /* Is the menu selected?               */
524     int                 Width;        /* Menu box width in pixels            */
525     int                 Height;       /* Menu box height in pixels           */
526     int                 X, Y;         /* Menu box raster position            */
527
528     SFG_MenuEntry      *ActiveEntry;  /* Currently active entry in the menu  */
529     SFG_Window         *Window;       /* Window for menu                     */
530     SFG_Window         *ParentWindow; /* Window in which the menu is defined */
531 };
532
533 /*
534  * This is a menu entry
535  */
536 struct tagSFG_MenuEntry
537 {
538     SFG_Node            Node;
539     int                 ID;                     /* The menu entry ID (local) */
540     int                 Ordinal;                /* The menu's ordinal number */
541     char*               Text;                   /* The text to be displayed  */
542     SFG_Menu*           SubMenu;                /* Optional sub-menu tree    */
543     GLboolean           IsActive;               /* Is the entry highlighted? */
544     int                 Width;                  /* Label's width in pixels   */
545 };
546
547 /*
548  * A window, making part of freeglut windows hierarchy.
549  * Should be kept portable.
550  */
551 struct tagSFG_Window
552 {
553     SFG_Node            Node;
554     int                 ID;                     /* Window's ID number        */
555
556     SFG_Context         Window;                 /* Window and OpenGL context */
557     SFG_WindowState     State;                  /* The window state          */
558     void         *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
559     void               *UserData ;              /* For use by user           */
560
561     SFG_Menu*       Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window  */
562     SFG_Menu*       ActiveMenu;                 /* The window's active menu  */
563
564     SFG_Window*         Parent;                 /* The parent to this window */
565     SFG_List            Children;               /* The subwindows d.l. list  */
566
567     GLboolean           IsMenu;                 /* Set to 1 if we are a menu */
568 };
569
570
571 /*
572  * A linked list structure of windows
573  */
574 typedef struct tagSFG_WindowList SFG_WindowList ;
575 struct tagSFG_WindowList
576 {
577     SFG_Node node;
578     SFG_Window *window ;
579 };
580
581 /*
582  * This holds information about all the windows, menus etc.
583  */
584 typedef struct tagSFG_Structure SFG_Structure;
585 struct tagSFG_Structure
586 {
587     SFG_List        Windows;      /* The global windows list            */
588     SFG_List        Menus;        /* The global menus list              */
589     SFG_List        WindowsToDestroy;
590
591     SFG_Window*     Window;       /* The currently active win.          */
592     SFG_Menu*       Menu;         /* Same, but menu...                  */
593
594     SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
595
596     SFG_Window*      GameMode;    /* The game mode window               */
597
598     int              WindowID;    /* The new current window ID          */
599     int              MenuID;      /* The new current menu ID            */
600 };
601
602 /*
603  * This structure is used for the enumeration purposes.
604  * You can easily extend its functionalities by declaring
605  * a structure containing enumerator's contents and custom
606  * data, then casting its pointer to (SFG_Enumerator *).
607  */
608 typedef struct tagSFG_Enumerator SFG_Enumerator;
609 struct tagSFG_Enumerator
610 {
611     GLboolean   found;                          /* Used to terminate search  */
612     void*       data;                           /* Custom data pointer       */
613 };
614 typedef void (* FGCBenumerator  )( SFG_Window *, SFG_Enumerator * );
615
616 /*
617  * The bitmap font structure
618  */
619 typedef struct tagSFG_Font SFG_Font;
620 struct tagSFG_Font
621 {
622     char*           Name;         /* The source font name             */
623     int             Quantity;     /* Number of chars in font          */
624     int             Height;       /* Height of the characters         */
625     const GLubyte** Characters;   /* The characters mapping           */
626
627     float           xorig, yorig; /* Relative origin of the character */
628 };
629
630 /*
631  * The stroke font structures
632  */
633
634 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
635 struct tagSFG_StrokeVertex
636 {
637     GLfloat         X, Y;
638 };
639
640 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
641 struct tagSFG_StrokeStrip
642 {
643     int             Number;
644     const SFG_StrokeVertex* Vertices;
645 };
646
647 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
648 struct tagSFG_StrokeChar
649 {
650     GLfloat         Right;
651     int             Number;
652     const SFG_StrokeStrip* Strips;
653 };
654
655 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
656 struct tagSFG_StrokeFont
657 {
658     char*           Name;                       /* The source font name      */
659     int             Quantity;                   /* Number of chars in font   */
660     GLfloat         Height;                     /* Height of the characters  */
661     const SFG_StrokeChar** Characters;          /* The characters mapping    */
662 };
663
664 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
665
666 /*
667  * Freeglut display related stuff (initialized once per session)
668  */
669 extern SFG_Display fgDisplay;
670
671 /*
672  * Freeglut internal structure
673  */
674 extern SFG_Structure fgStructure;
675
676 /*
677  * The current freeglut settings
678  */
679 extern SFG_State fgState;
680
681
682 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
683
684 /*
685  * A call to this function makes us sure that the Display and Structure
686  * subsystems have been properly initialized and are ready to be used
687  */
688 #define  freeglut_assert_ready  assert( fgState.Initialised );
689
690 /*
691  * Following definitions are somewhat similiar to GLib's,
692  * but do not generate any log messages:
693  */
694 #define  freeglut_return_if_fail( expr ) \
695     if( !(expr) )                        \
696         return;
697 #define  freeglut_return_val_if_fail( expr, val ) \
698     if( !(expr) )                                 \
699         return val ;
700
701 /*
702  * A call to those macros assures us that there is a current
703  * window and menu set, respectively:
704  */
705 #define  freeglut_assert_window assert( fgStructure.Window != NULL );
706 #define  freeglut_assert_menu   assert( fgStructure.Menu != NULL );
707
708 /*
709  * The initialize and deinitialize functions get called on glutInit()
710  * and glutMainLoop() end respectively. They should create/clean up
711  * everything inside of the freeglut
712  */
713 void fgInitialize( const char* displayName );
714 void fgDeinitialize( void );
715
716 /*
717  * Those two functions are used to create/destroy the freeglut internal
718  * structures. This actually happens when calling glutInit() and when
719  * quitting the glutMainLoop() (which actually happens, when all windows
720  * have been closed).
721  */
722 void fgCreateStructure( void );
723 void fgDestroyStructure( void );
724
725 /*
726  * A helper function to check if a display mode is possible to use
727  */
728 #if TARGET_HOST_UNIX_X11
729 XVisualInfo* fgChooseVisual( void );
730 #endif
731
732 /*
733  * The window procedure for Win32 events handling
734  */
735 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
736 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
737                                WPARAM wParam, LPARAM lParam );
738 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
739                               unsigned char layer_type );
740 #endif
741
742 /*
743  * Window creation, opening, closing and destruction.
744  * Also CallBack clearing/initialization.
745  * Defined in freeglut_structure.c, freeglut_window.c.
746  */
747 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
748                             int x, int y, int w, int h,
749                             GLboolean gameMode, GLboolean isMenu );
750 void        fgSetWindow ( SFG_Window *window );
751 void        fgOpenWindow( SFG_Window* window, const char* title,
752                           int x, int y, int w, int h, GLboolean gameMode,
753                           GLboolean isSubWindow );
754 void        fgCloseWindow( SFG_Window* window );
755 void        fgAddToWindowDestroyList ( SFG_Window* window );
756 void        fgCloseWindows ();
757 void        fgDestroyWindow( SFG_Window* window );
758 void        fgClearCallBacks( SFG_Window *window );
759
760 /*
761  * Menu creation and destruction. Defined in freeglut_structure.c
762  */
763 SFG_Menu*   fgCreateMenu( FGCBMenu menuCallback );
764 void        fgDestroyMenu( SFG_Menu* menu );
765
766 /*
767  * Joystick device management functions, defined in freeglut_joystick.c
768  */
769 void        fgJoystickInit( int ident );
770 void        fgJoystickClose( void );
771 void        fgJoystickPollWindow( SFG_Window* window );
772
773 /*
774  * Helper function to enumerate through all registered windows
775  * and one to enumerate all of a window's subwindows...
776  *
777  * The GFunc callback for those functions will be defined as:
778  *
779  *      void enumCallback( gpointer window, gpointer enumerator );
780  *
781  * where window is the enumerated (sub)window pointer (SFG_Window *),
782  * and userData is the a custom user-supplied pointer. Functions
783  * are defined and exported from freeglut_structure.c file.
784  */
785 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
786 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
787                        SFG_Enumerator* enumerator );
788
789 /*
790  * fgWindowByHandle returns a (SFG_Window *) value pointing to the
791  * first window in the queue matching the specified window handle.
792  * The function is defined in freeglut_structure.c file.
793  */
794 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
795
796 /*
797  * This function is similiar to the previous one, except it is
798  * looking for a specified (sub)window identifier. The function
799  * is defined in freeglut_structure.c file.
800  */
801 SFG_Window* fgWindowByID( int windowID );
802
803 /*
804  * Looks up a menu given its ID. This is easier than fgWindowByXXX
805  * as all menus are placed in a single doubly linked list...
806  */
807 SFG_Menu* fgMenuByID( int menuID );
808
809 /*
810  * The menu activation and deactivation the code. This is the meat
811  * of the menu user interface handling code...
812  */
813 void fgActivateMenu( SFG_Window* window, int button );
814 void fgExecuteMenuCallback( SFG_Menu* menu );
815 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
816 void fgDeactivateMenu( SFG_Window *window );
817 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
818
819 /*
820  * This function gets called just before the buffers swap, so that
821  * freeglut can display the pull-down menus via OpenGL. The function
822  * is defined in freeglut_menu.c file.
823  */
824 void fgDisplayMenu( void );
825
826 /*
827  * Display the mouse cursor using OpenGL calls. The function
828  * is defined in freeglut_cursor.c file.
829  */
830 void fgDisplayCursor( void );
831
832 /*
833  * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
834  */
835 long fgElapsedTime( void );
836
837 /*
838  * List functions
839  */
840 void fgListInit(SFG_List *list);
841 void fgListAppend(SFG_List *list, SFG_Node *node);
842 void fgListRemove(SFG_List *list, SFG_Node *node);
843 int fgListLength(SFG_List *list);
844 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);
845
846 /*
847  * Error Messages functions
848  */
849 void fgError( const char *fmt, ... );
850 void fgWarning( const char *fmt, ... );
851
852 #endif /* FREEGLUT_INTERNAL_H */
853
854 /*** END OF FILE ***/