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(_WIN32_WCE)
40 # define TARGET_HOST_UNIX_X11 0
41 # define TARGET_HOST_WIN32 0
42 # define TARGET_HOST_WINCE 1
43 #elif defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)
44 # define TARGET_HOST_UNIX_X11 0
45 # define TARGET_HOST_WIN32 1
46 # define TARGET_HOST_WINCE 0
48 # define TARGET_HOST_UNIX_X11 1
49 # define TARGET_HOST_WIN32 0
50 # define TARGET_HOST_WINCE 0
53 #define FREEGLUT_MAX_MENUS 3
56 * Somehow all Win32 include headers depend on this one:
66 #define strdup _strdup
70 * Those files should be available on every platform.
80 #if TARGET_HOST_UNIX_X11
86 * The system-dependant include files should go here:
88 #if TARGET_HOST_UNIX_X11
91 #include <X11/Xatom.h>
92 #include <X11/keysym.h>
94 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
95 #include <X11/extensions/xf86vmode.h>
100 * Microsoft VisualC++ 5.0's <math.h> does not define the PI
103 # define M_PI 3.14159265358979323846
114 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
117 * Freeglut callbacks type definitions
119 typedef void (* FGCBDisplay )( void );
120 typedef void (* FGCBReshape )( int, int );
121 typedef void (* FGCBVisibility )( int );
122 typedef void (* FGCBKeyboard )( unsigned char, int, int );
123 typedef void (* FGCBSpecial )( int, int, int );
124 typedef void (* FGCBMouse )( int, int, int, int );
125 typedef void (* FGCBMouseWheel )( int, int, int, int );
126 typedef void (* FGCBMotion )( int, int );
127 typedef void (* FGCBPassive )( int, int );
128 typedef void (* FGCBEntry )( int );
129 typedef void (* FGCBWindowStatus )( int );
130 typedef void (* FGCBSelect )( int, int, int );
131 typedef void (* FGCBJoystick )( unsigned int, int, int, int );
132 typedef void (* FGCBKeyboardUp )( unsigned char, int, int );
133 typedef void (* FGCBSpecialUp )( int, int, int );
134 typedef void (* FGCBOverlayDisplay)( void );
135 typedef void (* FGCBSpaceMotion )( int, int, int );
136 typedef void (* FGCBSpaceRotation )( int, int, int );
137 typedef void (* FGCBSpaceButton )( int, int );
138 typedef void (* FGCBDials )( int, int );
139 typedef void (* FGCBButtonBox )( int, int );
140 typedef void (* FGCBTabletMotion )( int, int );
141 typedef void (* FGCBTabletButton )( int, int, int, int );
142 typedef void (* FGCBDestroy )( void );
145 * The global callbacks type definitions
147 typedef void (* FGCBIdle )( void );
148 typedef void (* FGCBTimer )( int );
149 typedef void (* FGCBMenuState )( int );
150 typedef void (* FGCBMenuStatus )( int, int, int );
153 * The callback used when creating/using menus
155 typedef void (* FGCBMenu )( int );
161 typedef struct tagSFG_List SFG_List;
169 * A list node structure
171 typedef struct tagSFG_Node SFG_Node;
179 * A helper structure holding two ints and a boolean
181 typedef struct tagSFG_XYUse SFG_XYUse;
184 GLint X, Y; /* The two integers... */
185 GLboolean Use; /* ...and a single boolean. */
189 * A helper structure holding a timeval and a boolean
191 typedef struct tagSFG_Time SFG_Time;
194 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
197 struct timeval Value;
203 * An enumeration containing the state of the GLUT execution:
204 * initializing, running, or stopping
208 GLUT_EXEC_STATE_INIT,
209 GLUT_EXEC_STATE_RUNNING,
214 * This structure holds different freeglut settings
216 typedef struct tagSFG_State SFG_State;
219 SFG_XYUse Position; /* The default windows' position */
220 SFG_XYUse Size; /* The default windows' size */
221 unsigned int DisplayMode; /* Display mode for new windows */
223 GLboolean Initialised; /* freeglut has been initialised */
225 int DirectContext; /* Direct rendering state */
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 int KeyRepeat; /* Global key repeat mode. */
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 || TARGET_HOST_WINCE
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 || TARGET_HOST_WINCE
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 Pixmap Pixmap; /* Used for offscreen rendering */
342 /* GLXPixmap GLXPixMap; */ /* Used for offscreen rendering */
343 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
344 HDC Device; /* The window's device context */
347 int DoubleBuffered; /* Treat the window as double-buffered */
351 * Window's state description. This structure should be kept portable.
353 typedef struct tagSFG_WindowState SFG_WindowState;
354 struct tagSFG_WindowState
356 int Width; /* Window's width in pixels */
357 int Height; /* The same about the height */
358 int OldWidth; /* Window width from before a resize */
359 int OldHeight; /* " height " " " " */
361 GLboolean Redisplay; /* Do we have to redisplay? */
362 GLboolean Visible; /* Is the window visible now */
364 int Cursor; /* The currently selected cursor */
366 long JoystickPollRate; /* The joystick polling rate */
367 long JoystickLastPoll; /* When the last poll happened */
369 int MouseX, MouseY; /* The most recent mouse position */
371 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */
372 GLboolean KeyRepeating; /* Currently in repeat mode */
374 GLboolean IsGameMode; /* Is this the game mode window? */
375 GLboolean NeedToResize; /* Do we need to resize the window? */
380 * SET_WCB() is used as:
382 * SET_WCB( window, Visibility, func );
384 * ...where {window} is the freeglut window to set the callback,
385 * {Visibility} is the window-specific callback to set,
386 * {func} is a function-pointer.
388 * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used,
389 * but this can cause warnings because the FETCH_WCB() macro type-
390 * casts its result, and a type-cast value shouldn't be an lvalue.
392 * The {if( FETCH_WCB( ... ) != func )} test is to do type-checking
393 * and for no other reason. Since it's hidden in the macro, the
394 * ugliness is felt to be rather benign.
396 #define SET_WCB(window,cbname,func) \
399 if( FETCH_WCB( window, cbname ) != func ) \
400 (((window).CallBacks[CB_ ## cbname]) = (void *) func); \
404 * FETCH_WCB() is used as:
406 * FETCH_WCB( window, Visibility );
408 * ...where {window} is the freeglut window to fetch the callback from,
409 * {Visibility} is the window-specific callback to fetch.
411 * The result is correctly type-cast to the callback function pointer
414 #define FETCH_WCB(window,cbname) \
415 ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
418 * INVOKE_WCB() is used as:
420 * INVOKE_WCB( window, Visibility, ( status ) );
422 * ...where {window} is the freeglut window,
423 * {Visibility} is the window-specific callback,
424 * {(status)} is the parameter list.
426 * The callback is invoked as:
428 * callback( status );
430 * ...so the parentheses are REQUIRED in the {arg_list}.
432 * NOTE that it does a sanity-check and also sets the
436 #define INVOKE_WCB(window,cbname,arg_list) \
439 if( FETCH_WCB( window, cbname ) ) \
441 fgSetWindow( &window ); \
442 FETCH_WCB( window, cbname ) arg_list; \
447 * The window callbacks the user can supply us with. Should be kept portable.
449 * This enumeration provides the freeglut CallBack numbers.
450 * The symbolic constants are indices into a window's array of
451 * function callbacks. The names are formed by splicing a common
452 * prefix onto the callback's base name. (This was originally
453 * done so that an early stage of development could live side-by-
454 * side with the old callback code. The old callback code used
455 * the bare callback's name as a structure member, so I used a
456 * prefix for the array index name.)
458 * XXX For consistancy, perhaps the prefix should match the
459 * XXX FETCH* and INVOKE* macro suffices. I.e., WCB_, rather than
480 /* Presently ignored */
491 /* Always make this the LAST one */
497 * This structure holds the OpenGL rendering context for all the menu windows
499 typedef struct tagSFG_MenuContext SFG_MenuContext;
500 struct tagSFG_MenuContext
502 #if TARGET_HOST_UNIX_X11
503 XVisualInfo* VisualInfo; /* The window's visual information */
506 SFG_WindowContextType Context; /* The menu window's WGL context */
510 * This structure describes a menu
512 typedef struct tagSFG_Window SFG_Window;
513 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
514 typedef struct tagSFG_Menu SFG_Menu;
518 void *UserData; /* User data passed back at callback */
519 int ID; /* The global menu ID */
520 SFG_List Entries; /* The menu entries list */
521 FGCBMenu Callback; /* The menu callback */
522 FGCBDestroy Destroy; /* Destruction callback */
523 GLboolean IsActive; /* Is the menu selected? */
524 int Width; /* Menu box width in pixels */
525 int Height; /* Menu box height in pixels */
526 int X, Y; /* Menu box raster position */
528 SFG_MenuEntry *ActiveEntry; /* Currently active entry in the menu */
529 SFG_Window *Window; /* Window for menu */
530 SFG_Window *ParentWindow; /* Window in which the menu is defined */
534 * This is a menu entry
536 struct tagSFG_MenuEntry
539 int ID; /* The menu entry ID (local) */
540 int Ordinal; /* The menu's ordinal number */
541 char* Text; /* The text to be displayed */
542 SFG_Menu* SubMenu; /* Optional sub-menu tree */
543 GLboolean IsActive; /* Is the entry highlighted? */
544 int Width; /* Label's width in pixels */
548 * A window, making part of freeglut windows hierarchy.
549 * Should be kept portable.
554 int ID; /* Window's ID number */
556 SFG_Context Window; /* Window and OpenGL context */
557 SFG_WindowState State; /* The window state */
558 void *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
559 void *UserData ; /* For use by user */
561 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
562 SFG_Menu* ActiveMenu; /* The window's active menu */
564 SFG_Window* Parent; /* The parent to this window */
565 SFG_List Children; /* The subwindows d.l. list */
567 GLboolean IsMenu; /* Set to 1 if we are a menu */
572 * A linked list structure of windows
574 typedef struct tagSFG_WindowList SFG_WindowList ;
575 struct tagSFG_WindowList
582 * This holds information about all the windows, menus etc.
584 typedef struct tagSFG_Structure SFG_Structure;
585 struct tagSFG_Structure
587 SFG_List Windows; /* The global windows list */
588 SFG_List Menus; /* The global menus list */
589 SFG_List WindowsToDestroy;
591 SFG_Window* Window; /* The currently active win. */
592 SFG_Menu* Menu; /* Same, but menu... */
594 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
596 SFG_Window* GameMode; /* The game mode window */
598 int WindowID; /* The new current window ID */
599 int MenuID; /* The new current menu ID */
603 * This structure is used for the enumeration purposes.
604 * You can easily extend its functionalities by declaring
605 * a structure containing enumerator's contents and custom
606 * data, then casting its pointer to (SFG_Enumerator *).
608 typedef struct tagSFG_Enumerator SFG_Enumerator;
609 struct tagSFG_Enumerator
611 GLboolean found; /* Used to terminate search */
612 void* data; /* Custom data pointer */
614 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
617 * The bitmap font structure
619 typedef struct tagSFG_Font SFG_Font;
622 char* Name; /* The source font name */
623 int Quantity; /* Number of chars in font */
624 int Height; /* Height of the characters */
625 const GLubyte** Characters; /* The characters mapping */
627 float xorig, yorig; /* Relative origin of the character */
631 * The stroke font structures
634 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
635 struct tagSFG_StrokeVertex
640 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
641 struct tagSFG_StrokeStrip
644 const SFG_StrokeVertex* Vertices;
647 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
648 struct tagSFG_StrokeChar
652 const SFG_StrokeStrip* Strips;
655 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
656 struct tagSFG_StrokeFont
658 char* Name; /* The source font name */
659 int Quantity; /* Number of chars in font */
660 GLfloat Height; /* Height of the characters */
661 const SFG_StrokeChar** Characters; /* The characters mapping */
664 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
667 * Freeglut display related stuff (initialized once per session)
669 extern SFG_Display fgDisplay;
672 * Freeglut internal structure
674 extern SFG_Structure fgStructure;
677 * The current freeglut settings
679 extern SFG_State fgState;
682 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
685 * A call to this function makes us sure that the Display and Structure
686 * subsystems have been properly initialized and are ready to be used
688 #define freeglut_assert_ready assert( fgState.Initialised );
691 * Following definitions are somewhat similiar to GLib's,
692 * but do not generate any log messages:
694 #define freeglut_return_if_fail( expr ) \
697 #define freeglut_return_val_if_fail( expr, val ) \
702 * A call to those macros assures us that there is a current
703 * window and menu set, respectively:
705 #define freeglut_assert_window assert( fgStructure.Window != NULL );
706 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
709 * The initialize and deinitialize functions get called on glutInit()
710 * and glutMainLoop() end respectively. They should create/clean up
711 * everything inside of the freeglut
713 void fgInitialize( const char* displayName );
714 void fgDeinitialize( void );
717 * Those two functions are used to create/destroy the freeglut internal
718 * structures. This actually happens when calling glutInit() and when
719 * quitting the glutMainLoop() (which actually happens, when all windows
722 void fgCreateStructure( void );
723 void fgDestroyStructure( void );
726 * A helper function to check if a display mode is possible to use
728 #if TARGET_HOST_UNIX_X11
729 XVisualInfo* fgChooseVisual( void );
733 * The window procedure for Win32 events handling
735 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
736 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
737 WPARAM wParam, LPARAM lParam );
738 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
739 unsigned char layer_type );
743 * Window creation, opening, closing and destruction.
744 * Also CallBack clearing/initialization.
745 * Defined in freeglut_structure.c, freeglut_window.c.
747 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
748 int x, int y, int w, int h,
749 GLboolean gameMode, GLboolean isMenu );
750 void fgSetWindow ( SFG_Window *window );
751 void fgOpenWindow( SFG_Window* window, const char* title,
752 int x, int y, int w, int h, GLboolean gameMode,
753 GLboolean isSubWindow );
754 void fgCloseWindow( SFG_Window* window );
755 void fgAddToWindowDestroyList ( SFG_Window* window );
756 void fgCloseWindows ();
757 void fgDestroyWindow( SFG_Window* window );
758 void fgClearCallBacks( SFG_Window *window );
761 * Menu creation and destruction. Defined in freeglut_structure.c
763 SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
764 void fgDestroyMenu( SFG_Menu* menu );
767 * Joystick device management functions, defined in freeglut_joystick.c
769 void fgJoystickInit( int ident );
770 void fgJoystickClose( void );
771 void fgJoystickPollWindow( SFG_Window* window );
774 * Helper function to enumerate through all registered windows
775 * and one to enumerate all of a window's subwindows...
777 * The GFunc callback for those functions will be defined as:
779 * void enumCallback( gpointer window, gpointer enumerator );
781 * where window is the enumerated (sub)window pointer (SFG_Window *),
782 * and userData is the a custom user-supplied pointer. Functions
783 * are defined and exported from freeglut_structure.c file.
785 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
786 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
787 SFG_Enumerator* enumerator );
790 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
791 * first window in the queue matching the specified window handle.
792 * The function is defined in freeglut_structure.c file.
794 SFG_Window* fgWindowByHandle( SFG_WindowHandleType hWindow );
797 * This function is similiar to the previous one, except it is
798 * looking for a specified (sub)window identifier. The function
799 * is defined in freeglut_structure.c file.
801 SFG_Window* fgWindowByID( int windowID );
804 * Looks up a menu given its ID. This is easier than fgWindowByXXX
805 * as all menus are placed in a single doubly linked list...
807 SFG_Menu* fgMenuByID( int menuID );
810 * The menu activation and deactivation the code. This is the meat
811 * of the menu user interface handling code...
813 void fgActivateMenu( SFG_Window* window, int button );
814 void fgExecuteMenuCallback( SFG_Menu* menu );
815 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
816 void fgDeactivateMenu( SFG_Window *window );
817 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
820 * This function gets called just before the buffers swap, so that
821 * freeglut can display the pull-down menus via OpenGL. The function
822 * is defined in freeglut_menu.c file.
824 void fgDisplayMenu( void );
827 * Display the mouse cursor using OpenGL calls. The function
828 * is defined in freeglut_cursor.c file.
830 void fgDisplayCursor( void );
833 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
835 long fgElapsedTime( void );
840 void fgListInit(SFG_List *list);
841 void fgListAppend(SFG_List *list, SFG_Node *node);
842 void fgListRemove(SFG_List *list, SFG_Node *node);
843 int fgListLength(SFG_List *list);
844 void fgListInsert(SFG_List *list, SFG_Node *next, SFG_Node *node);
847 * Error Messages functions
849 void fgError( const char *fmt, ... );
850 void fgWarning( const char *fmt, ... );
852 #endif /* FREEGLUT_INTERNAL_H */
854 /*** END OF FILE ***/