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 0
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
84 * The system-dependant include files should go here:
86 #if TARGET_HOST_UNIX_X11
89 #include <X11/Xatom.h>
90 #include <X11/keysym.h>
92 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
93 #include <X11/extensions/xf86vmode.h>
98 * Microsoft VisualC++ 5.0's <math.h> does not define the PI
101 # define M_PI 3.14159265358979323846
112 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
115 * Freeglut callbacks type definitions
117 typedef void (* FGCBDisplay )( void );
118 typedef void (* FGCBReshape )( int, int );
119 typedef void (* FGCBVisibility )( int );
120 typedef void (* FGCBKeyboard )( unsigned char, int, int );
121 typedef void (* FGCBSpecial )( int, int, int );
122 typedef void (* FGCBMouse )( int, int, int, int );
123 typedef void (* FGCBMouseWheel )( int, int, int, int );
124 typedef void (* FGCBMotion )( int, int );
125 typedef void (* FGCBPassive )( int, int );
126 typedef void (* FGCBEntry )( int );
127 typedef void (* FGCBWindowStatus )( int );
128 typedef void (* FGCBSelect )( int, int, int );
129 typedef void (* FGCBJoystick )( unsigned int, int, int, int );
130 typedef void (* FGCBKeyboardUp )( unsigned char, int, int );
131 typedef void (* FGCBSpecialUp )( int, int, int );
132 typedef void (* FGCBOverlayDisplay)( void );
133 typedef void (* FGCBSpaceMotion )( int, int, int );
134 typedef void (* FGCBSpaceRotation )( int, int, int );
135 typedef void (* FGCBSpaceButton )( int, int );
136 typedef void (* FGCBDials )( int, int );
137 typedef void (* FGCBButtonBox )( int, int );
138 typedef void (* FGCBTabletMotion )( int, int );
139 typedef void (* FGCBTabletButton )( int, int, int, int );
140 typedef void (* FGCBDestroy )( void );
143 * The global callbacks type definitions
145 typedef void (* FGCBIdle )( void );
146 typedef void (* FGCBTimer )( int );
147 typedef void (* FGCBMenuState )( int );
148 typedef void (* FGCBMenuStatus )( int, int, int );
151 * The callback used when creating/using menus
153 typedef void (* FGCBMenu )( int );
159 typedef struct tagSFG_List SFG_List;
167 * A list node structure
169 typedef struct tagSFG_Node SFG_Node;
177 * A helper structure holding two ints and a boolean
179 typedef struct tagSFG_XYUse SFG_XYUse;
182 GLint X, Y; /* The two integers... */
183 GLboolean Use; /* ...and a single boolean. */
187 * A helper structure holding a timeval and a boolean
189 typedef struct tagSFG_Time SFG_Time;
195 struct timeval Value;
201 * An enumeration containing the state of the GLUT execution:
202 * initializing, running, or stopping
206 GLUT_EXEC_STATE_INIT,
207 GLUT_EXEC_STATE_RUNNING,
212 * This structure holds different freeglut settings
214 typedef struct tagSFG_State SFG_State;
217 SFG_XYUse Position; /* The default windows' position */
218 SFG_XYUse Size; /* The default windows' size */
219 unsigned int DisplayMode; /* Display mode for new windows */
221 GLboolean Initalized; /* Freeglut has been initalized */
223 GLboolean ForceDirectContext; /* Force direct rendering? */
224 GLboolean TryDirectContext; /* What about giving a try to? */
226 GLboolean ForceIconic; /* New top windows are iconified */
227 GLboolean UseCurrentContext; /* New windows share with current */
229 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
230 GLboolean XSyncSwitch; /* X11 sync protocol switch */
232 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */
234 GLuint FPSInterval; /* Interval between FPS printfs */
235 GLuint SwapCount; /* Count of glutSwapBuffer calls */
236 GLuint SwapTime; /* Time of last SwapBuffers */
238 SFG_Time Time; /* Time that glutInit was called */
239 SFG_List Timers; /* The freeglut timer hooks */
241 FGCBIdle IdleCallback; /* The global idle callback */
243 GLboolean BuildingAMenu; /* Are we presently making a menu */
244 int ActiveMenus; /* Num. of currently active menus */
245 FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
246 FGCBMenuStatus MenuStatusCallback;
248 SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
249 int GameModeDepth; /* The pixel depth for game mode */
250 int GameModeRefresh; /* The refresh rate for game mode */
252 int ActionOnWindowClose; /* Action when user closes window */
254 fgExecutionState ExecState; /* Used for GLUT termination */
255 char *ProgramName; /* Name of the invoking program */
259 * The structure used by display initialization in freeglut_init.c
261 typedef struct tagSFG_Display SFG_Display;
262 struct tagSFG_Display
264 #if TARGET_HOST_UNIX_X11
265 Display* Display; /* The display we are being run in. */
266 int Screen; /* The screen we are about to use. */
267 Window RootWindow; /* The screen's root window. */
268 int Connection; /* The display's connection number */
269 Atom DeleteWindow; /* The window deletion atom */
271 #ifdef X_XF86VidModeGetModeLine
273 * XF86VidMode may be compilable even if it fails at runtime. Therefore,
274 * the validity of the VidMode has to be tracked
276 int DisplayModeValid; /* Flag that indicates runtime status*/
277 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
278 int DisplayModeClock; /* The display mode's refresh rate */
279 int DisplayViewPortX; /* saved X location of the viewport */
280 int DisplayViewPortY; /* saved Y location of the viewport */
281 int DisplayPointerX; /* saved X location of the pointer */
282 int DisplayPointerY; /* saved Y location of the pointer */
286 #elif TARGET_HOST_WIN32
287 HINSTANCE Instance; /* The application's instance */
288 DEVMODE DisplayMode; /* Desktop's display settings */
292 int ScreenWidth; /* The screen's width in pixels */
293 int ScreenHeight; /* The screen's height in pixels */
294 int ScreenWidthMM; /* The screen's width in milimeters */
295 int ScreenHeightMM; /* The screen's height in milimeters */
300 * The user can create any number of timer hooks
302 typedef struct tagSFG_Timer SFG_Timer;
306 int ID; /* The timer ID integer */
307 FGCBTimer Callback; /* The timer callback */
308 long TriggerTime; /* The timer trigger time */
312 * A window and its OpenGL context. The contents of this structure
313 * are highly dependant on the target operating system we aim at...
315 typedef struct tagSFG_Context SFG_Context;
316 struct tagSFG_Context
318 #if TARGET_HOST_UNIX_X11
319 Window Handle; /* The window's handle */
320 GLXContext Context; /* The OpenGL context */
321 XVisualInfo* VisualInfo; /* The window's visual information */
323 #elif TARGET_HOST_WIN32
324 HWND Handle; /* The window's handle */
325 HDC Device; /* The window's device context */
326 HGLRC Context; /* The window's WGL context */
330 int DoubleBuffered; /* Treat the window as double-buffered */
334 * Window's state description. This structure should be kept portable.
336 typedef struct tagSFG_WindowState SFG_WindowState;
337 struct tagSFG_WindowState
339 int Width; /* Window's width in pixels */
340 int Height; /* The same about the height */
342 GLboolean Redisplay; /* Do we have to redisplay? */
343 GLboolean Visible; /* Is the window visible now */
345 int Cursor; /* The currently selected cursor */
346 int Modifiers; /* The current ALT/SHIFT/CTRL state */
348 long JoystickPollRate; /* The joystick polling rate */
349 long JoystickLastPoll; /* When the last poll has happened */
351 int MouseX, MouseY; /* The most recent mouse position */
353 GLboolean IsGameMode; /* Is this the game mode window? */
355 #if TARGET_HOST_WIN32
356 GLboolean NeedToResize; /* Do we need to explicitly resize? */
362 * FETCH_WCB() is used as:
364 * FETCH_WCB( window, Visibility );
366 * ...where {window} is the freeglut window to fetch the callback from,
367 * {Visibility} is the window-specific callback to fetch.
369 * The result is correctly type-cast to the callback function pointer
372 #define FETCH_WCB(window,cbname) \
373 ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
376 * INVOKE_WCB() is used as:
378 * INVOKE_WCB( window, Visibility, ( status ) );
380 * ...where {window} is the freeglut window,
381 * {Visibility} is the window-specific callback,
382 * {(status)} is the parameter list.
384 * The callback is invoked as:
386 * callback( status );
388 * ...so the parentheses are REQUIRED in the {arg_list}.
390 * NOTE that it does a sanity-check and also sets the
394 #define INVOKE_WCB(window,cbname,arg_list) \
397 if( FETCH_WCB( window, cbname ) ) \
399 fgSetWindow( &window ); \
400 FETCH_WCB( window, cbname ) arg_list; \
405 * The window callbacks the user can supply us with. Should be kept portable.
407 * This enumeration provides the freeglut CallBack numbers.
408 * The symbolic constants are indices into a window's array of
409 * function callbacks. The names are formed by splicing a common
410 * prefix onto the callback's base name. (This was originally
411 * done so that an early stage of development could live side-by-
412 * side with the old callback code. The old callback code used
413 * the bare callback's name as a structure member, so I used a
414 * prefix for the array index name.)
416 * XXX For consistancy, perhaps the prefix should match the
417 * XXX FETCH* and INVOKE* macro suffices. I.e., WCB_, rather than
438 /* Presently ignored */
449 /* Always make this the LAST one */
455 * This structure holds the OpenGL rendering context for all the menu windows
457 typedef struct tagSFG_MenuContext SFG_MenuContext;
458 struct tagSFG_MenuContext
460 #if TARGET_HOST_UNIX_X11
461 GLXContext Context; /* The menu OpenGL context */
462 XVisualInfo* VisualInfo; /* The window's visual information */
463 #elif TARGET_HOST_WIN32
464 HGLRC Context; /* The menu window's WGL context */
470 * This structure describes a menu
472 typedef struct tagSFG_Window SFG_Window;
473 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
474 typedef struct tagSFG_Menu SFG_Menu;
478 void *UserData; /* User data passed back at callback */
479 int ID; /* The global menu ID */
480 SFG_List Entries; /* The menu entries list */
481 FGCBMenu Callback; /* The menu callback */
482 FGCBDestroy Destroy; /* Destruction callback */
483 GLboolean IsActive; /* Is the menu selected? */
484 int Width; /* Menu box width in pixels */
485 int Height; /* Menu box height in pixels */
486 int X, Y; /* Menu box raster position */
488 SFG_MenuEntry *ActiveEntry; /* Currently active entry in the menu */
489 SFG_Window *Window; /* Window for menu */
490 SFG_Window *ParentWindow; /* Window in which the menu is defined */
494 * This is a menu entry
496 struct tagSFG_MenuEntry
499 int ID; /* The menu entry ID (local) */
500 int Ordinal; /* The menu's ordinal number */
501 char* Text; /* The text to be displayed */
502 SFG_Menu* SubMenu; /* Optional sub-menu tree */
503 GLboolean IsActive; /* Is the entry highlighted? */
504 int Width; /* Label's width in pixels */
508 * A window, making part of freeglut windows hierarchy.
509 * Should be kept portable.
514 int ID; /* Window's ID number */
516 SFG_Context Window; /* Window and OpenGL context */
517 SFG_WindowState State; /* The window state */
518 void *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
519 void *UserData ; /* For use by user */
521 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
522 SFG_Menu* ActiveMenu; /* The window's active menu */
524 SFG_Window* Parent; /* The parent to this window */
525 SFG_List Children; /* The subwindows d.l. list */
527 GLboolean IsMenu; /* Set to 1 if we are a menu */
532 * A linked list structure of windows
534 typedef struct tagSFG_WindowList SFG_WindowList;
535 struct tagSFG_WindowList
538 GLboolean needToClose;
539 SFG_WindowList *next;
543 * This holds information about all the windows, menus etc.
545 typedef struct tagSFG_Structure SFG_Structure;
546 struct tagSFG_Structure
548 SFG_List Windows; /* The global windows list */
549 SFG_List Menus; /* The global menus list */
551 SFG_Window* Window; /* The currently active win. */
552 SFG_Menu* Menu; /* Same, but menu... */
554 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
556 SFG_Window* GameMode; /* The game mode window */
558 int WindowID; /* The new current window ID */
559 int MenuID; /* The new current menu ID */
563 * This structure is used for the enumeration purposes.
564 * You can easily extend its functionalities by declaring
565 * a structure containing enumerator's contents and custom
566 * data, then casting its pointer to (SFG_Enumerator *).
568 typedef struct tagSFG_Enumerator SFG_Enumerator;
569 struct tagSFG_Enumerator
571 GLboolean found; /* Used to terminate search */
572 void* data; /* Custom data pointer */
574 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
577 * The bitmap font structure
579 typedef struct tagSFG_Font SFG_Font;
582 char* Name; /* The source font name */
583 int Quantity; /* Number of chars in font */
584 int Height; /* Height of the characters */
585 const GLubyte** Characters; /* The characters mapping */
587 float xorig, yorig; /* Relative origin of the character */
591 * The stroke font structures
594 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
595 struct tagSFG_StrokeVertex
600 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
601 struct tagSFG_StrokeStrip
604 const SFG_StrokeVertex* Vertices;
607 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
608 struct tagSFG_StrokeChar
612 const SFG_StrokeStrip* Strips;
615 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
616 struct tagSFG_StrokeFont
618 char* Name; /* The source font name */
619 int Quantity; /* Number of chars in font */
620 GLfloat Height; /* Height of the characters */
621 const SFG_StrokeChar** Characters; /* The characters mapping */
624 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
627 * Freeglut display related stuff (initialized once per session)
629 extern SFG_Display fgDisplay;
632 * Freeglut internal structure
634 extern SFG_Structure fgStructure;
637 * The current freeglut settings
639 extern SFG_State fgState;
642 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
645 * A call to this function makes us sure that the Display and Structure
646 * subsystems have been properly initialized and are ready to be used
648 #define freeglut_assert_ready assert( fgState.Initalized );
651 * Following definitions are somewhat similiar to GLib's,
652 * but do not generate any log messages:
654 #define freeglut_return_if_fail( expr ) \
657 #define freeglut_return_val_if_fail( expr, val ) \
662 * A call to those macros assures us that there is a current
663 * window and menu set, respectively:
665 #define freeglut_assert_window assert( fgStructure.Window != NULL );
666 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
669 * The initialize and deinitialize functions get called on glutInit()
670 * and glutMainLoop() end respectively. They should create/clean up
671 * everything inside of the freeglut
673 void fgInitialize( const char* displayName );
674 void fgDeinitialize( void );
677 * Those two functions are used to create/destroy the freeglut internal
678 * structures. This actually happens when calling glutInit() and when
679 * quitting the glutMainLoop() (which actually happens, when all windows
682 void fgCreateStructure( void );
683 void fgDestroyStructure( void );
686 * A helper function to check if a display mode is possible to use
688 #if TARGET_HOST_UNIX_X11
689 XVisualInfo* fgChooseVisual( void );
693 * The window procedure for Win32 events handling
695 #if TARGET_HOST_WIN32
696 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
697 WPARAM wParam, LPARAM lParam );
698 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
699 unsigned char layer_type );
703 * Window creation, opening, closing and destruction.
704 * Also CallBack clearing/initialization.
705 * Defined in freeglut_structure.c, freeglut_window.c.
707 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
708 int x, int y, int w, int h, GLboolean gameMode );
709 void fgSetWindow ( SFG_Window *window );
710 void fgOpenWindow( SFG_Window* window, const char* title,
711 int x, int y, int w, int h, GLboolean gameMode,
712 GLboolean isSubWindow );
713 void fgCloseWindow( SFG_Window* window );
714 void fgAddToWindowDestroyList ( SFG_Window* window,
715 GLboolean needToClose );
716 void fgCloseWindows( );
717 void fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
718 void fgClearCallBacks( SFG_Window *window );
721 * Menu creation and destruction. Defined in freeglut_structure.c
723 SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
724 void fgDestroyMenu( SFG_Menu* menu );
727 * Joystick device management functions, defined in freeglut_joystick.c
729 void fgJoystickInit( int ident );
730 void fgJoystickClose( void );
731 void fgJoystickPollWindow( SFG_Window* window );
734 * Helper function to enumerate through all registered windows
735 * and one to enumerate all of a window's subwindows...
737 * The GFunc callback for those functions will be defined as:
739 * void enumCallback( gpointer window, gpointer enumerator );
741 * where window is the enumerated (sub)window pointer (SFG_Window *),
742 * and userData is the a custom user-supplied pointer. Functions
743 * are defined and exported from freeglut_structure.c file.
745 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
746 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
747 SFG_Enumerator* enumerator );
750 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
751 * first window in the queue matching the specified window handle.
752 * The function is defined in freeglut_structure.c file.
754 #if TARGET_HOST_UNIX_X11
755 SFG_Window* fgWindowByHandle( Window hWindow );
756 #elif TARGET_HOST_WIN32
757 SFG_Window* fgWindowByHandle( HWND hWindow );
761 * This function is similiar to the previous one, except it is
762 * looking for a specified (sub)window identifier. The function
763 * is defined in freeglut_structure.c file.
765 SFG_Window* fgWindowByID( int windowID );
768 * Looks up a menu given its ID. This is easier that fgWindowByXXX
769 * as all menus are placed in a single doubly linked list...
771 SFG_Menu* fgMenuByID( int menuID );
774 * The menu activation and deactivation the code. This is the meat
775 * of the menu user interface handling code...
777 void fgActivateMenu( SFG_Window* window, int button );
778 void fgExecuteMenuCallback( SFG_Menu* menu );
779 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
780 void fgDeactivateMenu( SFG_Window *window );
781 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
784 * This function gets called just before the buffers swap, so that
785 * freeglut can display the pull-down menus via OpenGL. The function
786 * is defined in freeglut_menu.c file.
788 void fgDisplayMenu( void );
791 * Display the mouse cursor using OpenGL calls. The function
792 * is defined in freeglut_cursor.c file.
794 void fgDisplayCursor( void );
797 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
799 long fgElapsedTime( void );
804 void fgListInit(SFG_List *list);
805 void fgListAppend(SFG_List *list, SFG_Node *node);
806 void fgListRemove(SFG_List *list, SFG_Node *node);
807 int fgListLength(SFG_List *list);
810 * Error Messages functions
812 void fgError( const char *fmt, ... );
813 void fgWarning( const char *fmt, ... );
815 #endif /* FREEGLUT_INTERNAL_H */
817 /*** END OF FILE ***/