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