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
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 */
243 FGCBIdle IdleCallback; /* The global idle callback */
245 int ActiveMenus; /* Num. of currently active menus */
246 FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
247 FGCBMenuStatus MenuStatusCallback;
249 SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
250 int GameModeDepth; /* The pixel depth for game mode */
251 int GameModeRefresh; /* The refresh rate for game mode */
253 int ActionOnWindowClose; /* Action when user closes window */
255 fgExecutionState ExecState; /* Used for GLUT termination */
256 char *ProgramName; /* Name of the invoking program */
260 * The structure used by display initialization in freeglut_init.c
262 typedef struct tagSFG_Display SFG_Display;
263 struct tagSFG_Display
265 #if TARGET_HOST_UNIX_X11
266 Display* Display; /* The display we are being run in. */
267 int Screen; /* The screen we are about to use. */
268 Window RootWindow; /* The screen's root window. */
269 int Connection; /* The display's connection number */
270 Atom DeleteWindow; /* The window deletion atom */
272 #ifdef X_XF86VidModeGetModeLine
274 * XF86VidMode may be compilable even if it fails at runtime. Therefore,
275 * the validity of the VidMode has to be tracked
277 int DisplayModeValid; /* Flag that indicates runtime status*/
278 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
279 int DisplayModeClock; /* The display mode's refresh rate */
280 int DisplayViewPortX; /* saved X location of the viewport */
281 int DisplayViewPortY; /* saved Y location of the viewport */
282 int DisplayPointerX; /* saved X location of the pointer */
283 int DisplayPointerY; /* saved Y location of the pointer */
287 #elif TARGET_HOST_WIN32
288 HINSTANCE Instance; /* The application's instance */
289 DEVMODE DisplayMode; /* Desktop's display settings */
293 int ScreenWidth; /* The screen's width in pixels */
294 int ScreenHeight; /* The screen's height in pixels */
295 int ScreenWidthMM; /* The screen's width in milimeters */
296 int ScreenHeightMM; /* The screen's height in milimeters */
301 * The user can create any number of timer hooks
303 typedef struct tagSFG_Timer SFG_Timer;
307 int ID; /* The timer ID integer */
308 FGCBTimer Callback; /* The timer callback */
309 long TriggerTime; /* The timer trigger time */
313 * A window and its OpenGL context. The contents of this structure
314 * are highly dependant on the target operating system we aim at...
316 typedef struct tagSFG_Context SFG_Context;
317 struct tagSFG_Context
319 #if TARGET_HOST_UNIX_X11
320 Window Handle; /* The window's handle */
321 GLXContext Context; /* The OpenGL context */
322 XVisualInfo* VisualInfo; /* The window's visual information */
324 #elif TARGET_HOST_WIN32
325 HWND Handle; /* The window's handle */
326 HDC Device; /* The window's device context */
327 HGLRC Context; /* The window's WGL context */
331 int DoubleBuffered; /* Treat the window as double-buffered */
335 * Window's state description. This structure should be kept portable.
337 typedef struct tagSFG_WindowState SFG_WindowState;
338 struct tagSFG_WindowState
340 int Width; /* Window's width in pixels */
341 int Height; /* The same about the height */
343 GLboolean Redisplay; /* Do we have to redisplay? */
344 GLboolean Visible; /* Is the window visible now */
346 int Cursor; /* The currently selected cursor */
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 GLboolean NeedToResize; /* Do we need to resize the window? */
360 * FETCH_WCB() is used as:
362 * FETCH_WCB( window, Visibility );
364 * ...where {window} is the freeglut window to fetch the callback from,
365 * {Visibility} is the window-specific callback to fetch.
367 * The result is correctly type-cast to the callback function pointer
370 #define FETCH_WCB(window,cbname) \
371 ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
374 * INVOKE_WCB() is used as:
376 * INVOKE_WCB( window, Visibility, ( status ) );
378 * ...where {window} is the freeglut window,
379 * {Visibility} is the window-specific callback,
380 * {(status)} is the parameter list.
382 * The callback is invoked as:
384 * callback( status );
386 * ...so the parentheses are REQUIRED in the {arg_list}.
388 * NOTE that it does a sanity-check and also sets the
392 #define INVOKE_WCB(window,cbname,arg_list) \
395 if( FETCH_WCB( window, cbname ) ) \
397 fgSetWindow( &window ); \
398 FETCH_WCB( window, cbname ) arg_list; \
403 * The window callbacks the user can supply us with. Should be kept portable.
405 * This enumeration provides the freeglut CallBack numbers.
406 * The symbolic constants are indices into a window's array of
407 * function callbacks. The names are formed by splicing a common
408 * prefix onto the callback's base name. (This was originally
409 * done so that an early stage of development could live side-by-
410 * side with the old callback code. The old callback code used
411 * the bare callback's name as a structure member, so I used a
412 * prefix for the array index name.)
414 * XXX For consistancy, perhaps the prefix should match the
415 * XXX FETCH* and INVOKE* macro suffices. I.e., WCB_, rather than
436 /* Presently ignored */
447 /* Always make this the LAST one */
453 * This structure holds the OpenGL rendering context for all the menu windows
455 typedef struct tagSFG_MenuContext SFG_MenuContext;
456 struct tagSFG_MenuContext
458 #if TARGET_HOST_UNIX_X11
459 GLXContext Context; /* The menu OpenGL context */
460 XVisualInfo* VisualInfo; /* The window's visual information */
461 #elif TARGET_HOST_WIN32
462 HGLRC Context; /* The menu window's WGL context */
468 * This structure describes a menu
470 typedef struct tagSFG_Window SFG_Window;
471 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
472 typedef struct tagSFG_Menu SFG_Menu;
476 void *UserData; /* User data passed back at callback */
477 int ID; /* The global menu ID */
478 SFG_List Entries; /* The menu entries list */
479 FGCBMenu Callback; /* The menu callback */
480 FGCBDestroy Destroy; /* Destruction callback */
481 GLboolean IsActive; /* Is the menu selected? */
482 int Width; /* Menu box width in pixels */
483 int Height; /* Menu box height in pixels */
484 int X, Y; /* Menu box raster position */
486 SFG_MenuEntry *ActiveEntry; /* Currently active entry in the menu */
487 SFG_Window *Window; /* Window for menu */
488 SFG_Window *ParentWindow; /* Window in which the menu is defined */
492 * This is a menu entry
494 struct tagSFG_MenuEntry
497 int ID; /* The menu entry ID (local) */
498 int Ordinal; /* The menu's ordinal number */
499 char* Text; /* The text to be displayed */
500 SFG_Menu* SubMenu; /* Optional sub-menu tree */
501 GLboolean IsActive; /* Is the entry highlighted? */
502 int Width; /* Label's width in pixels */
506 * A window, making part of freeglut windows hierarchy.
507 * Should be kept portable.
512 int ID; /* Window's ID number */
514 SFG_Context Window; /* Window and OpenGL context */
515 SFG_WindowState State; /* The window state */
516 void *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
517 void *UserData ; /* For use by user */
519 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
520 SFG_Menu* ActiveMenu; /* The window's active menu */
522 SFG_Window* Parent; /* The parent to this window */
523 SFG_List Children; /* The subwindows d.l. list */
525 GLboolean IsMenu; /* Set to 1 if we are a menu */
530 * A linked list structure of windows
532 typedef struct tagSFG_WindowList SFG_WindowList ;
533 struct tagSFG_WindowList
536 GLboolean needToClose ;
537 SFG_WindowList *next ;
541 * This holds information about all the windows, menus etc.
543 typedef struct tagSFG_Structure SFG_Structure;
544 struct tagSFG_Structure
546 SFG_List Windows; /* The global windows list */
547 SFG_List Menus; /* The global menus list */
549 SFG_Window* Window; /* The currently active win. */
550 SFG_Menu* Menu; /* Same, but menu... */
552 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
554 SFG_Window* GameMode; /* The game mode window */
556 int WindowID; /* The new current window ID */
557 int MenuID; /* The new current menu ID */
561 * This structure is used for the enumeration purposes.
562 * You can easily extend its functionalities by declaring
563 * a structure containing enumerator's contents and custom
564 * data, then casting its pointer to (SFG_Enumerator *).
566 typedef struct tagSFG_Enumerator SFG_Enumerator;
567 struct tagSFG_Enumerator
569 GLboolean found; /* Used to terminate search */
570 void* data; /* Custom data pointer */
572 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
575 * The bitmap font structure
577 typedef struct tagSFG_Font SFG_Font;
580 char* Name; /* The source font name */
581 int Quantity; /* Number of chars in font */
582 int Height; /* Height of the characters */
583 const GLubyte** Characters; /* The characters mapping */
585 float xorig, yorig; /* Relative origin of the character */
589 * The stroke font structures
592 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
593 struct tagSFG_StrokeVertex
598 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
599 struct tagSFG_StrokeStrip
602 const SFG_StrokeVertex* Vertices;
605 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
606 struct tagSFG_StrokeChar
610 const SFG_StrokeStrip* Strips;
613 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
614 struct tagSFG_StrokeFont
616 char* Name; /* The source font name */
617 int Quantity; /* Number of chars in font */
618 GLfloat Height; /* Height of the characters */
619 const SFG_StrokeChar** Characters; /* The characters mapping */
622 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
625 * Freeglut display related stuff (initialized once per session)
627 extern SFG_Display fgDisplay;
630 * Freeglut internal structure
632 extern SFG_Structure fgStructure;
635 * The current freeglut settings
637 extern SFG_State fgState;
640 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
643 * A call to this function makes us sure that the Display and Structure
644 * subsystems have been properly initialized and are ready to be used
646 #define freeglut_assert_ready assert( fgState.Initialised );
649 * Following definitions are somewhat similiar to GLib's,
650 * but do not generate any log messages:
652 #define freeglut_return_if_fail( expr ) \
655 #define freeglut_return_val_if_fail( expr, val ) \
660 * A call to those macros assures us that there is a current
661 * window and menu set, respectively:
663 #define freeglut_assert_window assert( fgStructure.Window != NULL );
664 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
667 * The initialize and deinitialize functions get called on glutInit()
668 * and glutMainLoop() end respectively. They should create/clean up
669 * everything inside of the freeglut
671 void fgInitialize( const char* displayName );
672 void fgDeinitialize( void );
675 * Those two functions are used to create/destroy the freeglut internal
676 * structures. This actually happens when calling glutInit() and when
677 * quitting the glutMainLoop() (which actually happens, when all windows
680 void fgCreateStructure( void );
681 void fgDestroyStructure( void );
684 * A helper function to check if a display mode is possible to use
686 #if TARGET_HOST_UNIX_X11
687 XVisualInfo* fgChooseVisual( void );
691 * The window procedure for Win32 events handling
693 #if TARGET_HOST_WIN32
694 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
695 WPARAM wParam, LPARAM lParam );
696 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
697 unsigned char layer_type );
701 * Window creation, opening, closing and destruction.
702 * Also CallBack clearing/initialization.
703 * Defined in freeglut_structure.c, freeglut_window.c.
705 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
706 int x, int y, int w, int h,
707 GLboolean gameMode, GLboolean isMenu );
708 void fgSetWindow ( SFG_Window *window ) ;
709 void fgOpenWindow( SFG_Window* window, const char* title,
710 int x, int y, int w, int h, GLboolean gameMode,
711 GLboolean isSubWindow );
712 void fgCloseWindow( SFG_Window* window );
713 void fgAddToWindowDestroyList ( SFG_Window* window,
714 GLboolean needToClose ) ;
715 void fgCloseWindows ();
716 void fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
717 void fgClearCallBacks( SFG_Window *window );
720 * Menu creation and destruction. Defined in freeglut_structure.c
722 SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
723 void fgDestroyMenu( SFG_Menu* menu );
726 * Joystick device management functions, defined in freeglut_joystick.c
728 void fgJoystickInit( int ident );
729 void fgJoystickClose( void );
730 void fgJoystickPollWindow( SFG_Window* window );
733 * Helper function to enumerate through all registered windows
734 * and one to enumerate all of a window's subwindows...
736 * The GFunc callback for those functions will be defined as:
738 * void enumCallback( gpointer window, gpointer enumerator );
740 * where window is the enumerated (sub)window pointer (SFG_Window *),
741 * and userData is the a custom user-supplied pointer. Functions
742 * are defined and exported from freeglut_structure.c file.
744 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
745 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
746 SFG_Enumerator* enumerator );
749 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
750 * first window in the queue matching the specified window handle.
751 * The function is defined in freeglut_structure.c file.
753 #if TARGET_HOST_UNIX_X11
754 SFG_Window* fgWindowByHandle( Window hWindow );
755 #elif TARGET_HOST_WIN32
756 SFG_Window* fgWindowByHandle( HWND hWindow );
760 * This function is similiar to the previous one, except it is
761 * looking for a specified (sub)window identifier. The function
762 * is defined in freeglut_structure.c file.
764 SFG_Window* fgWindowByID( int windowID );
767 * Looks up a menu given its ID. This is easier that fgWindowByXXX
768 * as all menus are placed in a single doubly linked list...
770 SFG_Menu* fgMenuByID( int menuID );
773 * The menu activation and deactivation the code. This is the meat
774 * of the menu user interface handling code...
776 void fgActivateMenu( SFG_Window* window, int button );
777 void fgExecuteMenuCallback( SFG_Menu* menu );
778 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
779 void fgDeactivateMenu( SFG_Window *window );
780 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
783 * This function gets called just before the buffers swap, so that
784 * freeglut can display the pull-down menus via OpenGL. The function
785 * is defined in freeglut_menu.c file.
787 void fgDisplayMenu( void );
790 * Display the mouse cursor using OpenGL calls. The function
791 * is defined in freeglut_cursor.c file.
793 void fgDisplayCursor( void );
796 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
798 long fgElapsedTime( void );
803 void fgListInit(SFG_List *list);
804 void fgListAppend(SFG_List *list, SFG_Node *node);
805 void fgListRemove(SFG_List *list, SFG_Node *node);
806 int fgListLength(SFG_List *list);
809 * Error Messages functions
811 void fgError( const char *fmt, ... );
812 void fgWarning( const char *fmt, ... );
814 #endif /* FREEGLUT_INTERNAL_H */
816 /*** END OF FILE ***/