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 #include "fg_version.h"
37 /* Freeglut is intended to function under all Unix/X11 and Win32 platforms. */
38 /* XXX: Don't all MS-Windows compilers (except Cygwin) have _WIN32 defined?
39 * XXX: If so, remove the first set of defined()'s below.
41 #if !defined(TARGET_HOST_POSIX_X11) && !defined(TARGET_HOST_MS_WINDOWS) && !defined(TARGET_HOST_MAC_OSX) && !defined(TARGET_HOST_SOLARIS)
42 #if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__) \
43 || defined(_WIN32) || defined(_WIN32_WCE) \
44 || ( defined(__CYGWIN__) && defined(X_DISPLAY_MISSING) )
45 # define TARGET_HOST_MS_WINDOWS 1
47 #elif defined (__ANDROID__)
48 # define TARGET_HOST_ANDROID 1
50 #elif defined (__QNXNTO__) || defined (__PLAYBOOK__)
51 # define TARGET_HOST_BLACKBERRY 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_ANDROID
77 # define TARGET_HOST_ANDROID 0
80 #ifndef TARGET_HOST_BLACKBERRY
81 # define TARGET_HOST_BLACKBERRY 0
84 #ifndef TARGET_HOST_POSIX_X11
85 # define TARGET_HOST_POSIX_X11 0
88 #ifndef TARGET_HOST_MAC_OSX
89 # define TARGET_HOST_MAC_OSX 0
92 #ifndef TARGET_HOST_SOLARIS
93 # define TARGET_HOST_SOLARIS 0
96 /* -- FIXED CONFIGURATION LIMITS ------------------------------------------- */
98 #define FREEGLUT_MAX_MENUS 3
100 /* These files should be available on every platform. */
107 /* These are included based on autoconf directives. */
108 #ifdef HAVE_SYS_TYPES_H
109 # include <sys/types.h>
114 #ifdef TIME_WITH_SYS_TIME
115 # include <sys/time.h>
117 #elif defined(HAVE_SYS_TIME_H)
118 # include <sys/time.h>
123 /* -- AUTOCONF HACKS --------------------------------------------------------*/
125 /* XXX: Update autoconf to avoid these.
126 * XXX: Are non-POSIX platforms intended not to use autoconf?
127 * If so, perhaps there should be a config_guess.h for them. Alternatively,
128 * config guesses could be placed above, just after the config.h exclusion.
130 #if defined(__FreeBSD__) || defined(__NetBSD__)
131 # define HAVE_USB_JS 1
132 # if defined(__NetBSD__) || ( defined(__FreeBSD__) && __FreeBSD_version >= 500000)
133 # define HAVE_USBHID_H 1
137 #if defined(_MSC_VER) || defined(__WATCOMC__)
138 /* strdup() is non-standard, for all but POSIX-2001 */
139 #define strdup _strdup
142 /* M_PI is non-standard (defined by BSD, not ISO-C) */
144 # define M_PI 3.14159265358979323846
147 #ifdef HAVE_STDBOOL_H
148 # include <stdbool.h>
164 /* General defines */
165 #define INVALID_MODIFIERS 0xffffffff
167 /* FreeGLUT internal time type */
168 #if defined(HAVE_STDINT_H)
170 typedef uint64_t fg_time_t;
171 #elif defined(HAVE_INTTYPES_H)
172 # include <inttypes.h>
173 typedef uint64_t fg_time_t;
174 #elif defined(HAVE_U__INT64)
175 typedef unsigned __int64 fg_time_t;
176 #elif defined(HAVE_ULONG_LONG)
177 typedef unsigned long long fg_time_t;
179 typedef unsigned long fg_time_t;
184 # define __fg_unused __attribute__((unused))
190 /* Platform-specific includes */
191 #if TARGET_HOST_POSIX_X11
192 #include "x11/fg_internal_x11.h"
194 #if TARGET_HOST_MS_WINDOWS
195 #include "mswin/fg_internal_mswin.h"
197 #if TARGET_HOST_ANDROID
198 #include "android/fg_internal_android.h"
200 #if TARGET_HOST_BLACKBERRY
201 #include "blackberry/fg_internal_blackberry.h"
205 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
207 /* Freeglut callbacks type definitions */
208 typedef void (* FGCBDisplay )( void );
209 typedef void (* FGCBReshape )( int, int );
210 typedef void (* FGCBPosition )( int, int );
211 typedef void (* FGCBVisibility )( int );
212 typedef void (* FGCBKeyboard )( unsigned char, int, int );
213 typedef void (* FGCBKeyboardUp )( unsigned char, int, int );
214 typedef void (* FGCBSpecial )( int, int, int );
215 typedef void (* FGCBSpecialUp )( int, int, int );
216 typedef void (* FGCBMouse )( int, int, int, int );
217 typedef void (* FGCBMouseWheel )( int, int, int, int );
218 typedef void (* FGCBMotion )( int, int );
219 typedef void (* FGCBPassive )( int, int );
220 typedef void (* FGCBEntry )( int );
221 typedef void (* FGCBWindowStatus )( int );
222 typedef void (* FGCBJoystick )( unsigned int, int, int, int );
223 typedef void (* FGCBOverlayDisplay)( void );
224 typedef void (* FGCBSpaceMotion )( int, int, int );
225 typedef void (* FGCBSpaceRotation )( int, int, int );
226 typedef void (* FGCBSpaceButton )( int, int );
227 typedef void (* FGCBDials )( int, int );
228 typedef void (* FGCBButtonBox )( int, int );
229 typedef void (* FGCBTabletMotion )( int, int );
230 typedef void (* FGCBTabletButton )( int, int, int, int );
231 typedef void (* FGCBDestroy )( void ); /* Used for both window and menu destroy callbacks */
233 typedef void (* FGCBMultiEntry )( int, int );
234 typedef void (* FGCBMultiButton )( int, int, int, int, int );
235 typedef void (* FGCBMultiMotion )( int, int, int );
236 typedef void (* FGCBMultiPassive )( int, int, int );
238 typedef void (* FGCBInitContext)();
239 typedef void (* FGCBAppStatus)(int);
241 /* The global callbacks type definitions */
242 typedef void (* FGCBIdle )( void );
243 typedef void (* FGCBTimer )( int );
244 typedef void (* FGCBMenuState )( int );
245 typedef void (* FGCBMenuStatus )( int, int, int );
247 /* The callback used when creating/using menus */
248 typedef void (* FGCBMenu )( int );
250 /* The FreeGLUT error/warning handler type definition */
251 typedef void (* FGError ) ( const char *fmt, va_list ap);
252 typedef void (* FGWarning ) ( const char *fmt, va_list ap);
255 /* A list structure */
256 typedef struct tagSFG_List SFG_List;
263 /* A list node structure */
264 typedef struct tagSFG_Node SFG_Node;
271 /* A helper structure holding two ints and a boolean */
272 typedef struct tagSFG_XYUse SFG_XYUse;
275 GLint X, Y; /* The two integers... */
276 GLboolean Use; /* ...and a single boolean. */
280 * An enumeration containing the state of the GLUT execution:
281 * initializing, running, or stopping
285 GLUT_EXEC_STATE_INIT,
286 GLUT_EXEC_STATE_RUNNING,
290 /* This structure holds different freeglut settings */
291 typedef struct tagSFG_State SFG_State;
294 SFG_XYUse Position; /* The default windows' position */
295 SFG_XYUse Size; /* The default windows' size */
296 unsigned int DisplayMode; /* Display mode for new windows */
298 GLboolean Initialised; /* freeglut has been initialised */
300 int DirectContext; /* Direct rendering state */
302 GLboolean ForceIconic; /* New top windows are iconified */
303 GLboolean UseCurrentContext; /* New windows share with current */
305 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
306 GLboolean XSyncSwitch; /* X11 sync protocol switch */
308 int KeyRepeat; /* Global key repeat mode. */
309 int Modifiers; /* Current ALT/SHIFT/CTRL state */
311 GLuint FPSInterval; /* Interval between FPS printfs */
312 GLuint SwapCount; /* Count of glutSwapBuffer calls */
313 GLuint SwapTime; /* Time of last SwapBuffers */
315 fg_time_t Time; /* Time that glutInit was called */
316 SFG_List Timers; /* The freeglut timer hooks */
317 SFG_List FreeTimers; /* The unused timer hooks */
319 FGCBIdle IdleCallback; /* The global idle callback */
321 int ActiveMenus; /* Num. of currently active menus */
322 FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
323 FGCBMenuStatus MenuStatusCallback;
324 void* MenuFont; /* Font to be used for newly created menus */
326 SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
327 int GameModeDepth; /* The pixel depth for game mode */
328 int GameModeRefresh; /* The refresh rate for game mode */
330 int ActionOnWindowClose; /* Action when user closes window */
332 fgExecutionState ExecState; /* Used for GLUT termination */
333 char *ProgramName; /* Name of the invoking program */
334 GLboolean JoysticksInitialised; /* Only initialize if application calls for them */
335 int NumActiveJoysticks; /* Number of active joysticks (callback defined and positive pollrate) -- if zero, don't poll joysticks */
336 GLboolean InputDevsInitialised; /* Only initialize if application calls for them */
338 int MouseWheelTicks; /* Number of ticks the mouse wheel has turned */
340 int AuxiliaryBufferNumber; /* Number of auxiliary buffers */
341 int SampleNumber; /* Number of samples per pixel */
343 GLboolean SkipStaleMotion; /* skip stale motion events */
345 int MajorVersion; /* Major OpenGL context version */
346 int MinorVersion; /* Minor OpenGL context version */
347 int ContextFlags; /* OpenGL context flags */
348 int ContextProfile; /* OpenGL context profile */
349 int HasOpenGL20; /* fgInitGL2 could find all OpenGL 2.0 functions */
350 FGError ErrorFunc; /* User defined error handler */
351 FGWarning WarningFunc; /* User defined warning handler */
354 /* The structure used by display initialization in freeglut_init.c */
355 typedef struct tagSFG_Display SFG_Display;
356 struct tagSFG_Display
358 SFG_PlatformDisplay pDisplay;
360 int ScreenWidth; /* The screen's width in pixels */
361 int ScreenHeight; /* The screen's height in pixels */
362 int ScreenWidthMM; /* The screen's width in milimeters */
363 int ScreenHeightMM; /* The screen's height in milimeters */
367 /* The user can create any number of timer hooks */
368 typedef struct tagSFG_Timer SFG_Timer;
372 int ID; /* The timer ID integer */
373 FGCBTimer Callback; /* The timer callback */
374 fg_time_t TriggerTime; /* The timer trigger time */
378 * A window and its OpenGL context. The contents of this structure
379 * are highly dependant on the target operating system we aim at...
381 typedef struct tagSFG_Context SFG_Context;
382 struct tagSFG_Context
384 SFG_WindowHandleType Handle; /* The window's handle */
385 SFG_WindowContextType Context; /* The window's OpenGL/WGL context */
387 SFG_PlatformContext pContext; /* The window's FBConfig (X11) or device context (Windows) */
389 int DoubleBuffered; /* Treat the window as double-buffered */
391 /* When drawing geometry to vertex attribute buffers, user specifies
392 * the attribute indices for vertices, normals and/or texture coords
393 * to freeglut. Those are stored here
395 GLint attribute_v_coord;
396 GLint attribute_v_normal;
397 GLint attribute_v_texture;
402 * Bitmasks indicating the different kinds of
403 * actions that can be scheduled for a window.
405 #define GLUT_INIT_WORK (1<<0)
406 #define GLUT_VISIBILITY_WORK (1<<1)
407 #define GLUT_POSITION_WORK (1<<2)
408 #define GLUT_SIZE_WORK (1<<3)
409 #define GLUT_ZORDER_WORK (1<<4)
410 #define GLUT_FULL_SCREEN_WORK (1<<5)
411 #define GLUT_DISPLAY_WORK (1<<6)
414 * An enumeration containing the state of the GLUT execution:
415 * initializing, running, or stopping
422 } fgDesiredVisibility ;
425 * There is considerable confusion about the "right thing to
426 * do" concerning window size and position. GLUT itself is
427 * not consistent between Windows and UNIX/X11; since
428 * platform independence is a virtue for "freeglut", we
429 * decided to break with GLUT's behaviour.
431 * Under UNIX/X11, it is apparently not possible to get the
432 * window border sizes in order to subtract them off the
433 * window's initial position until some time after the window
434 * has been created. Therefore we decided on the following
435 * behaviour, both under Windows and under UNIX/X11:
436 * - When you create a window with position (x,y) and size
437 * (w,h), the upper left hand corner of the outside of the
438 * window is at (x,y) and the size of the drawable area is
440 * - When you query the size and position of the window--as
441 * is happening here for Windows--"freeglut" will return
442 * the size of the drawable area--the (w,h) that you
443 * specified when you created the window--and the coordinates
444 * of the upper left hand corner of the drawable area, i.e.
445 * of the client rect--which is NOT the (x,y) you specified.
447 typedef struct tagSFG_WindowState SFG_WindowState;
448 struct tagSFG_WindowState /* as per notes above, sizes always refer to the client area (thus without the window decorations) */
450 /* window state - size, position, look */
451 int Xpos; /* Window's top-left of client area, X-coordinate */
452 int Ypos; /* Window's top-left of client area, Y-coordinate */
453 int Width; /* Window's width in pixels */
454 int Height; /* The same about the height */
455 GLboolean Visible; /* Is the window visible now? Not using fgVisibilityState as we only care if visible or not */
456 int Cursor; /* The currently selected cursor style */
457 GLboolean IsFullscreen; /* is the window fullscreen? */
459 /* FreeGLUT operations are deferred, that is, window moving, resizing,
460 * Z-order changing, making full screen or not do not happen immediately
461 * upon the user's request, but only in the next iteration of the main
462 * loop, before the display callback is called. This allows multiple
463 * reshape, position, etc requests to be combined into one and is
464 * compatible with the way GLUT does things. Callbacks get triggered
465 * based on the feedback/messages/notifications from the window manager.
466 * Below here we define what work should be done, as well as the relevant
467 * parameters for this work.
469 unsigned int WorkMask; /* work (resize, etc) to be done on the window */
470 int DesiredXpos; /* desired X location */
471 int DesiredYpos; /* desired Y location */
472 int DesiredWidth; /* desired window width */
473 int DesiredHeight; /* desired window height */
474 int DesiredZOrder; /* desired window Z Order position */
475 fgDesiredVisibility DesiredVisibility;/* desired visibility (hidden, iconic, shown/normal) */
477 SFG_PlatformWindowState pWState; /* Window width/height (X11) or rectangle/style (Windows) from before a resize, and other stuff only needed on specific platforms */
479 long JoystickPollRate; /* The joystick polling rate */
480 fg_time_t JoystickLastPoll; /* When the last poll happened */
482 int MouseX, MouseY; /* The most recent mouse position */
484 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */
486 GLboolean VisualizeNormals; /* When drawing objects, draw vectors representing the normals as well? */
491 * A generic function pointer. We should really use the GLUTproc type
492 * defined in freeglut_ext.h, but if we include that header in this file
493 * a bunch of other stuff (font-related) blows up!
495 typedef void (*SFG_Proc)();
499 * SET_WCB() is used as:
501 * SET_WCB( window, cbname, func );
503 * ...where {window} is the freeglut window to set the callback,
504 * {cbname} is the window-specific callback to set,
505 * {func} is a function-pointer.
507 * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,
508 * but this can cause warnings because the FETCH_WCB() macro type-
509 * casts its result, and a type-cast value shouldn't be an lvalue.
511 * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking
512 * and for no other reason. Since it's hidden in the macro, the
513 * ugliness is felt to be rather benign.
515 #define SET_WCB(window,cbname,func) \
518 if( FETCH_WCB( window, cbname ) != (SFG_Proc)(func) ) \
519 (((window).CallBacks[WCB_ ## cbname]) = (SFG_Proc)(func)); \
523 * FETCH_WCB() is used as:
525 * FETCH_WCB( window, cbname );
527 * ...where {window} is the freeglut window to fetch the callback from,
528 * {cbname} is the window-specific callback to fetch.
530 * The result is correctly type-cast to the callback function pointer
533 #define FETCH_WCB(window,cbname) \
534 ((window).CallBacks[WCB_ ## cbname])
537 * INVOKE_WCB() is used as:
539 * INVOKE_WCB( window, cbname, ( arg_list ) );
541 * ...where {window} is the freeglut window,
542 * {cbname} is the window-specific callback to be invoked,
543 * {(arg_list)} is the parameter list.
545 * The callback is invoked as:
547 * callback( arg_list );
549 * ...so the parentheses are REQUIRED in the {arg_list}.
551 * NOTE that it does a sanity-check and also sets the
555 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: also WinCE? */
556 #define INVOKE_WCB(window,cbname,arg_list) \
559 if( FETCH_WCB( window, cbname ) ) \
561 FGCB ## cbname func = (FGCB ## cbname)(FETCH_WCB( window, cbname )); \
562 fgSetWindow( &window ); \
567 #define INVOKE_WCB(window,cbname,arg_list) \
570 if( FETCH_WCB( window, cbname ) ) \
572 fgSetWindow( &window ); \
573 ((FGCB ## cbname)FETCH_WCB( window, cbname )) arg_list; \
579 * The window callbacks the user can supply us with. Should be kept portable.
581 * This enumeration provides the freeglut CallBack numbers.
582 * The symbolic constants are indices into a window's array of
583 * function callbacks. The names are formed by splicing a common
584 * prefix onto the callback's base name. (This was originally
585 * done so that an early stage of development could live side-by-
586 * side with the old callback code. The old callback code used
587 * the bare callback's name as a structure member, so I used a
588 * prefix for the array index name.)
609 /* Multi-Pointer X and touch related */
615 /* Mobile platforms LifeCycle */
619 /* Presently ignored */
622 WCB_SpaceMotion, /* presently implemented only on UNIX/X11 */
623 WCB_SpaceRotation, /* presently implemented only on UNIX/X11 */
624 WCB_SpaceButton, /* presently implemented only on UNIX/X11 */
630 /* Always make this the LAST one */
635 /* This structure holds the OpenGL rendering context for all the menu windows */
636 typedef struct tagSFG_MenuContext SFG_MenuContext;
637 struct tagSFG_MenuContext
639 SFG_WindowContextType MContext; /* The menu window's WGL context */
642 /* This structure describes a menu */
643 typedef struct tagSFG_Window SFG_Window;
644 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
645 typedef struct tagSFG_Menu SFG_Menu;
649 void *UserData; /* User data passed back at callback */
650 int ID; /* The global menu ID */
651 SFG_List Entries; /* The menu entries list */
652 FGCBMenu Callback; /* The menu callback */
653 FGCBDestroy Destroy; /* Destruction callback */
654 GLboolean IsActive; /* Is the menu selected? */
655 void* Font; /* Font to be used for displaying this menu */
656 int Width; /* Menu box width in pixels */
657 int Height; /* Menu box height in pixels */
658 int X, Y; /* Menu box raster position */
660 SFG_MenuEntry *ActiveEntry; /* Currently active entry in the menu */
661 SFG_Window *Window; /* Window for menu */
662 SFG_Window *ParentWindow; /* Window in which the menu is invoked */
665 /* This is a menu entry */
666 struct tagSFG_MenuEntry
669 int ID; /* The menu entry ID (local) */
670 int Ordinal; /* The menu's ordinal number */
671 char* Text; /* The text to be displayed */
672 SFG_Menu* SubMenu; /* Optional sub-menu tree */
673 GLboolean IsActive; /* Is the entry highlighted? */
674 int Width; /* Label's width in pixels */
678 * A window, making part of freeglut windows hierarchy.
679 * Should be kept portable.
681 * NOTE that ActiveMenu is set to menu itself if the window is a menu.
686 int ID; /* Window's ID number */
688 SFG_Context Window; /* Window and OpenGL context */
689 SFG_WindowState State; /* The window state */
690 SFG_Proc CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
691 void *UserData ; /* For use by user */
693 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
694 SFG_Menu* ActiveMenu; /* The window's active menu */
696 SFG_Window* Parent; /* The parent to this window */
697 SFG_List Children; /* The subwindows d.l. list */
699 GLboolean IsMenu; /* Set to 1 if we are a menu */
703 /* A linked list structure of windows */
704 typedef struct tagSFG_WindowList SFG_WindowList ;
705 struct tagSFG_WindowList
711 /* This holds information about all the windows, menus etc. */
712 typedef struct tagSFG_Structure SFG_Structure;
713 struct tagSFG_Structure
715 SFG_List Windows; /* The global windows list */
716 SFG_List Menus; /* The global menus list */
717 SFG_List WindowsToDestroy;
719 SFG_Window* CurrentWindow; /* The currently set window */
720 SFG_Menu* CurrentMenu; /* Same, but menu... */
722 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
724 SFG_Window* GameModeWindow; /* The game mode window */
726 int WindowID; /* The window ID for the next window to be created */
727 int MenuID; /* The menu ID for the next menu to be created */
731 * This structure is used for the enumeration purposes.
732 * You can easily extend its functionalities by declaring
733 * a structure containing enumerator's contents and custom
734 * data, then casting its pointer to (SFG_Enumerator *).
736 typedef struct tagSFG_Enumerator SFG_Enumerator;
737 struct tagSFG_Enumerator
739 GLboolean found; /* Used to terminate search */
740 void* data; /* Custom data pointer */
742 typedef void (* FGCBWindowEnumerator )( SFG_Window *, SFG_Enumerator * );
743 typedef void (* FGCBMenuEnumerator )( SFG_Menu *, SFG_Enumerator * );
745 /* The bitmap font structure */
746 typedef struct tagSFG_Font SFG_Font;
749 char* Name; /* The source font name */
750 int Quantity; /* Number of chars in font */
751 int Height; /* Height of the characters */
752 const GLubyte** Characters; /* The characters mapping */
754 float xorig, yorig; /* Relative origin of the character */
757 /* The stroke font structures */
759 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
760 struct tagSFG_StrokeVertex
765 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
766 struct tagSFG_StrokeStrip
769 const SFG_StrokeVertex* Vertices;
772 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
773 struct tagSFG_StrokeChar
777 const SFG_StrokeStrip* Strips;
780 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
781 struct tagSFG_StrokeFont
783 char* Name; /* The source font name */
784 int Quantity; /* Number of chars in font */
785 GLfloat Height; /* Height of the characters */
786 const SFG_StrokeChar** Characters; /* The characters mapping */
790 /* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */
792 * Initial defines from "js.h" starting around line 33 with the existing "freeglut_joystick.c"
796 #if TARGET_HOST_MACINTOSH
797 # include <InputSprocket.h>
800 #if TARGET_HOST_MAC_OSX
801 # include <mach/mach.h>
802 # include <IOKit/IOkitLib.h>
803 # include <IOKit/hid/IOHIDLib.h>
806 /* XXX It might be better to poll the operating system for the numbers of buttons and
807 * XXX axes and then dynamically allocate the arrays.
809 #define _JS_MAX_BUTTONS 32
811 #if TARGET_HOST_MACINTOSH
812 # define _JS_MAX_AXES 9
813 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
814 struct tagSFG_PlatformJoystick
816 #define ISP_NUM_AXIS 9
817 #define ISP_NUM_NEEDS 41
818 ISpElementReference isp_elem [ ISP_NUM_NEEDS ];
819 ISpNeed isp_needs [ ISP_NUM_NEEDS ];
823 #if TARGET_HOST_MAC_OSX
824 # define _JS_MAX_AXES 16
825 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
826 struct tagSFG_PlatformJoystick
828 IOHIDDeviceInterface ** hidDev;
829 IOHIDElementCookie buttonCookies[41];
830 IOHIDElementCookie axisCookies[_JS_MAX_AXES];
831 /* The next two variables are not used anywhere */
832 /* long minReport[_JS_MAX_AXES],
833 * maxReport[_JS_MAX_AXES];
840 * Definition of "SFG_Joystick" structure -- based on JS's "jsJoystick" object class.
841 * See "js.h" lines 80-178.
843 typedef struct tagSFG_Joystick SFG_Joystick;
844 struct tagSFG_Joystick
846 SFG_PlatformJoystick pJoystick;
854 float dead_band[ _JS_MAX_AXES ];
855 float saturate [ _JS_MAX_AXES ];
856 float center [ _JS_MAX_AXES ];
857 float max [ _JS_MAX_AXES ];
858 float min [ _JS_MAX_AXES ];
863 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
865 /* Freeglut display related stuff (initialized once per session) */
866 extern SFG_Display fgDisplay;
868 /* Freeglut internal structure */
869 extern SFG_Structure fgStructure;
871 /* The current freeglut settings */
872 extern SFG_State fgState;
875 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
878 * A call to this function makes us sure that the Display and Structure
879 * subsystems have been properly initialized and are ready to be used
881 #define FREEGLUT_EXIT_IF_NOT_INITIALISED( string ) \
882 if ( ! fgState.Initialised ) \
884 fgError ( " ERROR: Function <%s> called" \
885 " without first calling 'glutInit'.", (string) ) ; \
888 #define FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED( string ) \
889 if ( ! fgState.Initialised ) \
891 fgError ( " ERROR: Internal <%s> function called" \
892 " without first calling 'glutInit'.", (string) ) ; \
895 #define FREEGLUT_INTERNAL_ERROR_EXIT( cond, string, function ) \
898 fgError ( " ERROR: Internal error <%s> in function %s", \
899 (string), (function) ) ; \
903 * Following definitions are somewhat similiar to GLib's,
904 * but do not generate any log messages:
906 #define freeglut_return_if_fail( expr ) \
909 #define freeglut_return_val_if_fail( expr, val ) \
914 * A call to those macros assures us that there is a current
915 * window set, respectively:
917 #define FREEGLUT_EXIT_IF_NO_WINDOW( string ) \
918 if ( ! fgStructure.CurrentWindow && \
919 ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION ) ) \
921 fgError ( " ERROR: Function <%s> called" \
922 " with no current window defined.", (string) ) ; \
926 * The deinitialize function gets called on glutMainLoop() end. It should clean up
927 * everything inside of the freeglut
929 void fgDeinitialize( void );
932 * Those two functions are used to create/destroy the freeglut internal
933 * structures. This actually happens when calling glutInit() and when
934 * quitting the glutMainLoop() (which actually happens, when all windows
937 void fgCreateStructure( void );
938 void fgDestroyStructure( void );
941 * Window creation, opening, closing and destruction.
942 * Also CallBack clearing/initialization.
943 * Defined in freeglut_structure.c, freeglut_window.c.
945 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
946 GLboolean positionUse, int x, int y,
947 GLboolean sizeUse, int w, int h,
948 GLboolean gameMode, GLboolean isMenu );
949 void fgSetWindow ( SFG_Window *window );
950 void fgOpenWindow( SFG_Window* window, const char* title,
951 GLboolean positionUse, int x, int y,
952 GLboolean sizeUse, int w, int h,
953 GLboolean gameMode, GLboolean isSubWindow );
954 void fgCloseWindow( SFG_Window* window );
955 void fgAddToWindowDestroyList ( SFG_Window* window );
956 void fgCloseWindows ();
957 void fgDestroyWindow( SFG_Window* window );
959 /* Menu creation and destruction. Defined in freeglut_structure.c */
960 SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
961 void fgDestroyMenu( SFG_Menu* menu );
963 /* Joystick device management functions, defined in freeglut_joystick.c */
964 int fgJoystickDetect( void );
965 void fgInitialiseJoysticks( void );
966 void fgJoystickClose( void );
967 void fgJoystickPollWindow( SFG_Window* window );
969 /* InputDevice Initialisation and Closure */
970 int fgInputDeviceDetect( void );
971 void fgInitialiseInputDevices( void );
972 void fgInputDeviceClose( void );
974 /* spaceball device functions, defined in freeglut_spaceball.c */
975 void fgInitialiseSpaceball( void );
976 void fgSpaceballClose( void );
977 void fgSpaceballSetWindow( SFG_Window *window );
979 int fgHasSpaceball( void );
980 int fgSpaceballNumButtons( void );
982 /* Setting the cursor for a given window */
983 void fgSetCursor ( SFG_Window *window, int cursorID );
986 * Helper function to enumerate through all registered windows
987 * and one to enumerate all of a window's subwindows...
989 * The GFunc callback for those functions will be defined as:
991 * void enumCallback( gpointer window, gpointer enumerator );
993 * where window is the enumerated (sub)window pointer (SFG_Window *),
994 * and userData is the a custom user-supplied pointer. Functions
995 * are defined and exported from freeglut_structure.c file.
997 void fgEnumWindows( FGCBWindowEnumerator enumCallback, SFG_Enumerator* enumerator );
998 void fgEnumSubWindows( SFG_Window* window, FGCBWindowEnumerator enumCallback,
999 SFG_Enumerator* enumerator );
1002 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
1003 * first window in the queue matching the specified window handle.
1004 * The function is defined in freeglut_structure.c file.
1006 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
1009 * This function is similiar to the previous one, except it is
1010 * looking for a specified (sub)window identifier. The function
1011 * is defined in freeglut_structure.c file.
1013 SFG_Window* fgWindowByID( int windowID );
1016 * Looks up a menu given its ID. This is easier than fgWindowByXXX
1017 * as all menus are placed in a single doubly linked list...
1019 SFG_Menu* fgMenuByID( int menuID );
1022 * Returns active menu, if any. Assumption: only one menu active throughout application at any one time.
1023 * This is easier than fgWindowByXXX as all menus are placed in one doubly linked list...
1025 SFG_Menu* fgGetActiveMenu( );
1028 * The menu activation and deactivation the code. This is the meat
1029 * of the menu user interface handling code...
1031 void fgUpdateMenuHighlight ( SFG_Menu *menu );
1032 GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
1033 int mouse_x, int mouse_y );
1034 void fgDeactivateMenu( SFG_Window *window );
1037 * This function gets called just before the buffers swap, so that
1038 * freeglut can display the pull-down menus via OpenGL. The function
1039 * is defined in freeglut_menu.c file.
1041 void fgDisplayMenu( void );
1043 /* Elapsed time as per glutGet(GLUT_ELAPSED_TIME). */
1044 fg_time_t fgElapsedTime( void );
1046 /* System time in milliseconds */
1047 fg_time_t fgSystemTime(void);
1049 /* List functions */
1050 void fgListInit(SFG_List *list);
1051 void fgListAppend(SFG_List *list, SFG_Node *node);
1052 void fgListRemove(SFG_List *list, SFG_Node *node);
1053 int fgListLength(SFG_List *list);
1054 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);
1056 /* Error Message functions */
1057 void fgError( const char *fmt, ... );
1058 void fgWarning( const char *fmt, ... );
1060 SFG_Proc fgPlatformGetProcAddress( const char *procName );
1062 /* pushing attribute/value pairs into an array */
1063 #define ATTRIB(a) attributes[where++]=(a)
1064 #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);}
1066 int fghMapBit( int mask, int from, int to );
1067 int fghIsLegacyContextRequested( void );
1068 void fghContextCreationError( void );
1069 int fghNumberOfAuxBuffersRequested( void );
1071 #endif /* FREEGLUT_INTERNAL_H */
1073 /*** END OF FILE ***/