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