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