4 * The freeglut library private include file.
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
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:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
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.
28 #ifndef FREEGLUT_INTERNAL_H
29 #define FREEGLUT_INTERNAL_H
35 /* XXX Update these for each release! */
36 #define VERSION_MAJOR 3
37 #define VERSION_MINOR 0
38 #define VERSION_PATCH 0
40 /* Freeglut is intended to function under all Unix/X11 and Win32 platforms. */
41 /* XXX: Don't all MS-Windows compilers (except Cygwin) have _WIN32 defined?
42 * XXX: If so, remove the first set of defined()'s below.
44 #if !defined(TARGET_HOST_POSIX_X11) && !defined(TARGET_HOST_MS_WINDOWS) && !defined(TARGET_HOST_MAC_OSX) && !defined(TARGET_HOST_SOLARIS)
45 #if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__) \
46 || defined(_WIN32) || defined(_WIN32_WCE) \
47 || ( defined(__CYGWIN__) && defined(X_DISPLAY_MISSING) )
48 # define TARGET_HOST_MS_WINDOWS 1
50 #elif defined (ANDROID)
51 # define TARGET_HOST_ANDROID 1
53 #elif defined(__posix__) || defined(__unix__) || defined(__linux__) || defined(__sun)
54 # define TARGET_HOST_POSIX_X11 1
56 #elif defined(__APPLE__)
57 /* This is a placeholder until we get native OSX support ironed out -- JFF 11/18/09 */
58 # define TARGET_HOST_POSIX_X11 1
59 /* # define TARGET_HOST_MAC_OSX 1 */
62 # error "Unrecognized target host!"
67 /* Detect both SunPro and gcc compilers on Sun Solaris */
68 #if defined (__SVR4) && defined (__sun)
69 # define TARGET_HOST_SOLARIS 1
72 #ifndef TARGET_HOST_MS_WINDOWS
73 # define TARGET_HOST_MS_WINDOWS 0
76 #ifndef TARGET_HOST_POSIX_X11
77 # define TARGET_HOST_POSIX_X11 0
80 #ifndef TARGET_HOST_MAC_OSX
81 # define TARGET_HOST_MAC_OSX 0
84 #ifndef TARGET_HOST_SOLARIS
85 # define TARGET_HOST_SOLARIS 0
88 /* -- FIXED CONFIGURATION LIMITS ------------------------------------------- */
90 #define FREEGLUT_MAX_MENUS 3
92 /* These files should be available on every platform. */
99 /* These are included based on autoconf directives. */
100 #ifdef HAVE_SYS_TYPES_H
101 # include <sys/types.h>
106 #ifdef TIME_WITH_SYS_TIME
107 # include <sys/time.h>
109 #elif defined(HAVE_SYS_TIME_H)
110 # include <sys/time.h>
115 /* -- AUTOCONF HACKS --------------------------------------------------------*/
117 /* XXX: Update autoconf to avoid these.
118 * XXX: Are non-POSIX platforms intended not to use autoconf?
119 * If so, perhaps there should be a config_guess.h for them. Alternatively,
120 * config guesses could be placed above, just after the config.h exclusion.
122 #if defined(__FreeBSD__) || defined(__NetBSD__)
123 # define HAVE_USB_JS 1
124 # if defined(__NetBSD__) || ( defined(__FreeBSD__) && __FreeBSD_version >= 500000)
125 # define HAVE_USBHID_H 1
129 #if defined(_MSC_VER) || defined(__WATCOMC__)
130 /* strdup() is non-standard, for all but POSIX-2001 */
131 #define strdup _strdup
134 /* M_PI is non-standard (defined by BSD, not ISO-C) */
136 # define M_PI 3.14159265358979323846
139 #ifdef HAVE_STDBOOL_H
140 # include <stdbool.h>
156 /* General defines */
157 #define INVALID_MODIFIERS 0xffffffff
159 /* FreeGLUT internal time type */
160 #if defined(HAVE_STDINT_H)
162 typedef uint64_t fg_time_t;
163 #elif defined(HAVE_INTTYPES_H)
164 # include <inttypes.h>
165 typedef uint64_t fg_time_t;
166 #elif defined(HAVE_ULONG_LONG)
167 typedef unsigned long long fg_time_t;
169 typedef unsigned long fg_time_t;
174 /* Platform-specific includes */
175 #if TARGET_HOST_POSIX_X11
176 #include "x11/fg_internal_x11.h"
178 #if TARGET_HOST_MS_WINDOWS
179 #include "mswin/fg_internal_mswin.h"
181 #if TARGET_HOST_ANDROID
182 #include "android/fg_internal_android.h"
186 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
188 /* Freeglut callbacks type definitions */
189 typedef void (* FGCBDisplay )( void );
190 typedef void (* FGCBReshape )( int, int );
191 typedef void (* FGCBVisibility )( int );
192 typedef void (* FGCBKeyboard )( unsigned char, int, int );
193 typedef void (* FGCBSpecial )( int, int, int );
194 typedef void (* FGCBMouse )( int, int, int, int );
195 typedef void (* FGCBMouseWheel )( int, int, int, int );
196 typedef void (* FGCBMotion )( int, int );
197 typedef void (* FGCBPassive )( int, int );
198 typedef void (* FGCBEntry )( int );
199 typedef void (* FGCBWindowStatus )( int );
200 typedef void (* FGCBSelect )( int, int, int );
201 typedef void (* FGCBJoystick )( unsigned int, int, int, int );
202 typedef void (* FGCBKeyboardUp )( unsigned char, int, int );
203 typedef void (* FGCBSpecialUp )( int, int, int );
204 typedef void (* FGCBOverlayDisplay)( void );
205 typedef void (* FGCBSpaceMotion )( int, int, int );
206 typedef void (* FGCBSpaceRotation )( int, int, int );
207 typedef void (* FGCBSpaceButton )( int, int );
208 typedef void (* FGCBDials )( int, int );
209 typedef void (* FGCBButtonBox )( int, int );
210 typedef void (* FGCBTabletMotion )( int, int );
211 typedef void (* FGCBTabletButton )( int, int, int, int );
212 typedef void (* FGCBDestroy )( void );
214 typedef void (* FGCBMultiEntry )( int, int );
215 typedef void (* FGCBMultiButton )( int, int, int, int, int );
216 typedef void (* FGCBMultiMotion )( int, int, int );
217 typedef void (* FGCBMultiPassive )( int, int, int );
219 /* The global callbacks type definitions */
220 typedef void (* FGCBIdle )( void );
221 typedef void (* FGCBTimer )( int );
222 typedef void (* FGCBMenuState )( int );
223 typedef void (* FGCBMenuStatus )( int, int, int );
225 /* The callback used when creating/using menus */
226 typedef void (* FGCBMenu )( int );
228 /* The FreeGLUT error/warning handler type definition */
229 typedef void (* FGError ) ( const char *fmt, va_list ap);
230 typedef void (* FGWarning ) ( const char *fmt, va_list ap);
233 /* A list structure */
234 typedef struct tagSFG_List SFG_List;
241 /* A list node structure */
242 typedef struct tagSFG_Node SFG_Node;
249 /* A helper structure holding two ints and a boolean */
250 typedef struct tagSFG_XYUse SFG_XYUse;
253 GLint X, Y; /* The two integers... */
254 GLboolean Use; /* ...and a single boolean. */
258 * An enumeration containing the state of the GLUT execution:
259 * initializing, running, or stopping
263 GLUT_EXEC_STATE_INIT,
264 GLUT_EXEC_STATE_RUNNING,
268 /* This structure holds different freeglut settings */
269 typedef struct tagSFG_State SFG_State;
272 SFG_XYUse Position; /* The default windows' position */
273 SFG_XYUse Size; /* The default windows' size */
274 unsigned int DisplayMode; /* Display mode for new windows */
276 GLboolean Initialised; /* freeglut has been initialised */
278 int DirectContext; /* Direct rendering state */
280 GLboolean ForceIconic; /* New top windows are iconified */
281 GLboolean UseCurrentContext; /* New windows share with current */
283 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
284 GLboolean XSyncSwitch; /* X11 sync protocol switch */
286 int KeyRepeat; /* Global key repeat mode. */
287 int Modifiers; /* Current ALT/SHIFT/CTRL state */
289 GLuint FPSInterval; /* Interval between FPS printfs */
290 GLuint SwapCount; /* Count of glutSwapBuffer calls */
291 GLuint SwapTime; /* Time of last SwapBuffers */
293 fg_time_t Time; /* Time that glutInit was called */
294 SFG_List Timers; /* The freeglut timer hooks */
295 SFG_List FreeTimers; /* The unused timer hooks */
297 FGCBIdle IdleCallback; /* The global idle callback */
299 int ActiveMenus; /* Num. of currently active menus */
300 FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
301 FGCBMenuStatus MenuStatusCallback;
303 SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
304 int GameModeDepth; /* The pixel depth for game mode */
305 int GameModeRefresh; /* The refresh rate for game mode */
307 int ActionOnWindowClose; /* Action when user closes window */
309 fgExecutionState ExecState; /* Used for GLUT termination */
310 char *ProgramName; /* Name of the invoking program */
311 GLboolean JoysticksInitialised; /* Only initialize if application calls for them */
312 int NumActiveJoysticks; /* Number of active joysticks -- if zero, don't poll joysticks */
313 GLboolean InputDevsInitialised; /* Only initialize if application calls for them */
315 int MouseWheelTicks; /* Number of ticks the mouse wheel has turned */
317 int AuxiliaryBufferNumber; /* Number of auxiliary buffers */
318 int SampleNumber; /* Number of samples per pixel */
320 int MajorVersion; /* Major OpenGL context version */
321 int MinorVersion; /* Minor OpenGL context version */
322 int ContextFlags; /* OpenGL context flags */
323 int ContextProfile; /* OpenGL context profile */
324 FGError ErrorFunc; /* User defined error handler */
325 FGWarning WarningFunc; /* User defined warning handler */
328 /* The structure used by display initialization in freeglut_init.c */
329 typedef struct tagSFG_Display SFG_Display;
330 struct tagSFG_Display
332 SFG_PlatformDisplay pDisplay;
334 int ScreenWidth; /* The screen's width in pixels */
335 int ScreenHeight; /* The screen's height in pixels */
336 int ScreenWidthMM; /* The screen's width in milimeters */
337 int ScreenHeightMM; /* The screen's height in milimeters */
341 /* The user can create any number of timer hooks */
342 typedef struct tagSFG_Timer SFG_Timer;
346 int ID; /* The timer ID integer */
347 FGCBTimer Callback; /* The timer callback */
348 fg_time_t TriggerTime; /* The timer trigger time */
352 * A window and its OpenGL context. The contents of this structure
353 * are highly dependant on the target operating system we aim at...
355 typedef struct tagSFG_Context SFG_Context;
356 struct tagSFG_Context
358 SFG_WindowHandleType Handle; /* The window's handle */
359 SFG_WindowContextType Context; /* The window's OpenGL/WGL context */
361 SFG_PlatformContext pContext; /* The window's FBConfig (X11) or device context (Windows) */
363 int DoubleBuffered; /* Treat the window as double-buffered */
367 typedef struct tagSFG_WindowState SFG_WindowState;
368 struct tagSFG_WindowState
370 /* Note that on Windows, sizes always refer to the client area, thus without the window decorations */
371 int Width; /* Window's width in pixels */
372 int Height; /* The same about the height */
374 SFG_PlatformWindowState pWState; /* Window width/height (X11) or rectangle/style (Windows) from before a resize */
376 GLboolean Redisplay; /* Do we have to redisplay? */
377 GLboolean Visible; /* Is the window visible now */
379 int Cursor; /* The currently selected cursor */
381 long JoystickPollRate; /* The joystick polling rate */
382 fg_time_t JoystickLastPoll; /* When the last poll happened */
384 int MouseX, MouseY; /* The most recent mouse position */
386 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */
387 GLboolean KeyRepeating; /* Currently in repeat mode */
389 GLboolean NeedToResize; /* Do we need to resize the window? */
391 GLboolean IsFullscreen; /* is the window fullscreen? */
396 * A generic function pointer. We should really use the GLUTproc type
397 * defined in freeglut_ext.h, but if we include that header in this file
398 * a bunch of other stuff (font-related) blows up!
400 typedef void (*SFG_Proc)();
404 * SET_WCB() is used as:
406 * SET_WCB( window, cbname, func );
408 * ...where {window} is the freeglut window to set the callback,
409 * {cbname} is the window-specific callback to set,
410 * {func} is a function-pointer.
412 * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,
413 * but this can cause warnings because the FETCH_WCB() macro type-
414 * casts its result, and a type-cast value shouldn't be an lvalue.
416 * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking
417 * and for no other reason. Since it's hidden in the macro, the
418 * ugliness is felt to be rather benign.
420 #define SET_WCB(window,cbname,func) \
423 if( FETCH_WCB( window, cbname ) != (SFG_Proc)(func) ) \
424 (((window).CallBacks[CB_ ## cbname]) = (SFG_Proc)(func)); \
428 * FETCH_WCB() is used as:
430 * FETCH_WCB( window, cbname );
432 * ...where {window} is the freeglut window to fetch the callback from,
433 * {cbname} is the window-specific callback to fetch.
435 * The result is correctly type-cast to the callback function pointer
438 #define FETCH_WCB(window,cbname) \
439 ((window).CallBacks[CB_ ## cbname])
442 * INVOKE_WCB() is used as:
444 * INVOKE_WCB( window, cbname, ( arg_list ) );
446 * ...where {window} is the freeglut window,
447 * {cbname} is the window-specific callback to be invoked,
448 * {(arg_list)} is the parameter list.
450 * The callback is invoked as:
452 * callback( arg_list );
454 * ...so the parentheses are REQUIRED in the {arg_list}.
456 * NOTE that it does a sanity-check and also sets the
460 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: also WinCE? */
461 #define INVOKE_WCB(window,cbname,arg_list) \
464 if( FETCH_WCB( window, cbname ) ) \
466 FGCB ## cbname func = (FGCB ## cbname)(FETCH_WCB( window, cbname )); \
467 fgSetWindow( &window ); \
472 #define INVOKE_WCB(window,cbname,arg_list) \
475 if( FETCH_WCB( window, cbname ) ) \
477 fgSetWindow( &window ); \
478 ((FGCB ## cbname)FETCH_WCB( window, cbname )) arg_list; \
484 * The window callbacks the user can supply us with. Should be kept portable.
486 * This enumeration provides the freeglut CallBack numbers.
487 * The symbolic constants are indices into a window's array of
488 * function callbacks. The names are formed by splicing a common
489 * prefix onto the callback's base name. (This was originally
490 * done so that an early stage of development could live side-by-
491 * side with the old callback code. The old callback code used
492 * the bare callback's name as a structure member, so I used a
493 * prefix for the array index name.)
495 * XXX For consistancy, perhaps the prefix should match the
496 * XXX FETCH* and INVOKE* macro suffices. I.e., WCB_, rather than
523 /* Presently ignored */
526 CB_SpaceMotion, /* presently implemented only on UNIX/X11 */
527 CB_SpaceRotation, /* presently implemented only on UNIX/X11 */
528 CB_SpaceButton, /* presently implemented only on UNIX/X11 */
534 /* Always make this the LAST one */
539 /* This structure holds the OpenGL rendering context for all the menu windows */
540 typedef struct tagSFG_MenuContext SFG_MenuContext;
541 struct tagSFG_MenuContext
543 SFG_WindowContextType MContext; /* The menu window's WGL context */
546 /* This structure describes a menu */
547 typedef struct tagSFG_Window SFG_Window;
548 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
549 typedef struct tagSFG_Menu SFG_Menu;
553 void *UserData; /* User data passed back at callback */
554 int ID; /* The global menu ID */
555 SFG_List Entries; /* The menu entries list */
556 FGCBMenu Callback; /* The menu callback */
557 FGCBDestroy Destroy; /* Destruction callback */
558 GLboolean IsActive; /* Is the menu selected? */
559 int Width; /* Menu box width in pixels */
560 int Height; /* Menu box height in pixels */
561 int X, Y; /* Menu box raster position */
563 SFG_MenuEntry *ActiveEntry; /* Currently active entry in the menu */
564 SFG_Window *Window; /* Window for menu */
565 SFG_Window *ParentWindow; /* Window in which the menu is invoked */
568 /* This is a menu entry */
569 struct tagSFG_MenuEntry
572 int ID; /* The menu entry ID (local) */
573 int Ordinal; /* The menu's ordinal number */
574 char* Text; /* The text to be displayed */
575 SFG_Menu* SubMenu; /* Optional sub-menu tree */
576 GLboolean IsActive; /* Is the entry highlighted? */
577 int Width; /* Label's width in pixels */
581 * A window, making part of freeglut windows hierarchy.
582 * Should be kept portable.
584 * NOTE that ActiveMenu is set to menu itself if the window is a menu.
589 int ID; /* Window's ID number */
591 SFG_Context Window; /* Window and OpenGL context */
592 SFG_WindowState State; /* The window state */
593 SFG_Proc CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
594 void *UserData ; /* For use by user */
596 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
597 SFG_Menu* ActiveMenu; /* The window's active menu */
599 SFG_Window* Parent; /* The parent to this window */
600 SFG_List Children; /* The subwindows d.l. list */
602 GLboolean IsMenu; /* Set to 1 if we are a menu */
606 /* A linked list structure of windows */
607 typedef struct tagSFG_WindowList SFG_WindowList ;
608 struct tagSFG_WindowList
614 /* This holds information about all the windows, menus etc. */
615 typedef struct tagSFG_Structure SFG_Structure;
616 struct tagSFG_Structure
618 SFG_List Windows; /* The global windows list */
619 SFG_List Menus; /* The global menus list */
620 SFG_List WindowsToDestroy;
622 SFG_Window* CurrentWindow; /* The currently set window */
623 SFG_Menu* CurrentMenu; /* Same, but menu... */
625 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
627 SFG_Window* GameModeWindow; /* The game mode window */
629 int WindowID; /* The new current window ID */
630 int MenuID; /* The new current menu ID */
634 * This structure is used for the enumeration purposes.
635 * You can easily extend its functionalities by declaring
636 * a structure containing enumerator's contents and custom
637 * data, then casting its pointer to (SFG_Enumerator *).
639 typedef struct tagSFG_Enumerator SFG_Enumerator;
640 struct tagSFG_Enumerator
642 GLboolean found; /* Used to terminate search */
643 void* data; /* Custom data pointer */
645 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
647 /* The bitmap font structure */
648 typedef struct tagSFG_Font SFG_Font;
651 char* Name; /* The source font name */
652 int Quantity; /* Number of chars in font */
653 int Height; /* Height of the characters */
654 const GLubyte** Characters; /* The characters mapping */
656 float xorig, yorig; /* Relative origin of the character */
659 /* The stroke font structures */
661 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
662 struct tagSFG_StrokeVertex
667 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
668 struct tagSFG_StrokeStrip
671 const SFG_StrokeVertex* Vertices;
674 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
675 struct tagSFG_StrokeChar
679 const SFG_StrokeStrip* Strips;
682 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
683 struct tagSFG_StrokeFont
685 char* Name; /* The source font name */
686 int Quantity; /* Number of chars in font */
687 GLfloat Height; /* Height of the characters */
688 const SFG_StrokeChar** Characters; /* The characters mapping */
692 /* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */
694 * Initial defines from "js.h" starting around line 33 with the existing "freeglut_joystick.c"
698 #if TARGET_HOST_MACINTOSH
699 # include <InputSprocket.h>
702 #if TARGET_HOST_MAC_OSX
703 # include <mach/mach.h>
704 # include <IOKit/IOkitLib.h>
705 # include <IOKit/hid/IOHIDLib.h>
708 /* XXX It might be better to poll the operating system for the numbers of buttons and
709 * XXX axes and then dynamically allocate the arrays.
711 #define _JS_MAX_BUTTONS 32
713 #if TARGET_HOST_MACINTOSH
714 # define _JS_MAX_AXES 9
715 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
716 struct tagSFG_PlatformJoystick
718 #define ISP_NUM_AXIS 9
719 #define ISP_NUM_NEEDS 41
720 ISpElementReference isp_elem [ ISP_NUM_NEEDS ];
721 ISpNeed isp_needs [ ISP_NUM_NEEDS ];
725 #if TARGET_HOST_MAC_OSX
726 # define _JS_MAX_AXES 16
727 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
728 struct tagSFG_PlatformJoystick
730 IOHIDDeviceInterface ** hidDev;
731 IOHIDElementCookie buttonCookies[41];
732 IOHIDElementCookie axisCookies[_JS_MAX_AXES];
733 /* The next two variables are not used anywhere */
734 /* long minReport[_JS_MAX_AXES],
735 * maxReport[_JS_MAX_AXES];
742 * Definition of "SFG_Joystick" structure -- based on JS's "jsJoystick" object class.
743 * See "js.h" lines 80-178.
745 typedef struct tagSFG_Joystick SFG_Joystick;
746 struct tagSFG_Joystick
748 SFG_PlatformJoystick pJoystick;
756 float dead_band[ _JS_MAX_AXES ];
757 float saturate [ _JS_MAX_AXES ];
758 float center [ _JS_MAX_AXES ];
759 float max [ _JS_MAX_AXES ];
760 float min [ _JS_MAX_AXES ];
765 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
767 /* Freeglut display related stuff (initialized once per session) */
768 extern SFG_Display fgDisplay;
770 /* Freeglut internal structure */
771 extern SFG_Structure fgStructure;
773 /* The current freeglut settings */
774 extern SFG_State fgState;
777 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
780 * A call to this function makes us sure that the Display and Structure
781 * subsystems have been properly initialized and are ready to be used
783 #define FREEGLUT_EXIT_IF_NOT_INITIALISED( string ) \
784 if ( ! fgState.Initialised ) \
786 fgError ( " ERROR: Function <%s> called" \
787 " without first calling 'glutInit'.", (string) ) ; \
790 #define FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED( string ) \
791 if ( ! fgState.Initialised ) \
793 fgError ( " ERROR: Internal <%s> function called" \
794 " without first calling 'glutInit'.", (string) ) ; \
797 #define FREEGLUT_INTERNAL_ERROR_EXIT( cond, string, function ) \
800 fgError ( " ERROR: Internal error <%s> in function %s", \
801 (string), (function) ) ; \
805 * Following definitions are somewhat similiar to GLib's,
806 * but do not generate any log messages:
808 #define freeglut_return_if_fail( expr ) \
811 #define freeglut_return_val_if_fail( expr, val ) \
816 * A call to those macros assures us that there is a current
817 * window set, respectively:
819 #define FREEGLUT_EXIT_IF_NO_WINDOW( string ) \
820 if ( ! fgStructure.CurrentWindow && \
821 ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION ) ) \
823 fgError ( " ERROR: Function <%s> called" \
824 " with no current window defined.", (string) ) ; \
828 * The deinitialize function gets called on glutMainLoop() end. It should clean up
829 * everything inside of the freeglut
831 void fgDeinitialize( void );
834 * Those two functions are used to create/destroy the freeglut internal
835 * structures. This actually happens when calling glutInit() and when
836 * quitting the glutMainLoop() (which actually happens, when all windows
839 void fgCreateStructure( void );
840 void fgDestroyStructure( void );
843 * Window creation, opening, closing and destruction.
844 * Also CallBack clearing/initialization.
845 * Defined in freeglut_structure.c, freeglut_window.c.
847 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
848 GLboolean positionUse, int x, int y,
849 GLboolean sizeUse, int w, int h,
850 GLboolean gameMode, GLboolean isMenu );
851 void fgSetWindow ( SFG_Window *window );
852 void fgOpenWindow( SFG_Window* window, const char* title,
853 GLboolean positionUse, int x, int y,
854 GLboolean sizeUse, int w, int h,
855 GLboolean gameMode, GLboolean isSubWindow );
856 void fgCloseWindow( SFG_Window* window );
857 void fgAddToWindowDestroyList ( SFG_Window* window );
858 void fgCloseWindows ();
859 void fgDestroyWindow( SFG_Window* window );
861 /* Menu creation and destruction. Defined in freeglut_structure.c */
862 SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
863 void fgDestroyMenu( SFG_Menu* menu );
865 /* Joystick device management functions, defined in freeglut_joystick.c */
866 int fgJoystickDetect( void );
867 void fgInitialiseJoysticks( void );
868 void fgJoystickClose( void );
869 void fgJoystickPollWindow( SFG_Window* window );
871 /* InputDevice Initialisation and Closure */
872 int fgInputDeviceDetect( void );
873 void fgInitialiseInputDevices( void );
874 void fgInputDeviceClose( void );
876 /* spaceball device functions, defined in freeglut_spaceball.c */
877 void fgInitialiseSpaceball( void );
878 void fgSpaceballClose( void );
879 void fgSpaceballSetWindow( SFG_Window *window );
881 int fgHasSpaceball( void );
882 int fgSpaceballNumButtons( void );
884 /* Setting the cursor for a given window */
885 void fgSetCursor ( SFG_Window *window, int cursorID );
888 * Helper function to enumerate through all registered windows
889 * and one to enumerate all of a window's subwindows...
891 * The GFunc callback for those functions will be defined as:
893 * void enumCallback( gpointer window, gpointer enumerator );
895 * where window is the enumerated (sub)window pointer (SFG_Window *),
896 * and userData is the a custom user-supplied pointer. Functions
897 * are defined and exported from freeglut_structure.c file.
899 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
900 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
901 SFG_Enumerator* enumerator );
904 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
905 * first window in the queue matching the specified window handle.
906 * The function is defined in freeglut_structure.c file.
908 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
911 * This function is similiar to the previous one, except it is
912 * looking for a specified (sub)window identifier. The function
913 * is defined in freeglut_structure.c file.
915 SFG_Window* fgWindowByID( int windowID );
918 * Looks up a menu given its ID. This is easier than fgWindowByXXX
919 * as all menus are placed in a single doubly linked list...
921 SFG_Menu* fgMenuByID( int menuID );
924 * The menu activation and deactivation the code. This is the meat
925 * of the menu user interface handling code...
927 void fgUpdateMenuHighlight ( SFG_Menu *menu );
928 GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
929 int mouse_x, int mouse_y );
930 void fgDeactivateMenu( SFG_Window *window );
933 * This function gets called just before the buffers swap, so that
934 * freeglut can display the pull-down menus via OpenGL. The function
935 * is defined in freeglut_menu.c file.
937 void fgDisplayMenu( void );
939 /* Elapsed time as per glutGet(GLUT_ELAPSED_TIME). */
940 fg_time_t fgElapsedTime( void );
942 /* System time in milliseconds */
943 fg_time_t fgSystemTime(void);
946 void fgListInit(SFG_List *list);
947 void fgListAppend(SFG_List *list, SFG_Node *node);
948 void fgListRemove(SFG_List *list, SFG_Node *node);
949 int fgListLength(SFG_List *list);
950 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);
952 /* Error Message functions */
953 void fgError( const char *fmt, ... );
954 void fgWarning( const char *fmt, ... );
956 SFG_Proc fgPlatformGetProcAddress( const char *procName );
958 /* pushing attribute/value pairs into an array */
959 #define ATTRIB(a) attributes[where++]=(a)
960 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
962 int fghIsLegacyContextVersionRequested( void );
963 int fghMapBit( int mask, int from, int to );
964 int fghIsLegacyContextRequested( void );
965 void fghContextCreationError( void );
966 int fghNumberOfAuxBuffersRequested( void );
968 #endif /* FREEGLUT_INTERNAL_H */
970 /*** END OF FILE ***/