More work from John (sorry for procrastinating):
[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 0
34 #define  VERSION_PATCH 2 
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
243     FGCBIdle         IdleCallback;         /* The global idle callback       */
244
245     int              ActiveMenus;          /* Num. of currently active menus */
246     FGCBMenuState    MenuStateCallback;    /* Menu callbacks are global      */
247     FGCBMenuStatus   MenuStatusCallback;
248
249     SFG_XYUse        GameModeSize;         /* Game mode screen's dimensions  */
250     int              GameModeDepth;        /* The pixel depth for game mode  */
251     int              GameModeRefresh;      /* The refresh rate for game mode */
252
253     int              ActionOnWindowClose; /* Action when user closes window  */
254
255     fgExecutionState ExecState;           /* Used for GLUT termination       */
256     char            *ProgramName;         /* Name of the invoking program    */
257 };
258
259 /*
260  * The structure used by display initialization in freeglut_init.c
261  */
262 typedef struct tagSFG_Display SFG_Display;
263 struct tagSFG_Display
264 {
265 #if TARGET_HOST_UNIX_X11
266     Display*        Display;            /* The display we are being run in.  */
267     int             Screen;             /* The screen we are about to use.   */
268     Window          RootWindow;         /* The screen's root window.         */
269     int             Connection;         /* The display's connection number   */
270     Atom            DeleteWindow;       /* The window deletion atom          */
271
272 #ifdef X_XF86VidModeGetModeLine
273     /*
274      * XF86VidMode may be compilable even if it fails at runtime.  Therefore,
275      * the validity of the VidMode has to be tracked
276      */
277     int             DisplayModeValid;   /* Flag that indicates runtime status*/
278     XF86VidModeModeLine DisplayMode;    /* Current screen's display settings */
279     int             DisplayModeClock;   /* The display mode's refresh rate   */
280     int             DisplayViewPortX;   /* saved X location of the viewport  */
281     int             DisplayViewPortY;   /* saved Y location of the viewport  */
282     int             DisplayPointerX;    /* saved X location of the pointer   */
283     int             DisplayPointerY;    /* saved Y location of the pointer   */
284
285 #endif
286
287 #elif TARGET_HOST_WIN32
288     HINSTANCE        Instance;          /* The application's instance        */
289     DEVMODE         DisplayMode;        /* Desktop's display settings        */
290
291 #endif
292
293     int             ScreenWidth;        /* The screen's width in pixels      */
294     int             ScreenHeight;       /* The screen's height in pixels     */
295     int             ScreenWidthMM;      /* The screen's width in milimeters  */
296     int             ScreenHeightMM;     /* The screen's height in milimeters */
297 };
298
299
300 /*
301  * The user can create any number of timer hooks
302  */
303 typedef struct tagSFG_Timer SFG_Timer;
304 struct tagSFG_Timer
305 {
306     SFG_Node        Node;
307     int             ID;                 /* The timer ID integer              */
308     FGCBTimer       Callback;           /* The timer callback                */
309     long            TriggerTime;        /* The timer trigger time            */
310 };
311
312 /*
313  * Make "freeglut" window handle and context types so that we don't need so
314  * much conditionally-compiled code later in the library.
315  */
316 #if TARGET_HOST_UNIX_X11
317
318 typedef Window     SFG_WindowHandleType ;
319 typedef GLXContext SFG_WindowContextType ;
320
321 #elif TARGET_HOST_WIN32
322
323 typedef HWND    SFG_WindowHandleType ;
324 typedef HGLRC   SFG_WindowContextType ;
325
326 #endif
327
328 /*
329  * A window and its OpenGL context. The contents of this structure
330  * are highly dependant on the target operating system we aim at...
331  */
332 typedef struct tagSFG_Context SFG_Context;
333 struct tagSFG_Context
334 {
335     SFG_WindowHandleType  Handle;    /* The window's handle                 */
336     SFG_WindowContextType Context;   /* The window's OpenGL/WGL context     */
337
338 #if TARGET_HOST_UNIX_X11
339     XVisualInfo*    VisualInfo;      /* The window's visual information     */
340 #elif TARGET_HOST_WIN32
341     HDC             Device;          /* The window's device context         */
342 #endif
343
344     int             DoubleBuffered;  /* Treat the window as double-buffered */
345 };
346
347 /*
348  * Window's state description. This structure should be kept portable.
349  */
350 typedef struct tagSFG_WindowState SFG_WindowState;
351 struct tagSFG_WindowState
352 {
353     int             Width;              /* Window's width in pixels          */
354     int             Height;             /* The same about the height         */
355
356     GLboolean       Redisplay;          /* Do we have to redisplay?          */
357     GLboolean       Visible;            /* Is the window visible now         */
358
359     int             Cursor;             /* The currently selected cursor     */
360
361     long            JoystickPollRate;   /* The joystick polling rate         */
362     long            JoystickLastPoll;   /* When the last poll has happened   */
363
364     int             MouseX, MouseY;     /* The most recent mouse position    */
365
366     GLboolean       IsGameMode;         /* Is this the game mode window?     */
367
368     GLboolean       NeedToResize;       /* Do we need to resize the window?  */
369 };
370
371
372 /*
373  * FETCH_WCB() is used as:
374  *
375  *     FETCH_WCB( window, Visibility );
376  *
377  * ...where {window} is the freeglut window to fetch the callback from,
378  *          {Visibility} is the window-specific callback to fetch.
379  *
380  * The result is correctly type-cast to the callback function pointer
381  * type.
382  */
383 #define FETCH_WCB(window,cbname) \
384     ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
385
386 /*
387  * INVOKE_WCB() is used as:
388  *
389  *     INVOKE_WCB( window, Visibility, ( status ) );
390  *
391  * ...where {window} is the freeglut window,
392  *          {Visibility} is the window-specific callback,
393  *          {(status)} is the parameter list.
394  *
395  * The callback is invoked as:
396  *
397  *    callback( status );
398  *
399  * ...so the parentheses are REQUIRED in the {arg_list}.
400  *
401  * NOTE that it does a sanity-check and also sets the
402  * current window.
403  *
404  */
405 #define INVOKE_WCB(window,cbname,arg_list)    \
406 do                                            \
407 {                                             \
408     if( FETCH_WCB( window, cbname ) )         \
409     {                                         \
410         fgSetWindow( &window );               \
411         FETCH_WCB( window, cbname ) arg_list; \
412     }                                         \
413 } while( 0 )
414
415 /*
416  * The window callbacks the user can supply us with. Should be kept portable.
417  *
418  * This enumeration provides the freeglut CallBack numbers.
419  * The symbolic constants are indices into a window's array of
420  * function callbacks.  The names are formed by splicing a common
421  * prefix onto the callback's base name.  (This was originally
422  * done so that an early stage of development could live side-by-
423  * side with the old callback code.  The old callback code used
424  * the bare callback's name as a structure member, so I used a
425  * prefix for the array index name.)
426  *
427  * XXX For consistancy, perhaps the prefix should match the
428  * XXX FETCH* and INVOKE* macro suffices.  I.e., WCB_, rather than
429  * XXX CB_.
430  */
431 enum
432 {
433     CB_Display,
434     CB_Reshape,
435     CB_Keyboard,
436     CB_KeyboardUp,
437     CB_Special,
438     CB_SpecialUp,
439     CB_Mouse,
440     CB_MouseWheel,
441     CB_Motion,
442     CB_Passive,
443     CB_Entry,
444     CB_Visibility,
445     CB_WindowStatus,
446     CB_Joystick,
447     CB_Destroy,
448
449     /* Presently ignored */
450     CB_Select,
451     CB_OverlayDisplay,
452     CB_SpaceMotion,
453     CB_SpaceRotation,
454     CB_SpaceButton,
455     CB_Dials,
456     CB_ButtonBox,
457     CB_TabletMotion,
458     CB_TabletButton,
459     
460     /* Always make this the LAST one */
461     TOTAL_CALLBACKS
462 };
463
464
465 /*
466  * This structure holds the OpenGL rendering context for all the menu windows
467  */
468 typedef struct tagSFG_MenuContext SFG_MenuContext;
469 struct tagSFG_MenuContext
470 {
471 #if TARGET_HOST_UNIX_X11
472     XVisualInfo*        VisualInfo;       /* The window's visual information */
473 #endif
474
475     SFG_WindowContextType Context;        /* The menu window's WGL context   */
476 };
477
478 /*
479  * This structure describes a menu
480  */
481 typedef struct tagSFG_Window SFG_Window;
482 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
483 typedef struct tagSFG_Menu SFG_Menu;
484 struct tagSFG_Menu
485 {
486     SFG_Node            Node;
487     void               *UserData;     /* User data passed back at callback   */
488     int                 ID;           /* The global menu ID                  */
489     SFG_List            Entries;      /* The menu entries list               */
490     FGCBMenu            Callback;     /* The menu callback                   */
491     FGCBDestroy         Destroy;      /* Destruction callback                */
492     GLboolean           IsActive;     /* Is the menu selected?               */
493     int                 Width;        /* Menu box width in pixels            */
494     int                 Height;       /* Menu box height in pixels           */
495     int                 X, Y;         /* Menu box raster position            */
496
497     SFG_MenuEntry      *ActiveEntry;  /* Currently active entry in the menu  */
498     SFG_Window         *Window;       /* Window for menu                     */
499     SFG_Window         *ParentWindow; /* Window in which the menu is defined */
500 };
501
502 /*
503  * This is a menu entry
504  */
505 struct tagSFG_MenuEntry
506 {
507     SFG_Node            Node;
508     int                 ID;                     /* The menu entry ID (local) */
509     int                 Ordinal;                /* The menu's ordinal number */
510     char*               Text;                   /* The text to be displayed  */
511     SFG_Menu*           SubMenu;                /* Optional sub-menu tree    */
512     GLboolean           IsActive;               /* Is the entry highlighted? */
513     int                 Width;                  /* Label's width in pixels   */
514 };
515
516 /*
517  * A window, making part of freeglut windows hierarchy.
518  * Should be kept portable.
519  */
520 struct tagSFG_Window
521 {
522     SFG_Node            Node;
523     int                 ID;                     /* Window's ID number        */
524
525     SFG_Context         Window;                 /* Window and OpenGL context */
526     SFG_WindowState     State;                  /* The window state          */
527     void         *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
528     void               *UserData ;              /* For use by user           */
529
530     SFG_Menu*       Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window  */
531     SFG_Menu*       ActiveMenu;                 /* The window's active menu  */
532
533     SFG_Window*         Parent;                 /* The parent to this window */
534     SFG_List            Children;               /* The subwindows d.l. list  */
535
536     GLboolean           IsMenu;                 /* Set to 1 if we are a menu */
537 };
538
539
540 /*
541  * A linked list structure of windows
542  */
543 typedef struct tagSFG_WindowList SFG_WindowList ;
544 struct tagSFG_WindowList
545 {
546     SFG_Window *window ;
547     GLboolean needToClose ;
548     SFG_WindowList *next ;
549 };
550
551 /*
552  * This holds information about all the windows, menus etc.
553  */
554 typedef struct tagSFG_Structure SFG_Structure;
555 struct tagSFG_Structure
556 {
557     SFG_List        Windows;      /* The global windows list            */
558     SFG_List        Menus;        /* The global menus list              */
559
560     SFG_Window*     Window;       /* The currently active win.          */
561     SFG_Menu*       Menu;         /* Same, but menu...                  */
562
563     SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
564
565     SFG_Window*      GameMode;    /* The game mode window               */
566
567     int              WindowID;    /* The new current window ID          */
568     int              MenuID;      /* The new current menu ID            */
569 };
570
571 /*
572  * This structure is used for the enumeration purposes.
573  * You can easily extend its functionalities by declaring
574  * a structure containing enumerator's contents and custom
575  * data, then casting its pointer to (SFG_Enumerator *).
576  */
577 typedef struct tagSFG_Enumerator SFG_Enumerator;
578 struct tagSFG_Enumerator
579 {
580     GLboolean   found;                          /* Used to terminate search  */
581     void*       data;                           /* Custom data pointer       */
582 };
583 typedef void (* FGCBenumerator  )( SFG_Window *, SFG_Enumerator * );
584
585 /*
586  * The bitmap font structure
587  */
588 typedef struct tagSFG_Font SFG_Font;
589 struct tagSFG_Font
590 {
591     char*           Name;         /* The source font name             */
592     int             Quantity;     /* Number of chars in font          */
593     int             Height;       /* Height of the characters         */
594     const GLubyte** Characters;   /* The characters mapping           */
595
596     float           xorig, yorig; /* Relative origin of the character */
597 };
598
599 /*
600  * The stroke font structures
601  */
602
603 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
604 struct tagSFG_StrokeVertex
605 {
606     GLfloat         X, Y;
607 };
608
609 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
610 struct tagSFG_StrokeStrip
611 {
612     int             Number;
613     const SFG_StrokeVertex* Vertices;
614 };
615
616 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
617 struct tagSFG_StrokeChar
618 {
619     GLfloat         Right;
620     int             Number;
621     const SFG_StrokeStrip* Strips;
622 };
623
624 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
625 struct tagSFG_StrokeFont
626 {
627     char*           Name;                       /* The source font name      */
628     int             Quantity;                   /* Number of chars in font   */
629     GLfloat         Height;                     /* Height of the characters  */
630     const SFG_StrokeChar** Characters;          /* The characters mapping    */
631 };
632
633 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
634
635 /*
636  * Freeglut display related stuff (initialized once per session)
637  */
638 extern SFG_Display fgDisplay;
639
640 /*
641  * Freeglut internal structure
642  */
643 extern SFG_Structure fgStructure;
644
645 /*
646  * The current freeglut settings
647  */
648 extern SFG_State fgState;
649
650
651 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
652
653 /*
654  * A call to this function makes us sure that the Display and Structure
655  * subsystems have been properly initialized and are ready to be used
656  */
657 #define  freeglut_assert_ready  assert( fgState.Initialised );
658
659 /*
660  * Following definitions are somewhat similiar to GLib's,
661  * but do not generate any log messages:
662  */
663 #define  freeglut_return_if_fail( expr ) \
664     if( !(expr) )                        \
665         return;
666 #define  freeglut_return_val_if_fail( expr, val ) \
667     if( !(expr) )                                 \
668         return val ;
669
670 /*
671  * A call to those macros assures us that there is a current
672  * window and menu set, respectively:
673  */
674 #define  freeglut_assert_window assert( fgStructure.Window != NULL );
675 #define  freeglut_assert_menu   assert( fgStructure.Menu != NULL );
676
677 /*
678  * The initialize and deinitialize functions get called on glutInit()
679  * and glutMainLoop() end respectively. They should create/clean up
680  * everything inside of the freeglut
681  */
682 void fgInitialize( const char* displayName );
683 void fgDeinitialize( void );
684
685 /*
686  * Those two functions are used to create/destroy the freeglut internal
687  * structures. This actually happens when calling glutInit() and when
688  * quitting the glutMainLoop() (which actually happens, when all windows
689  * have been closed).
690  */
691 void fgCreateStructure( void );
692 void fgDestroyStructure( void );
693
694 /*
695  * A helper function to check if a display mode is possible to use
696  */
697 #if TARGET_HOST_UNIX_X11
698 XVisualInfo* fgChooseVisual( void );
699 #endif
700
701 /*
702  * The window procedure for Win32 events handling
703  */
704 #if TARGET_HOST_WIN32
705 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
706                                WPARAM wParam, LPARAM lParam );
707 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
708                               unsigned char layer_type );
709 #endif
710
711 /*
712  * Window creation, opening, closing and destruction.
713  * Also CallBack clearing/initialization.
714  * Defined in freeglut_structure.c, freeglut_window.c.
715  */
716 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
717                             int x, int y, int w, int h,
718                             GLboolean gameMode, GLboolean isMenu );
719 void        fgSetWindow ( SFG_Window *window );
720 void        fgOpenWindow( SFG_Window* window, const char* title,
721                           int x, int y, int w, int h, GLboolean gameMode,
722                           GLboolean isSubWindow );
723 void        fgCloseWindow( SFG_Window* window );
724 void        fgAddToWindowDestroyList ( SFG_Window* window,
725                                        GLboolean needToClose );
726 void        fgCloseWindows ();
727 void        fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
728 void        fgClearCallBacks( SFG_Window *window );
729
730 /*
731  * Menu creation and destruction. Defined in freeglut_structure.c
732  */
733 SFG_Menu*   fgCreateMenu( FGCBMenu menuCallback );
734 void        fgDestroyMenu( SFG_Menu* menu );
735
736 /*
737  * Joystick device management functions, defined in freeglut_joystick.c
738  */
739 void        fgJoystickInit( int ident );
740 void        fgJoystickClose( void );
741 void        fgJoystickPollWindow( SFG_Window* window );
742
743 /*
744  * Helper function to enumerate through all registered windows
745  * and one to enumerate all of a window's subwindows...
746  *
747  * The GFunc callback for those functions will be defined as:
748  *
749  *      void enumCallback( gpointer window, gpointer enumerator );
750  *
751  * where window is the enumerated (sub)window pointer (SFG_Window *),
752  * and userData is the a custom user-supplied pointer. Functions
753  * are defined and exported from freeglut_structure.c file.
754  */
755 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
756 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
757                        SFG_Enumerator* enumerator );
758
759 /*
760  * fgWindowByHandle returns a (SFG_Window *) value pointing to the
761  * first window in the queue matching the specified window handle.
762  * The function is defined in freeglut_structure.c file.
763  */
764 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
765
766 /*
767  * This function is similiar to the previous one, except it is
768  * looking for a specified (sub)window identifier. The function
769  * is defined in freeglut_structure.c file.
770  */
771 SFG_Window* fgWindowByID( int windowID );
772
773 /*
774  * Looks up a menu given its ID. This is easier than fgWindowByXXX
775  * as all menus are placed in a single doubly linked list...
776  */
777 SFG_Menu* fgMenuByID( int menuID );
778
779 /*
780  * The menu activation and deactivation the code. This is the meat
781  * of the menu user interface handling code...
782  */
783 void fgActivateMenu( SFG_Window* window, int button );
784 void fgExecuteMenuCallback( SFG_Menu* menu );
785 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
786 void fgDeactivateMenu( SFG_Window *window );
787 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
788
789 /*
790  * This function gets called just before the buffers swap, so that
791  * freeglut can display the pull-down menus via OpenGL. The function
792  * is defined in freeglut_menu.c file.
793  */
794 void fgDisplayMenu( void );
795
796 /*
797  * Display the mouse cursor using OpenGL calls. The function
798  * is defined in freeglut_cursor.c file.
799  */
800 void fgDisplayCursor( void );
801
802 /*
803  * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
804  */
805 long fgElapsedTime( void );
806
807 /*
808  * List functions
809  */
810 void fgListInit(SFG_List *list);
811 void fgListAppend(SFG_List *list, SFG_Node *node);
812 void fgListRemove(SFG_List *list, SFG_Node *node);
813 int fgListLength(SFG_List *list);
814
815 /*
816  * Error Messages functions
817  */
818 void fgError( const char *fmt, ... );
819 void fgWarning( const char *fmt, ... );
820
821 #endif /* FREEGLUT_INTERNAL_H */
822
823 /*** END OF FILE ***/