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 (* FGCBspaceRotate )( 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; /* The display mode for new windows */
219 GLboolean ForceDirectContext; /* Should we force direct contexts? */
220 GLboolean TryDirectContext; /* What about giving a try to? */
222 GLboolean ForceIconic; /* All new top windows are iconified */
223 GLboolean UseCurrentContext; /* New windows use current window's rendering context */
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; /* The time that glutInit was called */
235 SFG_List Timers; /* The freeglut timer hooks */
237 FGCBidle IdleCallback; /* The global idle callback */
239 GLboolean BuildingAMenu; /* True if we are presently making a menu */
240 int ActiveMenus; /* Number of currently active menus */
241 FGCBmenuState MenuStateCallback; /* Menu callbacks are global */
242 FGCBmenuStatus MenuStatusCallback;
244 SFG_XYUse GameModeSize; /* The 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 clicks "x" on window header bar */
250 fgExecutionState ExecState ; /* Current state of the GLUT execution */
251 char *ProgramName ; /* Name of the program invoking the "freeglut" library" */
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? */
357 * The window callbacks the user can supply us with. Should be kept portable.
359 typedef struct tagSFG_WindowCallbacks SFG_WindowCallbacks;
360 struct tagSFG_WindowCallbacks
363 * Following callbacks are fully supported right now
364 * and are ready to be tested for GLUT conformance:
368 FGCBkeyboard Keyboard;
369 FGCBkeyboardUp KeyboardUp;
371 FGCBspecialUp SpecialUp;
373 FGCBmousewheel MouseWheel;
377 FGCBvisibility Visibility;
378 FGCBwindowStatus WindowStatus;
379 FGCBjoystick Joystick;
383 * Those callbacks are being ignored for the moment
386 FGCBoverlayDisplay OverlayDisplay;
387 FGCBspaceMotion SpaceMotion;
388 FGCBspaceRotate SpaceRotation;
389 FGCBspaceButton SpaceButton;
391 FGCBbuttonBox ButtonBox;
392 FGCBtabletMotion TabletMotion;
393 FGCBtabletButton TabletButton;
397 * This structure holds the OpenGL rendering context for all the menu windows
399 typedef struct tagSFG_MenuContext SFG_MenuContext;
400 struct tagSFG_MenuContext
402 #if TARGET_HOST_UNIX_X11
403 GLXContext Context; /* The menu OpenGL context */
404 XVisualInfo* VisualInfo; /* The window's visual information */
405 #elif TARGET_HOST_WIN32
406 HGLRC Context; /* The menu window's WGL context */
412 * This structure describes a menu
414 typedef struct tagSFG_Window SFG_Window;
415 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
416 typedef struct tagSFG_Menu SFG_Menu;
420 void *UserData ; /* A. Donev: User data passed back at callback */
421 int ID; /* The global menu ID */
422 SFG_List Entries; /* The menu entries list */
423 FGCBmenu Callback; /* The menu callback */
424 FGCBdestroy Destroy; /* A. Donev: Destruction callback */
425 GLboolean IsActive; /* Is the menu selected? */
426 int Width; /* Menu box width in pixels */
427 int Height; /* Menu box height in pixels */
428 int X, Y; /* Menu box raster position */
430 SFG_MenuEntry *ActiveEntry ; /* Currently active entry in the menu */
431 SFG_Window *Window ; /* OpenGL window for menu */
432 SFG_Window *ParentWindow ; /* OpenGL window in which the menu is defined */
436 * This is a menu entry
438 struct tagSFG_MenuEntry
441 int ID; /* The menu entry ID (local) */
442 int Ordinal; /* The menu's ordinal number */
443 char* Text; /* The text to be displayed */
444 SFG_Menu* SubMenu; /* Optional sub-menu tree */
445 GLboolean IsActive; /* Is the entry highlighted? */
446 int Width; /* Label's width in pixels */
450 * A window, making part of freeglut windows hierarchy. Should be kept portable.
455 int ID; /* Window's ID number */
457 SFG_Context Window; /* Window and OpenGL context */
458 SFG_WindowState State; /* The window state */
459 SFG_WindowCallbacks Callbacks; /* The window callbacks */
460 void *UserData ; /* A. Donev: A pointer to user data used in rendering */
462 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
463 SFG_Menu* ActiveMenu; /* The window's active menu */
465 SFG_Window* Parent; /* The parent to this window */
466 SFG_List Children; /* The subwindows d.l. list */
468 GLboolean IsMenu; /* Set to 1 if we are a menu */
472 * A linked list structure of windows
474 typedef struct tagSFG_WindowList SFG_WindowList ;
475 struct tagSFG_WindowList
478 GLboolean needToClose ;
479 SFG_WindowList *next ;
483 * This holds information about all the windows, menus etc.
485 typedef struct tagSFG_Structure SFG_Structure;
486 struct tagSFG_Structure
488 SFG_List Windows; /* The global windows list */
489 SFG_List Menus; /* The global menus list */
491 SFG_Window* Window; /* The currently active win. */
492 SFG_Menu* Menu; /* Same, but menu... */
494 SFG_MenuContext* MenuContext; /* OpenGL rendering context for menus */
496 SFG_Window* GameMode; /* The game mode window */
498 int WindowID; /* The new current window ID */
499 int MenuID; /* The new current menu ID */
503 * This structure is used for the enumeration purposes.
504 * You can easily extend its functionalities by declaring
505 * a structure containing enumerator's contents and custom
506 * data, then casting its pointer to (SFG_Enumerator *).
508 typedef struct tagSFG_Enumerator SFG_Enumerator;
509 struct tagSFG_Enumerator
511 GLboolean found; /* Used to terminate search */
512 void* data; /* Custom data pointer */
514 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
517 * The bitmap font structure
519 typedef struct tagSFG_Font SFG_Font;
522 char* Name; /* The source font name */
523 int Quantity; /* Number of chars in font */
524 int Height; /* Height of the characters */
525 const GLubyte** Characters; /* The characters mapping */
527 float xorig, yorig ; /* The origin of the character relative to the draw location */
531 * The stroke font structures
534 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
535 struct tagSFG_StrokeVertex
540 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
541 struct tagSFG_StrokeStrip
544 const SFG_StrokeVertex* Vertices;
547 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
548 struct tagSFG_StrokeChar
552 const SFG_StrokeStrip* Strips;
555 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
556 struct tagSFG_StrokeFont
558 char* Name; /* The source font name */
559 int Quantity; /* Number of chars in font */
560 GLfloat Height; /* Height of the characters */
561 const SFG_StrokeChar** Characters; /* The characters mapping */
564 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
567 * Freeglut display related stuff (initialized once per session)
569 extern SFG_Display fgDisplay;
572 * Freeglut internal structure
574 extern SFG_Structure fgStructure;
577 * The current freeglut settings
579 extern SFG_State fgState;
582 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
585 * A call to this function makes us sure that the Display and Structure
586 * subsystems have been properly initialized and are ready to be used
588 #define freeglut_assert_ready assert( fgState.Time.Set );
591 * Following definitions are somewhat similiar to GLib's,
592 * but do not generate any log messages:
594 #define freeglut_return_if_fail( expr ) if( !(expr) ) return;
595 #define freeglut_return_val_if_fail( expr, val ) if( !(expr) ) return( val );
598 * A call to those macros assures us that there is a current
599 * window and menu set, respectively:
601 #define freeglut_assert_window assert( fgStructure.Window != NULL );
602 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
605 * The initialize and deinitialize functions get called on glutInit()
606 * and glutMainLoop() end respectively. They should create/clean up
607 * everything inside of the freeglut
609 void fgInitialize( const char* displayName );
610 void fgDeinitialize( void );
613 * Those two functions are used to create/destroy the freeglut internal
614 * structures. This actually happens when calling glutInit() and when
615 * quitting the glutMainLoop() (which actually happens, when all windows
618 void fgCreateStructure( void );
619 void fgDestroyStructure( void );
622 * A helper function to check if a display mode is possible to use
624 #if TARGET_HOST_UNIX_X11
625 XVisualInfo* fgChooseVisual( void );
629 * The window procedure for Win32 events handling
631 #if TARGET_HOST_WIN32
632 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
633 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned char layer_type );
637 * Window creation, opening, closing and destruction.
638 * Defined in freeglut_structure.c, freeglut_window.c.
640 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, int x, int y, int w, int h, GLboolean gameMode );
641 void fgSetWindow ( SFG_Window *window ) ;
642 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode, int isSubWindow );
643 void fgCloseWindow( SFG_Window* window );
644 void fgAddToWindowDestroyList ( SFG_Window* window, GLboolean needToClose ) ;
645 void fgCloseWindows () ;
646 void fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
649 * Menu creation and destruction. Defined in freeglut_structure.c
651 SFG_Menu* fgCreateMenu( FGCBmenu menuCallback );
652 void fgDestroyMenu( SFG_Menu* menu );
655 * Joystick device management functions, defined in freeglut_joystick.c
657 void fgJoystickInit( int ident );
658 void fgJoystickClose( void );
659 void fgJoystickPollWindow( SFG_Window* window );
662 * Helper function to enumerate through all registered windows
663 * and one to enumerate all of a window's subwindows...
665 * The GFunc callback for those functions will be defined as:
667 * void enumCallback( gpointer window, gpointer enumerator );
669 * where window is the enumerated (sub)window pointer (SFG_Window *),
670 * and userData is the a custom user-supplied pointer. Functions
671 * are defined and exported from freeglut_structure.c file.
673 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
674 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
677 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
678 * first window in the queue matching the specified window handle.
679 * The function is defined in freeglut_structure.c file.
681 #if TARGET_HOST_UNIX_X11
682 SFG_Window* fgWindowByHandle( Window hWindow );
683 #elif TARGET_HOST_WIN32
685 SFG_Window* fgWindowByHandle( HWND hWindow );
689 * This function is similiar to the previous one, except it is
690 * looking for a specified (sub)window identifier. The function
691 * is defined in freeglut_structure.c file.
693 SFG_Window* fgWindowByID( int windowID );
696 * Looks up a menu given its ID. This is easier that fgWindowByXXX
697 * as all menus are placed in a single doubly linked list...
699 SFG_Menu* fgMenuByID( int menuID );
702 * The menu activation and deactivation the code. This is the meat
703 * of the menu user interface handling code...
705 void fgActivateMenu( SFG_Window* window, int button );
706 void fgExecuteMenuCallback( SFG_Menu* menu ) ;
707 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu ) ;
708 void fgDeactivateMenu( SFG_Window *window );
709 void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry );
712 * This function gets called just before the buffers swap, so that
713 * freeglut can display the pull-down menus via OpenGL. The function
714 * is defined in freeglut_menu.c file.
716 void fgDisplayMenu( void );
719 * Display the mouse cursor using OpenGL calls. The function
720 * is defined in freeglut_cursor.c file.
722 void fgDisplayCursor( void );
725 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
727 long fgElapsedTime( void );
732 void fgListInit(SFG_List *list);
733 void fgListAppend(SFG_List *list, SFG_Node *node);
734 void fgListRemove(SFG_List *list, SFG_Node *node);
735 int fgListLength(SFG_List *list);
738 * Error Messages functions
740 void fgError( const char *fmt, ... );
741 void fgWarning( const char *fmt, ... );
743 #endif /* FREEGLUT_INTERNAL_H */
745 /*** END OF FILE ***/