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: initializing, running, or stopping
204 GLUT_EXEC_STATE_INIT,
205 GLUT_EXEC_STATE_RUNNING,
210 * This structure holds different freeglut settings
212 typedef struct tagSFG_State SFG_State;
215 SFG_XYUse Position; /* The default windows' position */
216 SFG_XYUse Size; /* The default windows' size */
217 unsigned int DisplayMode; /* Display mode for new windows */
219 GLboolean ForceDirectContext; /* Force direct rendering? */
220 GLboolean TryDirectContext; /* What about giving a try to? */
222 GLboolean ForceIconic; /* New top windows are iconified */
223 GLboolean UseCurrentContext; /* New windows share with current */
225 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
226 GLboolean XSyncSwitch; /* X11 sync protocol switch */
228 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat. */
230 GLuint FPSInterval; /* Interval between FPS printfs */
231 GLuint SwapCount; /* Count of glutSwapBuffer calls */
232 GLuint SwapTime; /* Time of last SwapBuffers */
234 SFG_Time Time; /* Time that glutInit was called */
235 SFG_List Timers; /* The freeglut timer hooks */
237 FGCBIdle IdleCallback; /* The global idle callback */
239 GLboolean BuildingAMenu; /* Are we presently making a menu */
240 int ActiveMenus; /* Num. of currently active menus */
241 FGCBMenuState MenuStateCallback; /* Menu callbacks are global */
242 FGCBMenuStatus MenuStatusCallback;
244 SFG_XYUse GameModeSize; /* Game mode screen's dimensions */
245 int GameModeDepth; /* The pixel depth for game mode */
246 int GameModeRefresh; /* The refresh rate for game mode */
248 int ActionOnWindowClose; /* Action when user closes window */
250 fgExecutionState ExecState; /* Used for GLUT termination */
251 char *ProgramName; /* Name of the invoking program */
255 * The structure used by display initialization in freeglut_init.c
257 typedef struct tagSFG_Display SFG_Display;
258 struct tagSFG_Display
260 #if TARGET_HOST_UNIX_X11
261 Display* Display; /* The display we are being run in. */
262 int Screen; /* The screen we are about to use. */
263 Window RootWindow; /* The screen's root window. */
264 int Connection; /* The display's connection number */
265 Atom DeleteWindow; /* The window deletion atom */
267 #ifdef X_XF86VidModeGetModeLine
269 * XF86VidMode may be compilable even if it fails at runtime. Therefore,
270 * the validity of the VidMode has to be tracked
272 int DisplayModeValid; /* Flag that indicates runtime status*/
273 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
274 int DisplayModeClock; /* The display mode's refresh rate */
275 int DisplayViewPortX; /* saved X location of the viewport */
276 int DisplayViewPortY; /* saved Y location of the viewport */
277 int DisplayPointerX; /* saved X location of the pointer */
278 int DisplayPointerY; /* saved Y location of the pointer */
282 #elif TARGET_HOST_WIN32
283 HINSTANCE Instance; /* The application's instance */
284 DEVMODE DisplayMode; /* Desktop's display settings */
288 int ScreenWidth; /* The screen's width in pixels */
289 int ScreenHeight; /* The screen's height in pixels */
290 int ScreenWidthMM; /* The screen's width in milimeters */
291 int ScreenHeightMM; /* The screen's height in milimeters */
296 * The user can create any number of timer hooks
298 typedef struct tagSFG_Timer SFG_Timer;
302 int ID; /* The timer ID integer */
303 FGCBTimer Callback; /* The timer callback */
304 long TriggerTime; /* The timer trigger time */
308 * A window and its OpenGL context. The contents of this structure
309 * are highly dependant on the target operating system we aim at...
311 typedef struct tagSFG_Context SFG_Context;
312 struct tagSFG_Context
314 #if TARGET_HOST_UNIX_X11
315 Window Handle; /* The window's handle */
316 GLXContext Context; /* The OpenGL context */
317 XVisualInfo* VisualInfo; /* The window's visual information */
319 #elif TARGET_HOST_WIN32
320 HWND Handle; /* The window's handle */
321 HDC Device; /* The window's device context */
322 HGLRC Context; /* The window's WGL context */
326 int DoubleBuffered; /* Treat the window as double-buffered */
330 * Window's state description. This structure should be kept portable.
332 typedef struct tagSFG_WindowState SFG_WindowState;
333 struct tagSFG_WindowState
335 int Width; /* Window's width in pixels */
336 int Height; /* The same about the height */
338 GLboolean Redisplay; /* Do we have to redisplay? */
339 GLboolean Visible; /* Is the window visible now */
341 int Cursor; /* The currently selected cursor */
342 int Modifiers; /* The current ALT/SHIFT/CTRL state */
344 long JoystickPollRate; /* The joystick polling rate */
345 long JoystickLastPoll; /* When the last poll has happened */
347 int MouseX, MouseY; /* The most recent mouse position */
349 GLboolean IsGameMode; /* Is this the game mode window? */
351 #if TARGET_HOST_WIN32
352 GLboolean NeedToResize; /* Do we need to explicitly resize? */
358 * FETCH_WCB() is used as:
360 * FETCH_WCB( window, Visibility );
362 * ...where {window} is the freeglut window to fetch the callback from,
363 * {Visibility} is the window-specific callback to fetch.
365 * The result is correctly type-cast to the callback function pointer
366 * type. (This is accomlished by abutting the callback name to a
367 * common prefix, using ANSI C token-pasting.)
369 #define FETCH_WCB(window,cbname) \
370 ((FGCB ## cbname)((window).CallBacks[CB_ ## cbname]))
373 * INVOKE_WCB() is used as:
375 * INVOKE_WCB( window, Visibility, ( status ) );
377 * ...where {window} is the freeglut window,
378 * {Visibility} is the window-specific callback,
379 * {(status)} is the parameter list.
381 * The callback is invoked as:
383 * callback( status );
385 * ...so the parentheses are REQUIRED in the {arg_list}.
387 * NOTE that it does a sanity-check and also sets the
391 #define INVOKE_WCB(window,cbname,arg_list) \
394 if( FETCH_WCB( window, cbname ) ) \
396 fgSetWindow( &window ); \
397 FETCH_WCB( window, cbname ) arg_list; \
402 * The window callbacks the user can supply us with. Should be kept portable.
404 * This enumeration provides the freeglut CallBack numbers.
405 * The symbolic constants are indices into a window's array of
406 * function callbacks. The names are formed by splicing a common
407 * prefix onto the callback's base name. (This was originally
408 * done so that an early stage of development could live side-by-
409 * side with the old callback code. The old callback code used
410 * the bare callback's name as a structure member, so I used a
411 * prefix for the array index name.)
413 * XXX For consistancy, perhaps the prefix should match the
414 * XXX FETCH* and INVOKE* macro suffices. I.e., WCB_, rather than
435 /* Presently ignored */
446 /* Always make this the LAST one */
452 * This structure holds the OpenGL rendering context for all the menu windows
454 typedef struct tagSFG_MenuContext SFG_MenuContext;
455 struct tagSFG_MenuContext
457 #if TARGET_HOST_UNIX_X11
458 GLXContext Context; /* The menu OpenGL context */
459 XVisualInfo* VisualInfo; /* The window's visual information */
460 #elif TARGET_HOST_WIN32
461 HGLRC Context; /* The menu window's WGL context */
467 * This structure describes a menu
469 typedef struct tagSFG_Window SFG_Window;
470 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
471 typedef struct tagSFG_Menu SFG_Menu;
475 void *UserData; /* User data passed back at callback */
476 int ID; /* The global menu ID */
477 SFG_List Entries; /* The menu entries list */
478 FGCBMenu Callback; /* The menu callback */
479 FGCBDestroy Destroy; /* Destruction callback */
480 GLboolean IsActive; /* Is the menu selected? */
481 int Width; /* Menu box width in pixels */
482 int Height; /* Menu box height in pixels */
483 int X, Y; /* Menu box raster position */
485 SFG_MenuEntry *ActiveEntry; /* Currently active entry in the menu */
486 SFG_Window *Window; /* Window for menu */
487 SFG_Window *ParentWindow; /* Window in which the menu is defined */
491 * This is a menu entry
493 struct tagSFG_MenuEntry
496 int ID; /* The menu entry ID (local) */
497 int Ordinal; /* The menu's ordinal number */
498 char* Text; /* The text to be displayed */
499 SFG_Menu* SubMenu; /* Optional sub-menu tree */
500 GLboolean IsActive; /* Is the entry highlighted? */
501 int Width; /* Label's width in pixels */
505 * A window, making part of freeglut windows hierarchy.
506 * Should be kept portable.
511 int ID; /* Window's ID number */
513 SFG_Context Window; /* Window and OpenGL context */
514 SFG_WindowState State; /* The window state */
515 void *CallBacks[ TOTAL_CALLBACKS ]; /* Array of window callbacks */
516 void *UserData ; /* For use by user */
518 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
519 SFG_Menu* ActiveMenu; /* The window's active menu */
521 SFG_Window* Parent; /* The parent to this window */
522 SFG_List Children; /* The subwindows d.l. list */
524 GLboolean IsMenu; /* Set to 1 if we are a menu */
529 * A linked list structure of windows
531 typedef struct tagSFG_WindowList SFG_WindowList ;
532 struct tagSFG_WindowList
535 GLboolean needToClose ;
536 SFG_WindowList *next ;
540 * This holds information about all the windows, menus etc.
542 typedef struct tagSFG_Structure SFG_Structure;
543 struct tagSFG_Structure
545 SFG_List Windows; /* The global windows list */
546 SFG_List Menus; /* The global menus list */
548 SFG_Window* Window; /* The currently active win. */
549 SFG_Menu* Menu; /* Same, but menu... */
551 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
553 SFG_Window* GameMode; /* The game mode window */
555 int WindowID; /* The new current window ID */
556 int MenuID; /* The new current menu ID */
560 * This structure is used for the enumeration purposes.
561 * You can easily extend its functionalities by declaring
562 * a structure containing enumerator's contents and custom
563 * data, then casting its pointer to (SFG_Enumerator *).
565 typedef struct tagSFG_Enumerator SFG_Enumerator;
566 struct tagSFG_Enumerator
568 GLboolean found; /* Used to terminate search */
569 void* data; /* Custom data pointer */
571 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
574 * The bitmap font structure
576 typedef struct tagSFG_Font SFG_Font;
579 char* Name; /* The source font name */
580 int Quantity; /* Number of chars in font */
581 int Height; /* Height of the characters */
582 const GLubyte** Characters; /* The characters mapping */
584 float xorig, yorig; /* Relative origin of the character */
588 * The stroke font structures
591 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
592 struct tagSFG_StrokeVertex
597 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
598 struct tagSFG_StrokeStrip
601 const SFG_StrokeVertex* Vertices;
604 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
605 struct tagSFG_StrokeChar
609 const SFG_StrokeStrip* Strips;
612 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
613 struct tagSFG_StrokeFont
615 char* Name; /* The source font name */
616 int Quantity; /* Number of chars in font */
617 GLfloat Height; /* Height of the characters */
618 const SFG_StrokeChar** Characters; /* The characters mapping */
621 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
624 * Freeglut display related stuff (initialized once per session)
626 extern SFG_Display fgDisplay;
629 * Freeglut internal structure
631 extern SFG_Structure fgStructure;
634 * The current freeglut settings
636 extern SFG_State fgState;
639 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
642 * A call to this function makes us sure that the Display and Structure
643 * subsystems have been properly initialized and are ready to be used
645 #define freeglut_assert_ready assert( fgState.Time.Set );
648 * Following definitions are somewhat similiar to GLib's,
649 * but do not generate any log messages:
651 #define freeglut_return_if_fail( expr ) \
654 #define freeglut_return_val_if_fail( expr, val ) \
659 * A call to those macros assures us that there is a current
660 * window and menu set, respectively:
662 #define freeglut_assert_window assert( fgStructure.Window != NULL );
663 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
666 * The initialize and deinitialize functions get called on glutInit()
667 * and glutMainLoop() end respectively. They should create/clean up
668 * everything inside of the freeglut
670 void fgInitialize( const char* displayName );
671 void fgDeinitialize( void );
674 * Those two functions are used to create/destroy the freeglut internal
675 * structures. This actually happens when calling glutInit() and when
676 * quitting the glutMainLoop() (which actually happens, when all windows
679 void fgCreateStructure( void );
680 void fgDestroyStructure( void );
683 * A helper function to check if a display mode is possible to use
685 #if TARGET_HOST_UNIX_X11
686 XVisualInfo* fgChooseVisual( void );
690 * The window procedure for Win32 events handling
692 #if TARGET_HOST_WIN32
693 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg,
694 WPARAM wParam, LPARAM lParam );
695 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
696 unsigned char layer_type );
700 * Window creation, opening, closing and destruction.
701 * Also CallBack clearing/initialization.
702 * Defined in freeglut_structure.c, freeglut_window.c.
704 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
705 int x, int y, int w, int h, GLboolean gameMode );
706 void fgSetWindow ( SFG_Window *window ) ;
707 void fgOpenWindow( SFG_Window* window, const char* title,
708 int x, int y, int w, int h, GLboolean gameMode,
710 void fgCloseWindow( SFG_Window* window );
711 void fgAddToWindowDestroyList ( SFG_Window* window,
712 GLboolean needToClose ) ;
713 void fgCloseWindows ();
714 void fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
715 void fgClearCallBacks( SFG_Window *window );
718 * Menu creation and destruction. Defined in freeglut_structure.c
720 SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
721 void fgDestroyMenu( SFG_Menu* menu );
724 * Joystick device management functions, defined in freeglut_joystick.c
726 void fgJoystickInit( int ident );
727 void fgJoystickClose( void );
728 void fgJoystickPollWindow( SFG_Window* window );
731 * Helper function to enumerate through all registered windows
732 * and one to enumerate all of a window's subwindows...
734 * The GFunc callback for those functions will be defined as:
736 * void enumCallback( gpointer window, gpointer enumerator );
738 * where window is the enumerated (sub)window pointer (SFG_Window *),
739 * and userData is the a custom user-supplied pointer. Functions
740 * are defined and exported from freeglut_structure.c file.
742 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
743 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback,
744 SFG_Enumerator* enumerator );
747 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
748 * first window in the queue matching the specified window handle.
749 * The function is defined in freeglut_structure.c file.
751 #if TARGET_HOST_UNIX_X11
752 SFG_Window* fgWindowByHandle( Window hWindow );
753 #elif TARGET_HOST_WIN32
754 SFG_Window* fgWindowByHandle( HWND hWindow );
758 * This function is similiar to the previous one, except it is
759 * looking for a specified (sub)window identifier. The function
760 * is defined in freeglut_structure.c file.
762 SFG_Window* fgWindowByID( int windowID );
765 * Looks up a menu given its ID. This is easier that fgWindowByXXX
766 * as all menus are placed in a single doubly linked list...
768 SFG_Menu* fgMenuByID( int menuID );
771 * The menu activation and deactivation the code. This is the meat
772 * of the menu user interface handling code...
774 void fgActivateMenu( SFG_Window* window, int button );
775 void fgExecuteMenuCallback( SFG_Menu* menu );
776 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu );
777 void fgDeactivateMenu( SFG_Window *window );
778 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
781 * This function gets called just before the buffers swap, so that
782 * freeglut can display the pull-down menus via OpenGL. The function
783 * is defined in freeglut_menu.c file.
785 void fgDisplayMenu( void );
788 * Display the mouse cursor using OpenGL calls. The function
789 * is defined in freeglut_cursor.c file.
791 void fgDisplayCursor( void );
794 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
796 long fgElapsedTime( void );
801 void fgListInit(SFG_List *list);
802 void fgListAppend(SFG_List *list, SFG_Node *node);
803 void fgListRemove(SFG_List *list, SFG_Node *node);
804 int fgListLength(SFG_List *list);
807 * Error Messages functions
809 void fgError( const char *fmt, ... );
810 void fgWarning( const char *fmt, ... );
812 #endif /* FREEGLUT_INTERNAL_H */
814 /*** END OF FILE ***/