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>
94 #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 (* 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 (* FGCBspaceRotate )( 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: initializing, running, or stopping
205 GLUT_EXEC_STATE_INIT,
206 GLUT_EXEC_STATE_RUNNING,
211 * This structure holds different freeglut settings
213 typedef struct tagSFG_State SFG_State;
216 SFG_XYUse Position; /* The default windows' position */
217 SFG_XYUse Size; /* The default windows' size */
218 unsigned int DisplayMode; /* The display mode for new windows */
220 GLboolean ForceDirectContext; /* Should we force direct contexts? */
221 GLboolean TryDirectContext; /* What about giving a try to? */
223 GLboolean ForceIconic; /* All new top windows are iconified */
224 GLboolean UseCurrentContext; /* New windows use current window's rendering context */
226 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
227 GLboolean XSyncSwitch; /* X11 sync protocol switch */
229 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat... */
231 GLuint FPSInterval; /* Interval between FPS printfs */
232 GLuint SwapCount; /* Count of glutSwapBuffer calls */
233 GLuint SwapTime; /* Time of last SwapBuffers */
235 SFG_Time Time; /* The time that glutInit was called */
236 SFG_List Timers; /* The freeglut timer hooks */
238 FGCBidle IdleCallback; /* The global idle callback */
240 FGCBmenuState MenuStateCallback; /* Menu callbacks are global */
241 FGCBmenuStatus MenuStatusCallback;
243 SFG_XYUse GameModeSize; /* The game mode screen's dimensions */
244 int GameModeDepth; /* The pixel depth for game mode */
245 int GameModeRefresh; /* The refresh rate for game mode */
247 int ActionOnWindowClose ; /* Action when user clicks "x" on window header bar */
249 fgExecutionState ExecState ; /* Current state of the GLUT execution */
253 * The structure used by display initialization in freeglut_init.c
255 typedef struct tagSFG_Display SFG_Display;
256 struct tagSFG_Display
258 #if TARGET_HOST_UNIX_X11
259 Display* Display; /* The display we are being run in. */
260 int Screen; /* The screen we are about to use. */
261 Window RootWindow; /* The screen's root window. */
262 int Connection; /* The display's connection number */
263 Atom DeleteWindow; /* The window deletion atom */
265 #ifdef X_XF86VidModeGetModeLine
267 * XF86VidMode may be compilable even if it fails at runtime. Therefore,
268 * the validity of the VidMode has to be tracked
270 int DisplayModeValid; /* Flag that indicates runtime status*/
271 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
272 int DisplayModeClock; /* The display mode's refresh rate */
275 #elif TARGET_HOST_WIN32
276 HINSTANCE Instance; /* The application's instance */
277 DEVMODE DisplayMode; /* Desktop's display settings */
281 int ScreenWidth; /* The screen's width in pixels */
282 int ScreenHeight; /* The screen's height in pixels */
283 int ScreenWidthMM; /* The screen's width in milimeters */
284 int ScreenHeightMM; /* The screen's height in milimeters */
289 * The user can create any number of timer hooks
291 typedef struct tagSFG_Timer SFG_Timer;
295 int ID; /* The timer ID integer */
296 FGCBtimer Callback; /* The timer callback */
297 long TriggerTime; /* The timer trigger time */
301 * A window and its OpenGL context. The contents of this structure
302 * are highly dependant on the target operating system we aim at...
304 typedef struct tagSFG_Context SFG_Context;
305 struct tagSFG_Context
307 #if TARGET_HOST_UNIX_X11
308 Window Handle; /* The window's handle */
309 GLXContext Context; /* The OpenGL context */
310 XVisualInfo* VisualInfo; /* The window's visual information */
312 #elif TARGET_HOST_WIN32
313 HWND Handle; /* The window's handle */
314 HDC Device; /* The window's device context */
315 HGLRC Context; /* The window's WGL context */
319 int DoubleBuffered; /* Treat the window as double-buffered */
323 * Window's state description. This structure should be kept portable.
325 typedef struct tagSFG_WindowState SFG_WindowState;
326 struct tagSFG_WindowState
328 int Width; /* Window's width in pixels */
329 int Height; /* The same about the height */
331 GLboolean Redisplay; /* Do we have to redisplay? */
332 GLboolean Visible; /* Is the window visible now */
334 int Cursor; /* The currently selected cursor */
335 int Modifiers; /* The current ALT/SHIFT/CTRL state */
337 long JoystickPollRate; /* The joystick polling rate */
338 long JoystickLastPoll; /* When the last poll has happened */
340 int MouseX, MouseY; /* The most recent mouse position */
342 GLboolean IsGameMode; /* Is this the game mode window? */
344 #if TARGET_HOST_WIN32
345 GLboolean NeedToResize; /* Do we need to explicitly resize? */
350 * The window callbacks the user can supply us with. Should be kept portable.
352 typedef struct tagSFG_WindowCallbacks SFG_WindowCallbacks;
353 struct tagSFG_WindowCallbacks
356 * Following callbacks are fully supported right now
357 * and are ready to be tested for GLUT conformance:
361 FGCBkeyboard Keyboard;
362 FGCBkeyboardUp KeyboardUp;
364 FGCBspecialUp SpecialUp;
369 FGCBvisibility Visibility;
370 FGCBwindowStatus WindowStatus;
371 FGCBjoystick Joystick;
375 * Those callbacks are being ignored for the moment
378 FGCBoverlayDisplay OverlayDisplay;
379 FGCBspaceMotion SpaceMotion;
380 FGCBspaceRotate SpaceRotation;
381 FGCBspaceButton SpaceButton;
383 FGCBbuttonBox ButtonBox;
384 FGCBtabletMotion TabletMotion;
385 FGCBtabletButton TabletButton;
389 * This structure describes a menu
391 typedef struct tagSFG_Menu SFG_Menu;
395 void *UserData ; /* A. Donev: User data passed back at callback */
396 int ID; /* The global menu ID */
397 SFG_List Entries; /* The menu entries list */
398 FGCBmenu Callback; /* The menu callback */
399 FGCBdestroy Destroy; /* A. Donev: Destruction callback */
400 GLboolean IsActive; /* Is the menu selected? */
401 int Width; /* Menu box width in pixels */
402 int Height; /* Menu box height in pixels */
403 int X, Y; /* Menu box raster position */
407 * This is a menu entry
409 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
410 struct tagSFG_MenuEntry
413 int ID; /* The menu entry ID (local) */
414 int Ordinal; /* The menu's ordinal number */
415 char* Text; /* The text to be displayed */
416 SFG_Menu* SubMenu; /* Optional sub-menu tree */
417 GLboolean IsActive; /* Is the entry highlighted? */
418 int Width; /* Label's width in pixels */
422 * A window, making part of freeglut windows hierarchy. Should be kept portable.
424 typedef struct tagSFG_Window SFG_Window;
428 int ID; /* Window's ID number */
430 SFG_Context Window; /* Window and OpenGL context */
431 SFG_WindowState State; /* The window state */
432 SFG_WindowCallbacks Callbacks; /* The window callbacks */
433 void *UserData ; /* A. Donev: A pointer to user data used in rendering */
435 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
436 SFG_Menu* ActiveMenu; /* The window's active menu */
438 SFG_Window* Parent; /* The parent to this window */
439 SFG_List Children; /* The subwindows d.l. list */
443 * A linked list structure of windows
445 typedef struct tagSFG_WindowList SFG_WindowList ;
446 struct tagSFG_WindowList
449 GLboolean needToClose ;
450 SFG_WindowList *next ;
454 * This holds information about all the windows, menus etc.
456 typedef struct tagSFG_Structure SFG_Structure;
457 struct tagSFG_Structure
459 SFG_List Windows; /* The global windows list */
460 SFG_List Menus; /* The global menus list */
462 SFG_Window* Window; /* The currently active win. */
463 SFG_Menu* Menu; /* Same, but menu... */
465 SFG_Window* GameMode; /* The game mode window */
467 int WindowID; /* The new current window ID */
468 int MenuID; /* The new current menu ID */
472 * This structure is used for the enumeration purposes.
473 * You can easily extend its functionalities by declaring
474 * a structure containing enumerator's contents and custom
475 * data, then casting its pointer to (SFG_Enumerator *).
477 typedef struct tagSFG_Enumerator SFG_Enumerator;
478 struct tagSFG_Enumerator
480 GLboolean found; /* Used to terminate search */
481 void* data; /* Custom data pointer */
483 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
486 * The bitmap font structure
488 typedef struct tagSFG_Font SFG_Font;
491 char* Name; /* The source font name */
492 int Quantity; /* Number of chars in font */
493 int Height; /* Height of the characters */
494 const GLubyte** Characters; /* The characters mapping */
496 float xorig, yorig ; /* The origin of the character relative to the draw location */
500 * The stroke font structures
503 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
504 struct tagSFG_StrokeVertex
509 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
510 struct tagSFG_StrokeStrip
513 const SFG_StrokeVertex* Vertices;
516 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
517 struct tagSFG_StrokeChar
521 const SFG_StrokeStrip* Strips;
524 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
525 struct tagSFG_StrokeFont
527 char* Name; /* The source font name */
528 int Quantity; /* Number of chars in font */
529 GLfloat Height; /* Height of the characters */
530 const SFG_StrokeChar** Characters; /* The characters mapping */
533 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
536 * Freeglut display related stuff (initialized once per session)
538 extern SFG_Display fgDisplay;
541 * Freeglut internal structure
543 extern SFG_Structure fgStructure;
546 * The current freeglut settings
548 extern SFG_State fgState;
551 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
554 * A call to this function makes us sure that the Display and Structure
555 * subsystems have been properly initialized and are ready to be used
557 #define freeglut_assert_ready assert( fgState.Time.Set );
560 * Following definitions are somewhat similiar to GLib's,
561 * but do not generate any log messages:
563 #define freeglut_return_if_fail( expr ) if( !(expr) ) return;
564 #define freeglut_return_val_if_fail( expr, val ) if( !(expr) ) return( val );
567 * A call to those macros assures us that there is a current
568 * window and menu set, respectively:
570 #define freeglut_assert_window assert( fgStructure.Window != NULL );
571 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
574 * The initialize and deinitialize functions get called on glutInit()
575 * and glutMainLoop() end respectively. They should create/clean up
576 * everything inside of the freeglut
578 void fgInitialize( const char* displayName );
579 void fgDeinitialize( void );
582 * Those two functions are used to create/destroy the freeglut internal
583 * structures. This actually happens when calling glutInit() and when
584 * quitting the glutMainLoop() (which actually happens, when all windows
587 void fgCreateStructure( void );
588 void fgDestroyStructure( void );
591 * A helper function to check if a display mode is possible to use
593 #if TARGET_HOST_UNIX_X11
594 XVisualInfo* fgChooseVisual( void );
598 * The window procedure for Win32 events handling
600 #if TARGET_HOST_WIN32
601 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
602 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned char layer_type );
606 * Window creation, opening, closing and destruction.
607 * Defined in freeglut_structure.c, freeglut_window.c.
609 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, int x, int y, int w, int h, GLboolean gameMode );
610 void fgSetWindow ( SFG_Window *window ) ;
611 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode, int isSubWindow );
612 void fgCloseWindow( SFG_Window* window );
613 void fgAddToWindowDestroyList ( SFG_Window* window, GLboolean needToClose ) ;
614 void fgCloseWindows () ;
615 void fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
618 * Menu creation and destruction. Defined in freeglut_structure.c
620 SFG_Menu* fgCreateMenu( FGCBmenu menuCallback );
621 void fgDestroyMenu( SFG_Menu* menu );
624 * Joystick device management functions, defined in freeglut_joystick.c
626 void fgJoystickInit( int ident );
627 void fgJoystickClose( void );
628 void fgJoystickPollWindow( SFG_Window* window );
631 * Helper function to enumerate through all registered windows
632 * and one to enumerate all of a window's subwindows...
634 * The GFunc callback for those functions will be defined as:
636 * void enumCallback( gpointer window, gpointer enumerator );
638 * where window is the enumerated (sub)window pointer (SFG_Window *),
639 * and userData is the a custom user-supplied pointer. Functions
640 * are defined and exported from freeglut_structure.c file.
642 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
643 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
646 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
647 * first window in the queue matching the specified window handle.
648 * The function is defined in freeglut_structure.c file.
650 #if TARGET_HOST_UNIX_X11
651 SFG_Window* fgWindowByHandle( Window hWindow );
652 #elif TARGET_HOST_WIN32
654 SFG_Window* fgWindowByHandle( HWND hWindow );
658 * This function is similiar to the previous one, except it is
659 * looking for a specified (sub)window identifier. The function
660 * is defined in freeglut_structure.c file.
662 SFG_Window* fgWindowByID( int windowID );
665 * Looks up a menu given its ID. This is easier that fgWindowByXXX
666 * as all menus are placed in a single doubly linked list...
668 SFG_Menu* fgMenuByID( int menuID );
671 * The menu activation and deactivation the code. This is the meat
672 * of the menu user interface handling code...
674 void fgActivateMenu( SFG_Window* window, int button );
675 void fgExecuteMenuCallback( SFG_Menu* menu ) ;
676 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu ) ;
677 void fgDeactivateMenu( SFG_Window *window );
680 * This function gets called just before the buffers swap, so that
681 * freeglut can display the pull-down menus via OpenGL. The function
682 * is defined in freeglut_menu.c file.
684 void fgDisplayMenu( void );
687 * Display the mouse cursor using OpenGL calls. The function
688 * is defined in freeglut_cursor.c file.
690 void fgDisplayCursor( void );
693 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
695 long fgElapsedTime( void );
700 void fgListInit(SFG_List *list);
701 void fgListAppend(SFG_List *list, SFG_Node *node);
702 void fgListRemove(SFG_List *list, SFG_Node *node);
703 int fgListLength(SFG_List *list);
706 * Error Messages functions
708 void fgError( const char *fmt, ... );
709 void fgWarning( const char *fmt, ... );
711 #endif /* FREEGLUT_INTERNAL_H */
713 /*** END OF FILE ***/