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