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