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