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 #if 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 (* FGCBmotion )( int, int );
124 typedef void (* FGCBpassive )( int, int );
125 typedef void (* FGCBentry )( int );
126 typedef void (* FGCBwindowStatus )( int );
127 typedef void (* FGCBselect )( int, int, int );
128 typedef void (* FGCBjoystick )( unsigned int, int, int, int );
129 typedef void (* FGCBkeyboardUp )( unsigned char, int, int );
130 typedef void (* FGCBspecialUp )( int, int, int );
131 typedef void (* FGCBoverlayDisplay)( void );
132 typedef void (* FGCBspaceMotion )( int, int, int );
133 typedef void (* FGCBspaceRotate )( int, int, int );
134 typedef void (* FGCBspaceButton )( int, int );
135 typedef void (* FGCBdials )( int, int );
136 typedef void (* FGCBbuttonBox )( int, int );
137 typedef void (* FGCBtabletMotion )( int, int );
138 typedef void (* FGCBtabletButton )( int, int, int, int );
139 typedef void (* FGCBdestroy )( void );
142 * The global callbacks type definitions
144 typedef void (* FGCBidle )( void );
145 typedef void (* FGCBtimer )( int );
146 typedef void (* FGCBmenuState )( int );
147 typedef void (* FGCBmenuStatus )( int, int, int );
150 * The callback used when creating/using menus
152 typedef void (* FGCBmenu )( int );
158 typedef struct tagSFG_List SFG_List;
166 * A list node structure
168 typedef struct tagSFG_Node SFG_Node;
176 * A helper structure holding two ints and a boolean
178 typedef struct tagSFG_XYUse SFG_XYUse;
181 GLint X, Y; /* The two integers... */
182 GLboolean Use; /* ...and a single boolean. */
186 * A helper structure holding a timeval and a boolean
188 typedef struct tagSFG_Time SFG_Time;
194 struct timeval Value;
200 * An enumeration containing the state of the GLUT execution: initializing, running, or stopping
203 GLUT_EXEC_STATE_INIT,
204 GLUT_EXEC_STATE_RUNNING,
209 * This structure holds different freeglut settings
211 typedef struct tagSFG_State SFG_State;
214 SFG_XYUse Position; /* The default windows' position */
215 SFG_XYUse Size; /* The default windows' size */
216 unsigned int DisplayMode; /* The display mode for new windows */
218 GLboolean ForceDirectContext; /* Should we force direct contexts? */
219 GLboolean TryDirectContext; /* What about giving a try to? */
221 GLboolean ForceIconic; /* All new top windows are iconified */
222 GLboolean UseCurrentContext; /* New windows use current window's rendering context */
224 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
225 GLboolean XSyncSwitch; /* X11 sync protocol switch */
227 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat... */
229 GLuint FPSInterval; /* Interval between FPS printfs */
230 GLuint SwapCount; /* Count of glutSwapBuffer calls */
231 GLuint SwapTime; /* Time of last SwapBuffers */
233 SFG_Time Time; /* The time that glutInit was called */
234 SFG_List Timers; /* The freeglut timer hooks */
236 FGCBidle IdleCallback; /* The global idle callback */
238 FGCBmenuState MenuStateCallback; /* Menu callbacks are global */
239 FGCBmenuStatus MenuStatusCallback;
241 SFG_XYUse GameModeSize; /* The game mode screen's dimensions */
242 int GameModeDepth; /* The pixel depth for game mode */
243 int GameModeRefresh; /* The refresh rate for game mode */
245 int ActionOnWindowClose ; /* Action when user clicks "x" on window header bar */
247 fgExecutionState ExecState ; /* Current state of the GLUT execution */
251 * The structure used by display initialization in freeglut_init.c
253 typedef struct tagSFG_Display SFG_Display;
254 struct tagSFG_Display
256 #if TARGET_HOST_UNIX_X11
257 Display* Display; /* The display we are being run in. */
258 int Screen; /* The screen we are about to use. */
259 Window RootWindow; /* The screen's root window. */
260 int Connection; /* The display's connection number */
261 Atom DeleteWindow; /* The window deletion atom */
263 #ifdef X_XF86VidModeGetModeLine
265 * XF86VidMode may be compilable even if it fails at runtime. Therefore,
266 * the validity of the VidMode has to be tracked
268 int DisplayModeValid; /* Flag that indicates runtime status*/
269 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
270 int DisplayModeClock; /* The display mode's refresh rate */
273 #elif TARGET_HOST_WIN32
274 HINSTANCE Instance; /* The application's instance */
275 DEVMODE DisplayMode; /* Desktop's display settings */
279 int ScreenWidth; /* The screen's width in pixels */
280 int ScreenHeight; /* The screen's height in pixels */
281 int ScreenWidthMM; /* The screen's width in milimeters */
282 int ScreenHeightMM; /* The screen's height in milimeters */
287 * The user can create any number of timer hooks
289 typedef struct tagSFG_Timer SFG_Timer;
293 int ID; /* The timer ID integer */
294 FGCBtimer Callback; /* The timer callback */
295 long TriggerTime; /* The timer trigger time */
299 * A window and its OpenGL context. The contents of this structure
300 * are highly dependant on the target operating system we aim at...
302 typedef struct tagSFG_Context SFG_Context;
303 struct tagSFG_Context
305 #if TARGET_HOST_UNIX_X11
306 Window Handle; /* The window's handle */
307 GLXContext Context; /* The OpenGL context */
308 XVisualInfo* VisualInfo; /* The window's visual information */
310 #elif TARGET_HOST_WIN32
311 HWND Handle; /* The window's handle */
312 HDC Device; /* The window's device context */
313 HGLRC Context; /* The window's WGL context */
317 int DoubleBuffered; /* Treat the window as double-buffered */
321 * Window's state description. This structure should be kept portable.
323 typedef struct tagSFG_WindowState SFG_WindowState;
324 struct tagSFG_WindowState
326 int Width; /* Window's width in pixels */
327 int Height; /* The same about the height */
329 GLboolean Redisplay; /* Do we have to redisplay? */
330 GLboolean Visible; /* Is the window visible now */
332 int Cursor; /* The currently selected cursor */
333 int Modifiers; /* The current ALT/SHIFT/CTRL state */
335 long JoystickPollRate; /* The joystick polling rate */
336 long JoystickLastPoll; /* When the last poll has happened */
338 int MouseX, MouseY; /* The most recent mouse position */
340 GLboolean IsGameMode; /* Is this the game mode window? */
342 #if TARGET_HOST_WIN32
343 GLboolean NeedToResize; /* Do we need to explicitly resize? */
348 * The window callbacks the user can supply us with. Should be kept portable.
350 typedef struct tagSFG_WindowCallbacks SFG_WindowCallbacks;
351 struct tagSFG_WindowCallbacks
354 * Following callbacks are fully supported right now
355 * and are ready to be tested for GLUT conformance:
359 FGCBkeyboard Keyboard;
360 FGCBkeyboardUp KeyboardUp;
362 FGCBspecialUp SpecialUp;
367 FGCBvisibility Visibility;
368 FGCBwindowStatus WindowStatus;
369 FGCBjoystick Joystick;
373 * Those callbacks are being ignored for the moment
376 FGCBoverlayDisplay OverlayDisplay;
377 FGCBspaceMotion SpaceMotion;
378 FGCBspaceRotate SpaceRotation;
379 FGCBspaceButton SpaceButton;
381 FGCBbuttonBox ButtonBox;
382 FGCBtabletMotion TabletMotion;
383 FGCBtabletButton TabletButton;
387 * This structure describes a menu
389 typedef struct tagSFG_Menu SFG_Menu;
393 void *UserData ; /* A. Donev: User data passed back at callback */
394 int ID; /* The global menu ID */
395 SFG_List Entries; /* The menu entries list */
396 FGCBmenu Callback; /* The menu callback */
397 FGCBdestroy Destroy; /* A. Donev: Destruction callback */
398 GLboolean IsActive; /* Is the menu selected? */
399 int Width; /* Menu box width in pixels */
400 int Height; /* Menu box height in pixels */
401 int X, Y; /* Menu box raster position */
405 * This is a menu entry
407 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
408 struct tagSFG_MenuEntry
411 int ID; /* The menu entry ID (local) */
412 int Ordinal; /* The menu's ordinal number */
413 char* Text; /* The text to be displayed */
414 SFG_Menu* SubMenu; /* Optional sub-menu tree */
415 GLboolean IsActive; /* Is the entry highlighted? */
416 int Width; /* Label's width in pixels */
420 * A window, making part of freeglut windows hierarchy. Should be kept portable.
422 typedef struct tagSFG_Window SFG_Window;
426 int ID; /* Window's ID number */
428 SFG_Context Window; /* Window and OpenGL context */
429 SFG_WindowState State; /* The window state */
430 SFG_WindowCallbacks Callbacks; /* The window callbacks */
431 void *UserData ; /* A. Donev: A pointer to user data used in rendering */
433 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
434 SFG_Menu* ActiveMenu; /* The window's active menu */
436 SFG_Window* Parent; /* The parent to this window */
437 SFG_List Children; /* The subwindows d.l. list */
441 * A linked list structure of windows
443 typedef struct tagSFG_WindowList SFG_WindowList ;
444 struct tagSFG_WindowList
447 GLboolean needToClose ;
448 SFG_WindowList *next ;
452 * This holds information about all the windows, menus etc.
454 typedef struct tagSFG_Structure SFG_Structure;
455 struct tagSFG_Structure
457 SFG_List Windows; /* The global windows list */
458 SFG_List Menus; /* The global menus list */
460 SFG_Window* Window; /* The currently active win. */
461 SFG_Menu* Menu; /* Same, but menu... */
463 SFG_Window* GameMode; /* The game mode window */
465 int WindowID; /* The new current window ID */
466 int MenuID; /* The new current menu ID */
470 * This structure is used for the enumeration purposes.
471 * You can easily extend its functionalities by declaring
472 * a structure containing enumerator's contents and custom
473 * data, then casting its pointer to (SFG_Enumerator *).
475 typedef struct tagSFG_Enumerator SFG_Enumerator;
476 struct tagSFG_Enumerator
478 GLboolean found; /* Used to terminate search */
479 void* data; /* Custom data pointer */
481 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
484 * The bitmap font structure
486 typedef struct tagSFG_Font SFG_Font;
489 char* Name; /* The source font name */
490 int Quantity; /* Number of chars in font */
491 int Height; /* Height of the characters */
492 const GLubyte** Characters; /* The characters mapping */
494 float xorig, yorig ; /* The origin of the character relative to the draw location */
498 * The stroke font structures
501 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
502 struct tagSFG_StrokeVertex
507 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
508 struct tagSFG_StrokeStrip
511 const SFG_StrokeVertex* Vertices;
514 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
515 struct tagSFG_StrokeChar
519 const SFG_StrokeStrip* Strips;
522 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
523 struct tagSFG_StrokeFont
525 char* Name; /* The source font name */
526 int Quantity; /* Number of chars in font */
527 GLfloat Height; /* Height of the characters */
528 const SFG_StrokeChar** Characters; /* The characters mapping */
531 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
534 * Freeglut display related stuff (initialized once per session)
536 extern SFG_Display fgDisplay;
539 * Freeglut internal structure
541 extern SFG_Structure fgStructure;
544 * The current freeglut settings
546 extern SFG_State fgState;
549 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
552 * A call to this function makes us sure that the Display and Structure
553 * subsystems have been properly initialized and are ready to be used
555 #define freeglut_assert_ready assert( fgState.Time.Set );
558 * Following definitions are somewhat similiar to GLib's,
559 * but do not generate any log messages:
561 #define freeglut_return_if_fail( expr ) if( !(expr) ) return;
562 #define freeglut_return_val_if_fail( expr, val ) if( !(expr) ) return( val );
565 * A call to those macros assures us that there is a current
566 * window and menu set, respectively:
568 #define freeglut_assert_window assert( fgStructure.Window != NULL );
569 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
572 * The initialize and deinitialize functions get called on glutInit()
573 * and glutMainLoop() end respectively. They should create/clean up
574 * everything inside of the freeglut
576 void fgInitialize( const char* displayName );
577 void fgDeinitialize( void );
580 * Those two functions are used to create/destroy the freeglut internal
581 * structures. This actually happens when calling glutInit() and when
582 * quitting the glutMainLoop() (which actually happens, when all windows
585 void fgCreateStructure( void );
586 void fgDestroyStructure( void );
589 * A helper function to check if a display mode is possible to use
591 #if TARGET_HOST_UNIX_X11
592 XVisualInfo* fgChooseVisual( void );
596 * The window procedure for Win32 events handling
598 #if TARGET_HOST_WIN32
599 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
600 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned char layer_type );
604 * Window creation, opening, closing and destruction.
605 * Defined in freeglut_structure.c, freeglut_window.c.
607 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, int x, int y, int w, int h, GLboolean gameMode );
608 void fgSetWindow ( SFG_Window *window ) ;
609 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode, int isSubWindow );
610 void fgCloseWindow( SFG_Window* window );
611 void fgAddToWindowDestroyList ( SFG_Window* window, GLboolean needToClose ) ;
612 void fgCloseWindows () ;
613 void fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
616 * Menu creation and destruction. Defined in freeglut_structure.c
618 SFG_Menu* fgCreateMenu( FGCBmenu menuCallback );
619 void fgDestroyMenu( SFG_Menu* menu );
622 * Joystick device management functions, defined in freeglut_joystick.c
624 void fgJoystickInit( int ident );
625 void fgJoystickClose( void );
626 void fgJoystickPollWindow( SFG_Window* window );
629 * Helper function to enumerate through all registered windows
630 * and one to enumerate all of a window's subwindows...
632 * The GFunc callback for those functions will be defined as:
634 * void enumCallback( gpointer window, gpointer enumerator );
636 * where window is the enumerated (sub)window pointer (SFG_Window *),
637 * and userData is the a custom user-supplied pointer. Functions
638 * are defined and exported from freeglut_structure.c file.
640 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
641 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
644 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
645 * first window in the queue matching the specified window handle.
646 * The function is defined in freeglut_structure.c file.
648 #if TARGET_HOST_UNIX_X11
649 SFG_Window* fgWindowByHandle( Window hWindow );
650 #elif TARGET_HOST_WIN32
652 SFG_Window* fgWindowByHandle( HWND hWindow );
656 * This function is similiar to the previous one, except it is
657 * looking for a specified (sub)window identifier. The function
658 * is defined in freeglut_structure.c file.
660 SFG_Window* fgWindowByID( int windowID );
663 * Looks up a menu given its ID. This is easier that fgWindowByXXX
664 * as all menus are placed in a single doubly linked list...
666 SFG_Menu* fgMenuByID( int menuID );
669 * The menu activation and deactivation the code. This is the meat
670 * of the menu user interface handling code...
672 void fgActivateMenu( SFG_Window* window, int button );
673 void fgExecuteMenuCallback( SFG_Menu* menu ) ;
674 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu ) ;
675 void fgDeactivateMenu( SFG_Window *window );
678 * This function gets called just before the buffers swap, so that
679 * freeglut can display the pull-down menus via OpenGL. The function
680 * is defined in freeglut_menu.c file.
682 void fgDisplayMenu( void );
685 * Display the mouse cursor using OpenGL calls. The function
686 * is defined in freeglut_cursor.c file.
688 void fgDisplayCursor( void );
691 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
693 long fgElapsedTime( void );
698 void fgListInit(SFG_List *list);
699 void fgListAppend(SFG_List *list, SFG_Node *node);
700 void fgListRemove(SFG_List *list, SFG_Node *node);
701 int fgListLength(SFG_List *list);
704 * Error Messages functions
706 void fgError( const char *fmt, ... );
707 void fgWarning( const char *fmt, ... );
709 #endif /* FREEGLUT_INTERNAL_H */
711 /*** END OF FILE ***/