C++ style comment converted to C style comment
[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     Pixmap          Pixmap;          /* Used for offscreen rendering        */
345     /* GLXPixmap      GLXPixMap; */  /* Used for offscreen rendering        */
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     GLboolean       NeedToResize;       /* Do we need to resize the window?  */
376     GLboolean       IsOffscreen;        /* Tags a `window' as on/offscreen.  */
377 };
378
379
380 /*
381  * SET_WCB() is used as:
382  *
383  *     SET_WCB( window, Visibility, func );
384  *
385  * ...where {window} is the freeglut window to set the callback,
386  *          {Visibility} is the window-specific callback to set,
387  *          {func} is a function-pointer.
388  *
389  * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,
390  * but this can cause warnings because the FETCH_WCB() macro type-
391  * casts its result, and a type-cast value shouldn't be an lvalue.
392  *
393  * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking
394  * and for no other reason.  Since it's hidden in the macro, the
395  * ugliness is felt to be rather benign.
396  */
397 #define SET_WCB(window,cbname,func)                            \
398 do                                                             \
399 {                                                              \
400     if( FETCH_WCB( window, cbname ) != func )                  \
401         (((window).CallBacks[CB_ ## cbname]) = (void *) func); \
402 } while( 0 )                                                   \
403
404 /*
405  * FETCH_WCB() is used as:
406  *
407  *     FETCH_WCB( window, Visibility );
408  *
409  * ...where {window} is the freeglut window to fetch the callback from,
410  *          {Visibility} is the window-specific callback to fetch.
411  *
412  * The result is correctly type-cast to the callback function pointer
413  * type.
414  */
415 #define FETCH_WCB(window,cbname) \
416     ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
417
418 /*
419  * INVOKE_WCB() is used as:
420  *
421  *     INVOKE_WCB( window, Visibility, ( status ) );
422  *
423  * ...where {window} is the freeglut window,
424  *          {Visibility} is the window-specific callback,
425  *          {(status)} is the parameter list.
426  *
427  * The callback is invoked as:
428  *
429  *    callback( status );
430  *
431  * ...so the parentheses are REQUIRED in the {arg_list}.
432  *
433  * NOTE that it does a sanity-check and also sets the
434  * current window.
435  *
436  */
437 #define INVOKE_WCB(window,cbname,arg_list)    \
438 do                                            \
439 {                                             \
440     if( FETCH_WCB( window, cbname ) )         \
441     {                                         \
442         fgSetWindow( &window );               \
443         FETCH_WCB( window, cbname ) arg_list; \
444     }                                         \
445 } while( 0 )
446
447 /*
448  * The window callbacks the user can supply us with. Should be kept portable.
449  *
450  * This enumeration provides the freeglut CallBack numbers.
451  * The symbolic constants are indices into a window's array of
452  * function callbacks.  The names are formed by splicing a common
453  * prefix onto the callback's base name.  (This was originally
454  * done so that an early stage of development could live side-by-
455  * side with the old callback code.  The old callback code used
456  * the bare callback's name as a structure member, so I used a
457  * prefix for the array index name.)
458  *
459  * XXX For consistancy, perhaps the prefix should match the
460  * XXX FETCH* and INVOKE* macro suffices.  I.e., WCB_, rather than
461  * XXX CB_.
462  */
463 enum
464 {
465     CB_Display,
466     CB_Reshape,
467     CB_Keyboard,
468     CB_KeyboardUp,
469     CB_Special,
470     CB_SpecialUp,
471     CB_Mouse,
472     CB_MouseWheel,
473     CB_Motion,
474     CB_Passive,
475     CB_Entry,
476     CB_Visibility,
477     CB_WindowStatus,
478     CB_Joystick,
479     CB_Destroy,
480
481     /* Presently ignored */
482     CB_Select,
483     CB_OverlayDisplay,
484     CB_SpaceMotion,
485     CB_SpaceRotation,
486     CB_SpaceButton,
487     CB_Dials,
488     CB_ButtonBox,
489     CB_TabletMotion,
490     CB_TabletButton,
491     
492     /* Always make this the LAST one */
493     TOTAL_CALLBACKS
494 };
495
496
497 /*
498  * This structure holds the OpenGL rendering context for all the menu windows
499  */
500 typedef struct tagSFG_MenuContext SFG_MenuContext;
501 struct tagSFG_MenuContext
502 {
503 #if TARGET_HOST_UNIX_X11
504     XVisualInfo*        VisualInfo;       /* The window's visual information */
505 #endif
506
507     SFG_WindowContextType Context;        /* The menu window's WGL context   */
508 };
509
510 /*
511  * This structure describes a menu
512  */
513 typedef struct tagSFG_Window SFG_Window;
514 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
515 typedef struct tagSFG_Menu SFG_Menu;
516 struct tagSFG_Menu
517 {
518     SFG_Node            Node;
519     void               *UserData;     /* User data passed back at callback   */
520     int                 ID;           /* The global menu ID                  */
521     SFG_List            Entries;      /* The menu entries list               */
522     FGCBMenu            Callback;     /* The menu callback                   */
523     FGCBDestroy         Destroy;      /* Destruction callback                */
524     GLboolean           IsActive;     /* Is the menu selected?               */
525     int                 Width;        /* Menu box width in pixels            */
526     int                 Height;       /* Menu box height in pixels           */
527     int                 X, Y;         /* Menu box raster position            */
528
529     SFG_MenuEntry      *ActiveEntry;  /* Currently active entry in the menu  */
530     SFG_Window         *Window;       /* Window for menu                     */
531     SFG_Window         *ParentWindow; /* Window in which the menu is defined */
532 };
533
534 /*
535  * This is a menu entry
536  */
537 struct tagSFG_MenuEntry
538 {
539     SFG_Node            Node;
540     int                 ID;                     /* The menu entry ID (local) */
541     int                 Ordinal;                /* The menu's ordinal number */
542     char*               Text;                   /* The text to be displayed  */
543     SFG_Menu*           SubMenu;                /* Optional sub-menu tree    */
544     GLboolean           IsActive;               /* Is the entry highlighted? */
545     int                 Width;                  /* Label's width in pixels   */
546 };
547
548 /*
549  * A window, making part of freeglut windows hierarchy.
550  * Should be kept portable.
551  */
552 struct tagSFG_Window
553 {
554     SFG_Node            Node;
555     int                 ID;                     /* Window's ID number        */
556
557     SFG_Context         Window;                 /* Window and OpenGL context */
558     SFG_WindowState     State;                  /* The window state          */
559     void         *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
560     void               *UserData ;              /* For use by user           */
561
562     SFG_Menu*       Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window  */
563     SFG_Menu*       ActiveMenu;                 /* The window's active menu  */
564
565     SFG_Window*         Parent;                 /* The parent to this window */
566     SFG_List            Children;               /* The subwindows d.l. list  */
567
568     GLboolean           IsMenu;                 /* Set to 1 if we are a menu */
569 };
570
571
572 /*
573  * A linked list structure of windows
574  */
575 typedef struct tagSFG_WindowList SFG_WindowList ;
576 struct tagSFG_WindowList
577 {
578     SFG_Node node;
579     SFG_Window *window ;
580 };
581
582 /*
583  * This holds information about all the windows, menus etc.
584  */
585 typedef struct tagSFG_Structure SFG_Structure;
586 struct tagSFG_Structure
587 {
588     SFG_List        Windows;      /* The global windows list            */
589     SFG_List        Menus;        /* The global menus list              */
590     SFG_List        WindowsToDestroy;
591
592     SFG_Window*     Window;       /* The currently active win.          */
593     SFG_Menu*       Menu;         /* Same, but menu...                  */
594
595     SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
596
597     SFG_Window*      GameMode;    /* The game mode window               */
598
599     int              WindowID;    /* The new current window ID          */
600     int              MenuID;      /* The new current menu ID            */
601 };
602
603 /*
604  * This structure is used for the enumeration purposes.
605  * You can easily extend its functionalities by declaring
606  * a structure containing enumerator's contents and custom
607  * data, then casting its pointer to (SFG_Enumerator *).
608  */
609 typedef struct tagSFG_Enumerator SFG_Enumerator;
610 struct tagSFG_Enumerator
611 {
612     GLboolean   found;                          /* Used to terminate search  */
613     void*       data;                           /* Custom data pointer       */
614 };
615 typedef void (* FGCBenumerator  )( SFG_Window *, SFG_Enumerator * );
616
617 /*
618  * The bitmap font structure
619  */
620 typedef struct tagSFG_Font SFG_Font;
621 struct tagSFG_Font
622 {
623     char*           Name;         /* The source font name             */
624     int             Quantity;     /* Number of chars in font          */
625     int             Height;       /* Height of the characters         */
626     const GLubyte** Characters;   /* The characters mapping           */
627
628     float           xorig, yorig; /* Relative origin of the character */
629 };
630
631 /*
632  * The stroke font structures
633  */
634
635 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
636 struct tagSFG_StrokeVertex
637 {
638     GLfloat         X, Y;
639 };
640
641 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
642 struct tagSFG_StrokeStrip
643 {
644     int             Number;
645     const SFG_StrokeVertex* Vertices;
646 };
647
648 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
649 struct tagSFG_StrokeChar
650 {
651     GLfloat         Right;
652     int             Number;
653     const SFG_StrokeStrip* Strips;
654 };
655
656 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
657 struct tagSFG_StrokeFont
658 {
659     char*           Name;                       /* The source font name      */
660     int             Quantity;                   /* Number of chars in font   */
661     GLfloat         Height;                     /* Height of the characters  */
662     const SFG_StrokeChar** Characters;          /* The characters mapping    */
663 };
664
665 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
666
667 /*
668  * Freeglut display related stuff (initialized once per session)
669  */
670 extern SFG_Display fgDisplay;
671
672 /*
673  * Freeglut internal structure
674  */
675 extern SFG_Structure fgStructure;
676
677 /*
678  * The current freeglut settings
679  */
680 extern SFG_State fgState;
681
682
683 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
684
685 /*
686  * A call to this function makes us sure that the Display and Structure
687  * subsystems have been properly initialized and are ready to be used
688  */
689 #define  freeglut_assert_ready  assert( fgState.Initialised );
690
691 /*
692  * Following definitions are somewhat similiar to GLib's,
693  * but do not generate any log messages:
694  */
695 #define  freeglut_return_if_fail( expr ) \
696     if( !(expr) )                        \
697         return;
698 #define  freeglut_return_val_if_fail( expr, val ) \
699     if( !(expr) )                                 \
700         return val ;
701
702 /*
703  * A call to those macros assures us that there is a current
704  * window and menu set, respectively:
705  */
706 #define  freeglut_assert_window assert( fgStructure.Window != NULL );
707 #define  freeglut_assert_menu   assert( fgStructure.Menu != NULL );
708
709 /*
710  * The initialize and deinitialize functions get called on glutInit()
711  * and glutMainLoop() end respectively. They should create/clean up
712  * everything inside of the freeglut
713  */
714 void fgInitialize( const char* displayName );
715 void fgDeinitialize( void );
716
717 /*
718  * Those two functions are used to create/destroy the freeglut internal
719  * structures. This actually happens when calling glutInit() and when
720  * quitting the glutMainLoop() (which actually happens, when all windows
721  * have been closed).
722  */
723 void fgCreateStructure( void );
724 void fgDestroyStructure( void );
725
726 /*
727  * A helper function to check if a display mode is possible to use
728  */
729 #if TARGET_HOST_UNIX_X11
730 XVisualInfo* fgChooseVisual( void );
731 #endif
732
733 /*
734  * The window procedure for Win32 events handling
735  */
736 #if TARGET_HOST_WIN32
737 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
738                                WPARAM wParam, LPARAM lParam );
739 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
740                               unsigned char layer_type );
741 #endif
742
743 /*
744  * Window creation, opening, closing and destruction.
745  * Also CallBack clearing/initialization.
746  * Defined in freeglut_structure.c, freeglut_window.c.
747  */
748 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
749                             int x, int y, int w, int h,
750                             GLboolean gameMode, GLboolean isMenu );
751 void        fgSetWindow ( SFG_Window *window );
752 void        fgOpenWindow( SFG_Window* window, const char* title,
753                           int x, int y, int w, int h, GLboolean gameMode,
754                           GLboolean isSubWindow );
755 void        fgCloseWindow( SFG_Window* window );
756 void        fgAddToWindowDestroyList ( SFG_Window* window );
757 void        fgCloseWindows ();
758 void        fgDestroyWindow( SFG_Window* window );
759 void        fgClearCallBacks( SFG_Window *window );
760
761 /*
762  * Menu creation and destruction. Defined in freeglut_structure.c
763  */
764 SFG_Menu*   fgCreateMenu( FGCBMenu menuCallback );
765 void        fgDestroyMenu( SFG_Menu* menu );
766
767 /*
768  * Joystick device management functions, defined in freeglut_joystick.c
769  */
770 void        fgJoystickInit( int ident );
771 void        fgJoystickClose( void );
772 void        fgJoystickPollWindow( SFG_Window* window );
773
774 /*
775  * Helper function to enumerate through all registered windows
776  * and one to enumerate all of a window's subwindows...
777  *
778  * The GFunc callback for those functions will be defined as:
779  *
780  *      void enumCallback( gpointer window, gpointer enumerator );
781  *
782  * where window is the enumerated (sub)window pointer (SFG_Window *),
783  * and userData is the a custom user-supplied pointer. Functions
784  * are defined and exported from freeglut_structure.c file.
785  */
786 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
787 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
788                        SFG_Enumerator* enumerator );
789
790 /*
791  * fgWindowByHandle returns a (SFG_Window *) value pointing to the
792  * first window in the queue matching the specified window handle.
793  * The function is defined in freeglut_structure.c file.
794  */
795 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
796
797 /*
798  * This function is similiar to the previous one, except it is
799  * looking for a specified (sub)window identifier. The function
800  * is defined in freeglut_structure.c file.
801  */
802 SFG_Window* fgWindowByID( int windowID );
803
804 /*
805  * Looks up a menu given its ID. This is easier than fgWindowByXXX
806  * as all menus are placed in a single doubly linked list...
807  */
808 SFG_Menu* fgMenuByID( int menuID );
809
810 /*
811  * The menu activation and deactivation the code. This is the meat
812  * of the menu user interface handling code...
813  */
814 void fgActivateMenu( SFG_Window* window, int button );
815 void fgExecuteMenuCallback( SFG_Menu* menu );
816 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
817 void fgDeactivateMenu( SFG_Window *window );
818 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
819
820 /*
821  * This function gets called just before the buffers swap, so that
822  * freeglut can display the pull-down menus via OpenGL. The function
823  * is defined in freeglut_menu.c file.
824  */
825 void fgDisplayMenu( void );
826
827 /*
828  * Display the mouse cursor using OpenGL calls. The function
829  * is defined in freeglut_cursor.c file.
830  */
831 void fgDisplayCursor( void );
832
833 /*
834  * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
835  */
836 long fgElapsedTime( void );
837
838 /*
839  * List functions
840  */
841 void fgListInit(SFG_List *list);
842 void fgListAppend(SFG_List *list, SFG_Node *node);
843 void fgListRemove(SFG_List *list, SFG_Node *node);
844 int fgListLength(SFG_List *list);
845 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);
846
847 /*
848  * Error Messages functions
849  */
850 void fgError( const char *fmt, ... );
851 void fgWarning( const char *fmt, ... );
852
853 #endif /* FREEGLUT_INTERNAL_H */
854
855 /*** END OF FILE ***/