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
31 /* XXX Update these for each release! */
32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 2
34 #define VERSION_PATCH 0
37 * Freeglut is meant to be available under all Unix/X11 and Win32 platforms.
39 #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)
40 # define TARGET_HOST_UNIX_X11 0
41 # define TARGET_HOST_WIN32 1
43 # define TARGET_HOST_UNIX_X11 1
44 # define TARGET_HOST_WIN32 0
47 #define FREEGLUT_MAX_MENUS 3
48 #define FREEGLUT_DEBUG 1
51 #undef G_DISABLE_ASSERT
52 #undef G_DISABLE_CHECKS
54 #define G_DISABLE_ASSERT
55 #define G_DISABLE_CHECKS
59 * Somehow all Win32 include headers depend on this one:
68 #define strdup _strdup
72 * Those files should be available on every platform.
82 #if TARGET_HOST_UNIX_X11
88 * The system-dependant include files should go here:
90 #if TARGET_HOST_UNIX_X11
93 #include <X11/Xatom.h>
94 #include <X11/keysym.h>
96 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
97 #include <X11/extensions/xf86vmode.h>
102 * Microsoft VisualC++ 5.0's <math.h> does not define the PI
105 # define M_PI 3.14159265358979323846
116 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
119 * Freeglut callbacks type definitions
121 typedef void (* FGCBDisplay )( void );
122 typedef void (* FGCBReshape )( int, int );
123 typedef void (* FGCBVisibility )( int );
124 typedef void (* FGCBKeyboard )( unsigned char, int, int );
125 typedef void (* FGCBSpecial )( int, int, int );
126 typedef void (* FGCBMouse )( int, int, int, int );
127 typedef void (* FGCBMouseWheel )( int, int, int, int );
128 typedef void (* FGCBMotion )( int, int );
129 typedef void (* FGCBPassive )( int, int );
130 typedef void (* FGCBEntry )( int );
131 typedef void (* FGCBWindowStatus )( int );
132 typedef void (* FGCBSelect )( int, int, int );
133 typedef void (* FGCBJoystick )( unsigned int, int, int, int );
134 typedef void (* FGCBKeyboardUp )( unsigned char, int, int );
135 typedef void (* FGCBSpecialUp )( int, int, int );
136 typedef void (* FGCBOverlayDisplay)( void );
137 typedef void (* FGCBSpaceMotion )( int, int, int );
138 typedef void (* FGCBSpaceRotation )( int, int, int );
139 typedef void (* FGCBSpaceButton )( int, int );
140 typedef void (* FGCBDials )( int, int );
141 typedef void (* FGCBButtonBox )( int, int );
142 typedef void (* FGCBTabletMotion )( int, int );
143 typedef void (* FGCBTabletButton )( int, int, int, int );
144 typedef void (* FGCBDestroy )( void );
147 * The global callbacks type definitions
149 typedef void (* FGCBIdle )( void );
150 typedef void (* FGCBTimer )( int );
151 typedef void (* FGCBMenuState )( int );
152 typedef void (* FGCBMenuStatus )( int, int, int );
155 * The callback used when creating/using menus
157 typedef void (* FGCBMenu )( int );
163 typedef struct tagSFG_List SFG_List;
171 * A list node structure
173 typedef struct tagSFG_Node SFG_Node;
181 * A helper structure holding two ints and a boolean
183 typedef struct tagSFG_XYUse SFG_XYUse;
186 GLint X, Y; /* The two integers... */
187 GLboolean Use; /* ...and a single boolean. */
191 * A helper structure holding a timeval and a boolean
193 typedef struct tagSFG_Time SFG_Time;
199 struct timeval Value;
205 * An enumeration containing the state of the GLUT execution:
206 * initializing, running, or stopping
210 GLUT_EXEC_STATE_INIT,
211 GLUT_EXEC_STATE_RUNNING,
216 * This structure holds different freeglut settings
218 typedef struct tagSFG_State SFG_State;
221 SFG_XYUse Position; /* The default windows' position */
222 SFG_XYUse Size; /* The default windows' size */
223 unsigned int DisplayMode; /* Display mode for new windows */
225 GLboolean Initialised; /* freeglut has been initialised */
227 GLboolean ForceDirectContext; /* Force direct rendering? */
228 GLboolean TryDirectContext; /* What about giving a try to? */
230 GLboolean ForceIconic; /* New top windows are iconified */
231 GLboolean UseCurrentContext; /* New windows share with current */
233 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
234 GLboolean XSyncSwitch; /* X11 sync protocol switch */
236 int KeyRepeat; /* Global key repeat mode. */
237 int Modifiers; /* Current ALT/SHIFT/CTRL state */
239 GLuint FPSInterval; /* Interval between FPS printfs */
240 GLuint SwapCount; /* Count of glutSwapBuffer calls */
241 GLuint SwapTime; /* Time of last SwapBuffers */
243 SFG_Time Time; /* Time that glutInit was called */
244 SFG_List Timers; /* The freeglut timer hooks */
245 SFG_List FreeTimers; /* The unused timer hooks */
247 FGCBIdle IdleCallback; /* The global idle callback */
249 int ActiveMenus; /* Num. of currently active menus */
250 FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
251 FGCBMenuStatus MenuStatusCallback;
253 SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
254 int GameModeDepth; /* The pixel depth for game mode */
255 int GameModeRefresh; /* The refresh rate for game mode */
257 int ActionOnWindowClose; /* Action when user closes window */
259 fgExecutionState ExecState; /* Used for GLUT termination */
260 char *ProgramName; /* Name of the invoking program */
264 * The structure used by display initialization in freeglut_init.c
266 typedef struct tagSFG_Display SFG_Display;
267 struct tagSFG_Display
269 #if TARGET_HOST_UNIX_X11
270 Display* Display; /* The display we are being run in. */
271 int Screen; /* The screen we are about to use. */
272 Window RootWindow; /* The screen's root window. */
273 int Connection; /* The display's connection number */
274 Atom DeleteWindow; /* The window deletion atom */
276 #ifdef X_XF86VidModeGetModeLine
278 * XF86VidMode may be compilable even if it fails at runtime. Therefore,
279 * the validity of the VidMode has to be tracked
281 int DisplayModeValid; /* Flag that indicates runtime status*/
282 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
283 int DisplayModeClock; /* The display mode's refresh rate */
284 int DisplayViewPortX; /* saved X location of the viewport */
285 int DisplayViewPortY; /* saved Y location of the viewport */
286 int DisplayPointerX; /* saved X location of the pointer */
287 int DisplayPointerY; /* saved Y location of the pointer */
291 #elif TARGET_HOST_WIN32
292 HINSTANCE Instance; /* The application's instance */
293 DEVMODE DisplayMode; /* Desktop's display settings */
297 int ScreenWidth; /* The screen's width in pixels */
298 int ScreenHeight; /* The screen's height in pixels */
299 int ScreenWidthMM; /* The screen's width in milimeters */
300 int ScreenHeightMM; /* The screen's height in milimeters */
305 * The user can create any number of timer hooks
307 typedef struct tagSFG_Timer SFG_Timer;
311 int ID; /* The timer ID integer */
312 FGCBTimer Callback; /* The timer callback */
313 long TriggerTime; /* The timer trigger time */
317 * Make "freeglut" window handle and context types so that we don't need so
318 * much conditionally-compiled code later in the library.
320 #if TARGET_HOST_UNIX_X11
322 typedef Window SFG_WindowHandleType ;
323 typedef GLXContext SFG_WindowContextType ;
325 #elif TARGET_HOST_WIN32
327 typedef HWND SFG_WindowHandleType ;
328 typedef HGLRC SFG_WindowContextType ;
333 * A window and its OpenGL context. The contents of this structure
334 * are highly dependant on the target operating system we aim at...
336 typedef struct tagSFG_Context SFG_Context;
337 struct tagSFG_Context
339 SFG_WindowHandleType Handle; /* The window's handle */
340 SFG_WindowContextType Context; /* The window's OpenGL/WGL context */
342 #if TARGET_HOST_UNIX_X11
343 XVisualInfo* VisualInfo; /* The window's visual information */
344 Pixmap Pixmap; /* Used for offscreen rendering */
345 /* GLXPixmap GLXPixMap; */ /* Used for offscreen rendering */
346 #elif TARGET_HOST_WIN32
347 HDC Device; /* The window's device context */
350 int DoubleBuffered; /* Treat the window as double-buffered */
354 * Window's state description. This structure should be kept portable.
356 typedef struct tagSFG_WindowState SFG_WindowState;
357 struct tagSFG_WindowState
359 int Width; /* Window's width in pixels */
360 int Height; /* The same about the height */
361 int OldWidth; /* Window width from before a resize */
362 int OldHeight; /* " height " " " " */
364 GLboolean Redisplay; /* Do we have to redisplay? */
365 GLboolean Visible; /* Is the window visible now */
367 int Cursor; /* The currently selected cursor */
369 long JoystickPollRate; /* The joystick polling rate */
370 long JoystickLastPoll; /* When the last poll happened */
372 int MouseX, MouseY; /* The most recent mouse position */
374 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */
375 GLboolean KeyRepeating; /* Currently in repeat mode */
377 GLboolean IsGameMode; /* Is this the game mode window? */
378 GLboolean NeedToResize; /* Do we need to resize the window? */
383 * SET_WCB() is used as:
385 * SET_WCB( window, Visibility, func );
387 * ...where {window} is the freeglut window to set the callback,
388 * {Visibility} is the window-specific callback to set,
389 * {func} is a function-pointer.
391 * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,
392 * but this can cause warnings because the FETCH_WCB() macro type-
393 * casts its result, and a type-cast value shouldn't be an lvalue.
395 * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking
396 * and for no other reason. Since it's hidden in the macro, the
397 * ugliness is felt to be rather benign.
399 #define SET_WCB(window,cbname,func) \
402 if( FETCH_WCB( window, cbname ) != func ) \
403 (((window).CallBacks[CB_ ## cbname]) = (void *) func); \
407 * FETCH_WCB() is used as:
409 * FETCH_WCB( window, Visibility );
411 * ...where {window} is the freeglut window to fetch the callback from,
412 * {Visibility} is the window-specific callback to fetch.
414 * The result is correctly type-cast to the callback function pointer
417 #define FETCH_WCB(window,cbname) \
418 ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
421 * INVOKE_WCB() is used as:
423 * INVOKE_WCB( window, Visibility, ( status ) );
425 * ...where {window} is the freeglut window,
426 * {Visibility} is the window-specific callback,
427 * {(status)} is the parameter list.
429 * The callback is invoked as:
431 * callback( status );
433 * ...so the parentheses are REQUIRED in the {arg_list}.
435 * NOTE that it does a sanity-check and also sets the
439 #define INVOKE_WCB(window,cbname,arg_list) \
442 if( FETCH_WCB( window, cbname ) ) \
444 fgSetWindow( &window ); \
445 FETCH_WCB( window, cbname ) arg_list; \
450 * The window callbacks the user can supply us with. Should be kept portable.
452 * This enumeration provides the freeglut CallBack numbers.
453 * The symbolic constants are indices into a window's array of
454 * function callbacks. The names are formed by splicing a common
455 * prefix onto the callback's base name. (This was originally
456 * done so that an early stage of development could live side-by-
457 * side with the old callback code. The old callback code used
458 * the bare callback's name as a structure member, so I used a
459 * prefix for the array index name.)
461 * XXX For consistancy, perhaps the prefix should match the
462 * XXX FETCH* and INVOKE* macro suffices. I.e., WCB_, rather than
483 /* Presently ignored */
494 /* Always make this the LAST one */
500 * This structure holds the OpenGL rendering context for all the menu windows
502 typedef struct tagSFG_MenuContext SFG_MenuContext;
503 struct tagSFG_MenuContext
505 #if TARGET_HOST_UNIX_X11
506 XVisualInfo* VisualInfo; /* The window's visual information */
509 SFG_WindowContextType Context; /* The menu window's WGL context */
513 * This structure describes a menu
515 typedef struct tagSFG_Window SFG_Window;
516 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
517 typedef struct tagSFG_Menu SFG_Menu;
521 void *UserData; /* User data passed back at callback */
522 int ID; /* The global menu ID */
523 SFG_List Entries; /* The menu entries list */
524 FGCBMenu Callback; /* The menu callback */
525 FGCBDestroy Destroy; /* Destruction callback */
526 GLboolean IsActive; /* Is the menu selected? */
527 int Width; /* Menu box width in pixels */
528 int Height; /* Menu box height in pixels */
529 int X, Y; /* Menu box raster position */
531 SFG_MenuEntry *ActiveEntry; /* Currently active entry in the menu */
532 SFG_Window *Window; /* Window for menu */
533 SFG_Window *ParentWindow; /* Window in which the menu is defined */
537 * This is a menu entry
539 struct tagSFG_MenuEntry
542 int ID; /* The menu entry ID (local) */
543 int Ordinal; /* The menu's ordinal number */
544 char* Text; /* The text to be displayed */
545 SFG_Menu* SubMenu; /* Optional sub-menu tree */
546 GLboolean IsActive; /* Is the entry highlighted? */
547 int Width; /* Label's width in pixels */
551 * A window, making part of freeglut windows hierarchy.
552 * Should be kept portable.
557 int ID; /* Window's ID number */
559 SFG_Context Window; /* Window and OpenGL context */
560 SFG_WindowState State; /* The window state */
561 void *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
562 void *UserData ; /* For use by user */
564 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
565 SFG_Menu* ActiveMenu; /* The window's active menu */
567 SFG_Window* Parent; /* The parent to this window */
568 SFG_List Children; /* The subwindows d.l. list */
570 GLboolean IsMenu; /* Set to 1 if we are a menu */
575 * A linked list structure of windows
577 typedef struct tagSFG_WindowList SFG_WindowList ;
578 struct tagSFG_WindowList
585 * This holds information about all the windows, menus etc.
587 typedef struct tagSFG_Structure SFG_Structure;
588 struct tagSFG_Structure
590 SFG_List Windows; /* The global windows list */
591 SFG_List Menus; /* The global menus list */
592 SFG_List WindowsToDestroy;
594 SFG_Window* Window; /* The currently active win. */
595 SFG_Menu* Menu; /* Same, but menu... */
597 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
599 SFG_Window* GameMode; /* The game mode window */
601 int WindowID; /* The new current window ID */
602 int MenuID; /* The new current menu ID */
606 * This structure is used for the enumeration purposes.
607 * You can easily extend its functionalities by declaring
608 * a structure containing enumerator's contents and custom
609 * data, then casting its pointer to (SFG_Enumerator *).
611 typedef struct tagSFG_Enumerator SFG_Enumerator;
612 struct tagSFG_Enumerator
614 GLboolean found; /* Used to terminate search */
615 void* data; /* Custom data pointer */
617 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
620 * The bitmap font structure
622 typedef struct tagSFG_Font SFG_Font;
625 char* Name; /* The source font name */
626 int Quantity; /* Number of chars in font */
627 int Height; /* Height of the characters */
628 const GLubyte** Characters; /* The characters mapping */
630 float xorig, yorig; /* Relative origin of the character */
634 * The stroke font structures
637 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
638 struct tagSFG_StrokeVertex
643 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
644 struct tagSFG_StrokeStrip
647 const SFG_StrokeVertex* Vertices;
650 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
651 struct tagSFG_StrokeChar
655 const SFG_StrokeStrip* Strips;
658 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
659 struct tagSFG_StrokeFont
661 char* Name; /* The source font name */
662 int Quantity; /* Number of chars in font */
663 GLfloat Height; /* Height of the characters */
664 const SFG_StrokeChar** Characters; /* The characters mapping */
667 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
670 * Freeglut display related stuff (initialized once per session)
672 extern SFG_Display fgDisplay;
675 * Freeglut internal structure
677 extern SFG_Structure fgStructure;
680 * The current freeglut settings
682 extern SFG_State fgState;
685 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
688 * A call to this function makes us sure that the Display and Structure
689 * subsystems have been properly initialized and are ready to be used
691 #define freeglut_assert_ready assert( fgState.Initialised );
694 * Following definitions are somewhat similiar to GLib's,
695 * but do not generate any log messages:
697 #define freeglut_return_if_fail( expr ) \
700 #define freeglut_return_val_if_fail( expr, val ) \
705 * A call to those macros assures us that there is a current
706 * window and menu set, respectively:
708 #define freeglut_assert_window assert( fgStructure.Window != NULL );
709 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
712 * The initialize and deinitialize functions get called on glutInit()
713 * and glutMainLoop() end respectively. They should create/clean up
714 * everything inside of the freeglut
716 void fgInitialize( const char* displayName );
717 void fgDeinitialize( void );
720 * Those two functions are used to create/destroy the freeglut internal
721 * structures. This actually happens when calling glutInit() and when
722 * quitting the glutMainLoop() (which actually happens, when all windows
725 void fgCreateStructure( void );
726 void fgDestroyStructure( void );
729 * A helper function to check if a display mode is possible to use
731 #if TARGET_HOST_UNIX_X11
732 XVisualInfo* fgChooseVisual( void );
736 * The window procedure for Win32 events handling
738 #if TARGET_HOST_WIN32
739 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
740 WPARAM wParam, LPARAM lParam );
741 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
742 unsigned char layer_type );
746 * Window creation, opening, closing and destruction.
747 * Also CallBack clearing/initialization.
748 * Defined in freeglut_structure.c, freeglut_window.c.
750 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
751 int x, int y, int w, int h,
752 GLboolean gameMode, GLboolean isMenu );
753 void fgSetWindow ( SFG_Window *window );
754 void fgOpenWindow( SFG_Window* window, const char* title,
755 int x, int y, int w, int h, GLboolean gameMode,
756 GLboolean isSubWindow );
757 void fgCloseWindow( SFG_Window* window );
758 void fgAddToWindowDestroyList ( SFG_Window* window );
759 void fgCloseWindows ();
760 void fgDestroyWindow( SFG_Window* window );
761 void fgClearCallBacks( SFG_Window *window );
764 * Menu creation and destruction. Defined in freeglut_structure.c
766 SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
767 void fgDestroyMenu( SFG_Menu* menu );
770 * Joystick device management functions, defined in freeglut_joystick.c
772 void fgJoystickInit( int ident );
773 void fgJoystickClose( void );
774 void fgJoystickPollWindow( SFG_Window* window );
777 * Helper function to enumerate through all registered windows
778 * and one to enumerate all of a window's subwindows...
780 * The GFunc callback for those functions will be defined as:
782 * void enumCallback( gpointer window, gpointer enumerator );
784 * where window is the enumerated (sub)window pointer (SFG_Window *),
785 * and userData is the a custom user-supplied pointer. Functions
786 * are defined and exported from freeglut_structure.c file.
788 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
789 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
790 SFG_Enumerator* enumerator );
793 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
794 * first window in the queue matching the specified window handle.
795 * The function is defined in freeglut_structure.c file.
797 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
800 * This function is similiar to the previous one, except it is
801 * looking for a specified (sub)window identifier. The function
802 * is defined in freeglut_structure.c file.
804 SFG_Window* fgWindowByID( int windowID );
807 * Looks up a menu given its ID. This is easier than fgWindowByXXX
808 * as all menus are placed in a single doubly linked list...
810 SFG_Menu* fgMenuByID( int menuID );
813 * The menu activation and deactivation the code. This is the meat
814 * of the menu user interface handling code...
816 void fgActivateMenu( SFG_Window* window, int button );
817 void fgExecuteMenuCallback( SFG_Menu* menu );
818 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
819 void fgDeactivateMenu( SFG_Window *window );
820 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
823 * This function gets called just before the buffers swap, so that
824 * freeglut can display the pull-down menus via OpenGL. The function
825 * is defined in freeglut_menu.c file.
827 void fgDisplayMenu( void );
830 * Display the mouse cursor using OpenGL calls. The function
831 * is defined in freeglut_cursor.c file.
833 void fgDisplayCursor( void );
836 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
838 long fgElapsedTime( void );
843 void fgListInit(SFG_List *list);
844 void fgListAppend(SFG_List *list, SFG_Node *node);
845 void fgListRemove(SFG_List *list, SFG_Node *node);
846 int fgListLength(SFG_List *list);
847 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);
850 * Error Messages functions
852 void fgError( const char *fmt, ... );
853 void fgWarning( const char *fmt, ... );
855 #endif /* FREEGLUT_INTERNAL_H */
857 /*** END OF FILE ***/