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.
40 # define TARGET_HOST_UNIX_X11 1
41 # define TARGET_HOST_WIN32 0
43 # define TARGET_HOST_UNIX_X11 0
44 # define TARGET_HOST_WIN32 1
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:
65 #define strdup _strdup
69 * Those files should be available on every platform.
79 #if TARGET_HOST_UNIX_X11
85 * The system-dependant include files should go here:
87 #if TARGET_HOST_UNIX_X11
90 #include <X11/Xatom.h>
91 #include <X11/keysym.h>
93 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
94 #include <X11/extensions/xf86vmode.h>
99 * Microsoft VisualC++ 5.0's <math.h> does not define the PI
102 # define M_PI 3.14159265358979323846
113 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
116 * Freeglut callbacks type definitions
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 );
144 * The global callbacks type definitions
146 typedef void (* FGCBIdle )( void );
147 typedef void (* FGCBTimer )( int );
148 typedef void (* FGCBMenuState )( int );
149 typedef void (* FGCBMenuStatus )( int, int, int );
152 * The callback used when creating/using menus
154 typedef void (* FGCBMenu )( int );
160 typedef struct tagSFG_List SFG_List;
168 * A list node structure
170 typedef struct tagSFG_Node SFG_Node;
178 * A helper structure holding two ints and a boolean
180 typedef struct tagSFG_XYUse SFG_XYUse;
183 GLint X, Y; /* The two integers... */
184 GLboolean Use; /* ...and a single boolean. */
188 * A helper structure holding a timeval and a boolean
190 typedef struct tagSFG_Time SFG_Time;
196 struct timeval Value;
202 * An enumeration containing the state of the GLUT execution:
203 * initializing, running, or stopping
207 GLUT_EXEC_STATE_INIT,
208 GLUT_EXEC_STATE_RUNNING,
213 * This structure holds different freeglut settings
215 typedef struct tagSFG_State SFG_State;
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 */
222 GLboolean Initialised; /* freeglut has been initialised */
224 GLboolean ForceDirectContext; /* Force direct rendering? */
225 GLboolean TryDirectContext; /* What about giving a try to? */
227 GLboolean ForceIconic; /* New top windows are iconified */
228 GLboolean UseCurrentContext; /* New windows share with current */
230 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
231 GLboolean XSyncSwitch; /* X11 sync protocol switch */
233 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */
234 int Modifiers; /* Current ALT/SHIFT/CTRL state */
236 GLuint FPSInterval; /* Interval between FPS printfs */
237 GLuint SwapCount; /* Count of glutSwapBuffer calls */
238 GLuint SwapTime; /* Time of last SwapBuffers */
240 SFG_Time Time; /* Time that glutInit was called */
241 SFG_List Timers; /* The freeglut timer hooks */
242 SFG_List FreeTimers; /* The unused timer hooks */
244 FGCBIdle IdleCallback; /* The global idle callback */
246 int ActiveMenus; /* Num. of currently active menus */
247 FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
248 FGCBMenuStatus MenuStatusCallback;
250 SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
251 int GameModeDepth; /* The pixel depth for game mode */
252 int GameModeRefresh; /* The refresh rate for game mode */
254 int ActionOnWindowClose; /* Action when user closes window */
256 fgExecutionState ExecState; /* Used for GLUT termination */
257 char *ProgramName; /* Name of the invoking program */
261 * The structure used by display initialization in freeglut_init.c
263 typedef struct tagSFG_Display SFG_Display;
264 struct tagSFG_Display
266 #if TARGET_HOST_UNIX_X11
267 Display* Display; /* The display we are being run in. */
268 int Screen; /* The screen we are about to use. */
269 Window RootWindow; /* The screen's root window. */
270 int Connection; /* The display's connection number */
271 Atom DeleteWindow; /* The window deletion atom */
273 #ifdef X_XF86VidModeGetModeLine
275 * XF86VidMode may be compilable even if it fails at runtime. Therefore,
276 * the validity of the VidMode has to be tracked
278 int DisplayModeValid; /* Flag that indicates runtime status*/
279 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
280 int DisplayModeClock; /* The display mode's refresh rate */
281 int DisplayViewPortX; /* saved X location of the viewport */
282 int DisplayViewPortY; /* saved Y location of the viewport */
283 int DisplayPointerX; /* saved X location of the pointer */
284 int DisplayPointerY; /* saved Y location of the pointer */
288 #elif TARGET_HOST_WIN32
289 HINSTANCE Instance; /* The application's instance */
290 DEVMODE DisplayMode; /* Desktop's display settings */
294 int ScreenWidth; /* The screen's width in pixels */
295 int ScreenHeight; /* The screen's height in pixels */
296 int ScreenWidthMM; /* The screen's width in milimeters */
297 int ScreenHeightMM; /* The screen's height in milimeters */
302 * The user can create any number of timer hooks
304 typedef struct tagSFG_Timer SFG_Timer;
308 int ID; /* The timer ID integer */
309 FGCBTimer Callback; /* The timer callback */
310 long TriggerTime; /* The timer trigger time */
314 * Make "freeglut" window handle and context types so that we don't need so
315 * much conditionally-compiled code later in the library.
317 #if TARGET_HOST_UNIX_X11
319 typedef Window SFG_WindowHandleType ;
320 typedef GLXContext SFG_WindowContextType ;
322 #elif TARGET_HOST_WIN32
324 typedef HWND SFG_WindowHandleType ;
325 typedef HGLRC SFG_WindowContextType ;
330 * A window and its OpenGL context. The contents of this structure
331 * are highly dependant on the target operating system we aim at...
333 typedef struct tagSFG_Context SFG_Context;
334 struct tagSFG_Context
336 SFG_WindowHandleType Handle; /* The window's handle */
337 SFG_WindowContextType Context; /* The window's OpenGL/WGL context */
339 #if TARGET_HOST_UNIX_X11
340 XVisualInfo* VisualInfo; /* The window's visual information */
341 #elif TARGET_HOST_WIN32
342 HDC Device; /* The window's device context */
345 int DoubleBuffered; /* Treat the window as double-buffered */
349 * Window's state description. This structure should be kept portable.
351 typedef struct tagSFG_WindowState SFG_WindowState;
352 struct tagSFG_WindowState
354 int Width; /* Window's width in pixels */
355 int Height; /* The same about the height */
356 int OldWidth; /* Window width from before a resize */
357 int OldHeight; /* " height " " " " */
359 GLboolean Redisplay; /* Do we have to redisplay? */
360 GLboolean Visible; /* Is the window visible now */
362 int Cursor; /* The currently selected cursor */
364 long JoystickPollRate; /* The joystick polling rate */
365 long JoystickLastPoll; /* When the last poll has happened */
367 int MouseX, MouseY; /* The most recent mouse position */
369 GLboolean IsGameMode; /* Is this the game mode window? */
371 GLboolean NeedToResize; /* Do we need to resize the window? */
376 * SET_WCB() is used as:
378 * SET_WCB( window, Visibility, func );
380 * ...where {window} is the freeglut window to set the callback,
381 * {Visibility} is the window-specific callback to set,
382 * {func} is a function-pointer.
384 * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,
385 * but this can cause warnings because the FETCH_WCB() macro type-
386 * casts its result, and a type-cast value shouldn't be an lvalue.
388 * XXX Note that there is no type-checking to make sure that {func} is
389 * XXX a suitable type. We could add a safety-check of the form:
391 * XXX if( FETCH_WCB( ... ) != func )
394 * XXX ...is this desired?
396 * XXX The {if( FETCH_WCB( ... ) != func )} test is to do type-checking
397 * XXX and for no other reason. Since it's hidden in the macro, the
398 * XXX ugliness is felt to be rather benign.
400 #define SET_WCB(window,cbname,func) \
403 if( FETCH_WCB( window, cbname ) != func ) \
404 (((window).CallBacks[CB_ ## cbname]) = func); \
408 * FETCH_WCB() is used as:
410 * FETCH_WCB( window, Visibility );
412 * ...where {window} is the freeglut window to fetch the callback from,
413 * {Visibility} is the window-specific callback to fetch.
415 * The result is correctly type-cast to the callback function pointer
418 #define FETCH_WCB(window,cbname) \
419 ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
422 * INVOKE_WCB() is used as:
424 * INVOKE_WCB( window, Visibility, ( status ) );
426 * ...where {window} is the freeglut window,
427 * {Visibility} is the window-specific callback,
428 * {(status)} is the parameter list.
430 * The callback is invoked as:
432 * callback( status );
434 * ...so the parentheses are REQUIRED in the {arg_list}.
436 * NOTE that it does a sanity-check and also sets the
440 #define INVOKE_WCB(window,cbname,arg_list) \
443 if( FETCH_WCB( window, cbname ) ) \
445 fgSetWindow( &window ); \
446 FETCH_WCB( window, cbname ) arg_list; \
451 * The window callbacks the user can supply us with. Should be kept portable.
453 * This enumeration provides the freeglut CallBack numbers.
454 * The symbolic constants are indices into a window's array of
455 * function callbacks. The names are formed by splicing a common
456 * prefix onto the callback's base name. (This was originally
457 * done so that an early stage of development could live side-by-
458 * side with the old callback code. The old callback code used
459 * the bare callback's name as a structure member, so I used a
460 * prefix for the array index name.)
462 * XXX For consistancy, perhaps the prefix should match the
463 * XXX FETCH* and INVOKE* macro suffices. I.e., WCB_, rather than
484 /* Presently ignored */
495 /* Always make this the LAST one */
501 * This structure holds the OpenGL rendering context for all the menu windows
503 typedef struct tagSFG_MenuContext SFG_MenuContext;
504 struct tagSFG_MenuContext
506 #if TARGET_HOST_UNIX_X11
507 XVisualInfo* VisualInfo; /* The window's visual information */
510 SFG_WindowContextType Context; /* The menu window's WGL context */
514 * This structure describes a menu
516 typedef struct tagSFG_Window SFG_Window;
517 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
518 typedef struct tagSFG_Menu SFG_Menu;
522 void *UserData; /* User data passed back at callback */
523 int ID; /* The global menu ID */
524 SFG_List Entries; /* The menu entries list */
525 FGCBMenu Callback; /* The menu callback */
526 FGCBDestroy Destroy; /* Destruction callback */
527 GLboolean IsActive; /* Is the menu selected? */
528 int Width; /* Menu box width in pixels */
529 int Height; /* Menu box height in pixels */
530 int X, Y; /* Menu box raster position */
532 SFG_MenuEntry *ActiveEntry; /* Currently active entry in the menu */
533 SFG_Window *Window; /* Window for menu */
534 SFG_Window *ParentWindow; /* Window in which the menu is defined */
538 * This is a menu entry
540 struct tagSFG_MenuEntry
543 int ID; /* The menu entry ID (local) */
544 int Ordinal; /* The menu's ordinal number */
545 char* Text; /* The text to be displayed */
546 SFG_Menu* SubMenu; /* Optional sub-menu tree */
547 GLboolean IsActive; /* Is the entry highlighted? */
548 int Width; /* Label's width in pixels */
552 * A window, making part of freeglut windows hierarchy.
553 * Should be kept portable.
558 int ID; /* Window's ID number */
560 SFG_Context Window; /* Window and OpenGL context */
561 SFG_WindowState State; /* The window state */
562 void *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
563 void *UserData ; /* For use by user */
565 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
566 SFG_Menu* ActiveMenu; /* The window's active menu */
568 SFG_Window* Parent; /* The parent to this window */
569 SFG_List Children; /* The subwindows d.l. list */
571 GLboolean IsMenu; /* Set to 1 if we are a menu */
576 * A linked list structure of windows
578 typedef struct tagSFG_WindowList SFG_WindowList ;
579 struct tagSFG_WindowList
586 * This holds information about all the windows, menus etc.
588 typedef struct tagSFG_Structure SFG_Structure;
589 struct tagSFG_Structure
591 SFG_List Windows; /* The global windows list */
592 SFG_List Menus; /* The global menus list */
593 SFG_List WindowsToDestroy;
595 SFG_Window* Window; /* The currently active win. */
596 SFG_Menu* Menu; /* Same, but menu... */
598 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
600 SFG_Window* GameMode; /* The game mode window */
602 int WindowID; /* The new current window ID */
603 int MenuID; /* The new current menu ID */
607 * This structure is used for the enumeration purposes.
608 * You can easily extend its functionalities by declaring
609 * a structure containing enumerator's contents and custom
610 * data, then casting its pointer to (SFG_Enumerator *).
612 typedef struct tagSFG_Enumerator SFG_Enumerator;
613 struct tagSFG_Enumerator
615 GLboolean found; /* Used to terminate search */
616 void* data; /* Custom data pointer */
618 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
621 * The bitmap font structure
623 typedef struct tagSFG_Font SFG_Font;
626 char* Name; /* The source font name */
627 int Quantity; /* Number of chars in font */
628 int Height; /* Height of the characters */
629 const GLubyte** Characters; /* The characters mapping */
631 float xorig, yorig; /* Relative origin of the character */
635 * The stroke font structures
638 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
639 struct tagSFG_StrokeVertex
644 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
645 struct tagSFG_StrokeStrip
648 const SFG_StrokeVertex* Vertices;
651 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
652 struct tagSFG_StrokeChar
656 const SFG_StrokeStrip* Strips;
659 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
660 struct tagSFG_StrokeFont
662 char* Name; /* The source font name */
663 int Quantity; /* Number of chars in font */
664 GLfloat Height; /* Height of the characters */
665 const SFG_StrokeChar** Characters; /* The characters mapping */
668 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
671 * Freeglut display related stuff (initialized once per session)
673 extern SFG_Display fgDisplay;
676 * Freeglut internal structure
678 extern SFG_Structure fgStructure;
681 * The current freeglut settings
683 extern SFG_State fgState;
686 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
689 * A call to this function makes us sure that the Display and Structure
690 * subsystems have been properly initialized and are ready to be used
692 #define freeglut_assert_ready assert( fgState.Initialised );
695 * Following definitions are somewhat similiar to GLib's,
696 * but do not generate any log messages:
698 #define freeglut_return_if_fail( expr ) \
701 #define freeglut_return_val_if_fail( expr, val ) \
706 * A call to those macros assures us that there is a current
707 * window and menu set, respectively:
709 #define freeglut_assert_window assert( fgStructure.Window != NULL );
710 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
713 * The initialize and deinitialize functions get called on glutInit()
714 * and glutMainLoop() end respectively. They should create/clean up
715 * everything inside of the freeglut
717 void fgInitialize( const char* displayName );
718 void fgDeinitialize( void );
721 * Those two functions are used to create/destroy the freeglut internal
722 * structures. This actually happens when calling glutInit() and when
723 * quitting the glutMainLoop() (which actually happens, when all windows
726 void fgCreateStructure( void );
727 void fgDestroyStructure( void );
730 * A helper function to check if a display mode is possible to use
732 #if TARGET_HOST_UNIX_X11
733 XVisualInfo* fgChooseVisual( void );
737 * The window procedure for Win32 events handling
739 #if TARGET_HOST_WIN32
740 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
741 WPARAM wParam, LPARAM lParam );
742 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
743 unsigned char layer_type );
747 * Window creation, opening, closing and destruction.
748 * Also CallBack clearing/initialization.
749 * Defined in freeglut_structure.c, freeglut_window.c.
751 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
752 int x, int y, int w, int h,
753 GLboolean gameMode, GLboolean isMenu );
754 void fgSetWindow ( SFG_Window *window );
755 void fgOpenWindow( SFG_Window* window, const char* title,
756 int x, int y, int w, int h, GLboolean gameMode,
757 GLboolean isSubWindow );
758 void fgCloseWindow( SFG_Window* window );
759 void fgAddToWindowDestroyList ( SFG_Window* window );
760 void fgCloseWindows ();
761 void fgDestroyWindow( SFG_Window* window );
762 void fgClearCallBacks( SFG_Window *window );
765 * Menu creation and destruction. Defined in freeglut_structure.c
767 SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
768 void fgDestroyMenu( SFG_Menu* menu );
771 * Joystick device management functions, defined in freeglut_joystick.c
773 void fgJoystickInit( int ident );
774 void fgJoystickClose( void );
775 void fgJoystickPollWindow( SFG_Window* window );
778 * Helper function to enumerate through all registered windows
779 * and one to enumerate all of a window's subwindows...
781 * The GFunc callback for those functions will be defined as:
783 * void enumCallback( gpointer window, gpointer enumerator );
785 * where window is the enumerated (sub)window pointer (SFG_Window *),
786 * and userData is the a custom user-supplied pointer. Functions
787 * are defined and exported from freeglut_structure.c file.
789 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
790 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
791 SFG_Enumerator* enumerator );
794 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
795 * first window in the queue matching the specified window handle.
796 * The function is defined in freeglut_structure.c file.
798 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
801 * This function is similiar to the previous one, except it is
802 * looking for a specified (sub)window identifier. The function
803 * is defined in freeglut_structure.c file.
805 SFG_Window* fgWindowByID( int windowID );
808 * Looks up a menu given its ID. This is easier than fgWindowByXXX
809 * as all menus are placed in a single doubly linked list...
811 SFG_Menu* fgMenuByID( int menuID );
814 * The menu activation and deactivation the code. This is the meat
815 * of the menu user interface handling code...
817 void fgActivateMenu( SFG_Window* window, int button );
818 void fgExecuteMenuCallback( SFG_Menu* menu );
819 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
820 void fgDeactivateMenu( SFG_Window *window );
821 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
824 * This function gets called just before the buffers swap, so that
825 * freeglut can display the pull-down menus via OpenGL. The function
826 * is defined in freeglut_menu.c file.
828 void fgDisplayMenu( void );
831 * Display the mouse cursor using OpenGL calls. The function
832 * is defined in freeglut_cursor.c file.
834 void fgDisplayCursor( void );
837 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
839 long fgElapsedTime( void );
844 void fgListInit(SFG_List *list);
845 void fgListAppend(SFG_List *list, SFG_Node *node);
846 void fgListRemove(SFG_List *list, SFG_Node *node);
847 int fgListLength(SFG_List *list);
848 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);
851 * Error Messages functions
853 void fgError( const char *fmt, ... );
854 void fgWarning( const char *fmt, ... );
856 #endif /* FREEGLUT_INTERNAL_H */
858 /*** END OF FILE ***/