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