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
32 * Freeglut is meant to be available under all Unix/X11 and Win32 platforms.
35 # define TARGET_HOST_UNIX_X11 1
36 # define TARGET_HOST_WIN32 0
38 # define TARGET_HOST_UNIX_X11 0
39 # define TARGET_HOST_WIN32 1
42 #define FREEGLUT_MAX_MENUS 3
43 #define FREEGLUT_DEBUG 1
46 #undef G_DISABLE_ASSERT
47 #undef G_DISABLE_CHECKS
49 #define G_DISABLE_ASSERT
50 #define G_DISABLE_CHECKS
54 * Somehow all Win32 include headers depend on this one:
60 #define strdup _strdup
64 * Those files should be available on every platform.
74 #if TARGET_HOST_UNIX_X11
79 * The system-dependant include files should go here:
81 #if TARGET_HOST_UNIX_X11
84 #include <X11/Xatom.h>
85 #include <X11/keysym.h>
88 #include <X11/extensions/xf86vmode.h>
93 * Microsoft VisualC++ 5.0's <math.h> does not define the PI
96 # define M_PI 3.14159265358979323846
107 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
110 * Freeglut callbacks type definitions
112 typedef void (* FGCBdisplay )( void );
113 typedef void (* FGCBreshape )( int, int );
114 typedef void (* FGCBvisibility )( int );
115 typedef void (* FGCBkeyboard )( unsigned char, int, int );
116 typedef void (* FGCBspecial )( int, int, int );
117 typedef void (* FGCBmouse )( int, int, int, int );
118 typedef void (* FGCBmotion )( int, int );
119 typedef void (* FGCBpassive )( int, int );
120 typedef void (* FGCBentry )( int );
121 typedef void (* FGCBwindowStatus )( int );
122 typedef void (* FGCBmenuState )( int );
123 typedef void (* FGCBmenuStatus )( int, int, int );
124 typedef void (* FGCBselect )( int, int, int );
125 typedef void (* FGCBjoystick )( unsigned int, int, int, int );
126 typedef void (* FGCBkeyboardUp )( unsigned char, int, int );
127 typedef void (* FGCBspecialUp )( int, int, int );
128 typedef void (* FGCBoverlayDisplay)( void );
129 typedef void (* FGCBspaceMotion )( int, int, int );
130 typedef void (* FGCBspaceRotate )( int, int, int );
131 typedef void (* FGCBspaceButton )( int, int );
132 typedef void (* FGCBdials )( int, int );
133 typedef void (* FGCBbuttonBox )( int, int );
134 typedef void (* FGCBtabletMotion )( int, int );
135 typedef void (* FGCBtabletButton )( int, int, int, int );
136 typedef void (* FGCBdestroy )( void );
139 * The global callbacks type definitions
141 typedef void (* FGCBidle )( void );
142 typedef void (* FGCBtimer )( int );
145 * The callback used when creating/using menus
147 typedef void (* FGCBmenu )( int );
153 typedef struct tagSFG_List SFG_List;
161 * A list node structure
163 typedef struct tagSFG_Node SFG_Node;
171 * A helper structure holding two ints and a boolean
173 typedef struct tagSFG_XYUse SFG_XYUse;
176 GLint X, Y; /* The two integers... */
177 GLboolean Use; /* ...and a single boolean. */
181 * A helper structure holding a timeval and a boolean
183 typedef struct tagSFG_Time SFG_Time;
189 struct timeval Value;
195 * An enumeration containing the state of the GLUT execution: initializing, running, or stopping
198 GLUT_EXEC_STATE_INIT,
199 GLUT_EXEC_STATE_RUNNING,
204 * This structure holds different freeglut settings
206 typedef struct tagSFG_State SFG_State;
209 SFG_XYUse Position; /* The default windows' position */
210 SFG_XYUse Size; /* The default windows' size */
211 unsigned int DisplayMode; /* The display mode for new windows */
213 GLboolean ForceDirectContext; /* Should we force direct contexts? */
214 GLboolean TryDirectContext; /* What about giving a try to? */
216 GLboolean ForceIconic; /* All new top windows are iconified */
218 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
219 GLboolean XSyncSwitch; /* X11 sync protocol switch */
221 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat... */
223 GLuint FPSInterval; /* Interval between FPS printfs */
224 GLuint SwapCount; /* Count of glutSwapBuffer calls */
225 GLuint SwapTime; /* Time of last SwapBuffers */
227 SFG_Time Time; /* The time that glutInit was called */
228 SFG_List Timers; /* The freeglut timer hooks */
230 FGCBidle IdleCallback; /* The global idle callback */
232 FGCBmenuState MenuStateCallback; /* Menu callbacks are global */
233 FGCBmenuStatus MenuStatusCallback;
235 SFG_XYUse GameModeSize; /* The game mode screen's dimensions */
236 int GameModeDepth; /* The pixel depth for game mode */
237 int GameModeRefresh; /* The refresh rate for game mode */
239 int ActionOnWindowClose ; /* Action when user clicks "x" on window header bar */
241 fgExecutionState ExecState ; /* Current state of the GLUT execution */
245 * The structure used by display initialization in freeglut_init.c
247 typedef struct tagSFG_Display SFG_Display;
248 struct tagSFG_Display
250 #if TARGET_HOST_UNIX_X11
251 Display* Display; /* The display we are being run in. */
252 int Screen; /* The screen we are about to use. */
253 Window RootWindow; /* The screen's root window. */
254 int Connection; /* The display's connection number */
255 Atom DeleteWindow; /* The window deletion atom */
257 #ifdef X_XF86VidModeGetModeLine
258 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
259 int DisplayModeClock; /* The display mode's refresh rate */
262 #elif TARGET_HOST_WIN32
263 HINSTANCE Instance; /* The application's instance */
264 DEVMODE DisplayMode; /* Desktop's display settings */
268 int ScreenWidth; /* The screen's width in pixels */
269 int ScreenHeight; /* The screen's height in pixels */
270 int ScreenWidthMM; /* The screen's width in milimeters */
271 int ScreenHeightMM; /* The screen's height in milimeters */
276 * The user can create any number of timer hooks
278 typedef struct tagSFG_Timer SFG_Timer;
282 int ID; /* The timer ID integer */
283 FGCBtimer Callback; /* The timer callback */
284 long TriggerTime; /* The timer trigger time */
288 * A window and its OpenGL context. The contents of this structure
289 * are highly dependant on the target operating system we aim at...
291 typedef struct tagSFG_Context SFG_Context;
292 struct tagSFG_Context
294 #if TARGET_HOST_UNIX_X11
295 Window Handle; /* The window's handle */
296 GLXContext Context; /* The OpenGL context */
297 XVisualInfo* VisualInfo; /* The window's visual information */
299 #elif TARGET_HOST_WIN32
300 HWND Handle; /* The window's handle */
301 HDC Device; /* The window's device context */
302 HGLRC Context; /* The window's WGL context */
306 int DoubleBuffered; /* Treat the window as double-buffered */
310 * Window's state description. This structure should be kept portable.
312 typedef struct tagSFG_WindowState SFG_WindowState;
313 struct tagSFG_WindowState
315 int Width; /* Window's width in pixels */
316 int Height; /* The same about the height */
318 GLboolean Redisplay; /* Do we have to redisplay? */
319 GLboolean Visible; /* Is the window visible now */
321 int Cursor; /* The currently selected cursor */
322 int Modifiers; /* The current ALT/SHIFT/CTRL state */
324 long JoystickPollRate; /* The joystick polling rate */
325 long JoystickLastPoll; /* When the last poll has happened */
327 int MouseX, MouseY; /* The most recent mouse position */
329 GLboolean IsGameMode; /* Is this the game mode window? */
331 #if TARGET_HOST_WIN32
332 GLboolean NeedToResize; /* Do we need to explicitly resize? */
337 * The window callbacks the user can supply us with. Should be kept portable.
339 typedef struct tagSFG_WindowCallbacks SFG_WindowCallbacks;
340 struct tagSFG_WindowCallbacks
343 * Following callbacks are fully supported right now
344 * and are ready to be tested for GLUT conformance:
348 FGCBkeyboard Keyboard;
349 FGCBkeyboardUp KeyboardUp;
351 FGCBspecialUp SpecialUp;
356 FGCBvisibility Visibility;
357 FGCBwindowStatus WindowStatus;
358 FGCBjoystick Joystick;
362 * Those callbacks are being ignored for the moment
365 FGCBoverlayDisplay OverlayDisplay;
366 FGCBspaceMotion SpaceMotion;
367 FGCBspaceRotate SpaceRotation;
368 FGCBspaceButton SpaceButton;
370 FGCBbuttonBox ButtonBox;
371 FGCBtabletMotion TabletMotion;
372 FGCBtabletButton TabletButton;
376 * This structure describes a menu
378 typedef struct tagSFG_Menu SFG_Menu;
382 int ID; /* The global menu ID */
383 SFG_List Entries; /* The menu entries list */
384 FGCBmenu Callback; /* The menu callback */
385 GLboolean IsActive; /* Is the menu selected? */
386 int Width; /* Menu box width in pixels */
387 int Height; /* Menu box height in pixels */
388 int X, Y; /* Menu box raster position */
392 * This is a menu entry
394 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
395 struct tagSFG_MenuEntry
398 int ID; /* The menu entry ID (local) */
399 int Ordinal; /* The menu's ordinal number */
400 char* Text; /* The text to be displayed */
401 SFG_Menu* SubMenu; /* Optional sub-menu tree */
402 GLboolean IsActive; /* Is the entry highlighted? */
403 int Width; /* Label's width in pixels */
407 * A window, making part of FreeGLUT windows hierarchy. Should be kept portable.
409 typedef struct tagSFG_Window SFG_Window;
413 int ID; /* Window's ID number */
415 SFG_Context Window; /* Window and OpenGL context */
416 SFG_WindowState State; /* The window state */
417 SFG_WindowCallbacks Callbacks; /* The window callbacks */
419 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
420 SFG_Menu* ActiveMenu; /* The window's active menu */
422 SFG_Window* Parent; /* The parent to this window */
423 SFG_List Children; /* The subwindows d.l. list */
427 * A linked list structure of windows
429 typedef struct tagSFG_WindowList SFG_WindowList ;
430 struct tagSFG_WindowList
433 GLboolean needToClose ;
434 SFG_WindowList *next ;
438 * This holds information about all the windows, menus etc.
440 typedef struct tagSFG_Structure SFG_Structure;
441 struct tagSFG_Structure
443 SFG_List Windows; /* The global windows list */
444 SFG_List Menus; /* The global menus list */
446 SFG_Window* Window; /* The currently active win. */
447 SFG_Menu* Menu; /* Same, but menu... */
449 SFG_Window* GameMode; /* The game mode window */
451 int WindowID; /* The new current window ID */
452 int MenuID; /* The new current menu ID */
456 * This structure is used for the enumeration purposes.
457 * You can easily extend its functionalities by declaring
458 * a structure containing enumerator's contents and custom
459 * data, then casting its pointer to (SFG_Enumerator *).
461 typedef struct tagSFG_Enumerator SFG_Enumerator;
462 struct tagSFG_Enumerator
464 GLboolean found; /* Used to terminate search */
465 void* data; /* Custom data pointer */
467 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
470 * The bitmap font structure
472 typedef struct tagSFG_Font SFG_Font;
475 char* Name; /* The source font name */
476 int Quantity; /* Number of chars in font */
477 int Height; /* Height of the characters */
478 const GLubyte** Characters; /* The characters mapping */
480 float xorig, yorig ; /* The origin of the character relative to the draw location */
484 * The stroke font structures
487 typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
488 struct tagSFG_StrokeVertex
493 typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
494 struct tagSFG_StrokeStrip
497 const SFG_StrokeVertex* Vertices;
500 typedef struct tagSFG_StrokeChar SFG_StrokeChar;
501 struct tagSFG_StrokeChar
505 const SFG_StrokeStrip* Strips;
508 typedef struct tagSFG_StrokeFont SFG_StrokeFont;
509 struct tagSFG_StrokeFont
511 char* Name; /* The source font name */
512 int Quantity; /* Number of chars in font */
513 GLfloat Height; /* Height of the characters */
514 const SFG_StrokeChar** Characters; /* The characters mapping */
517 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
520 * Freeglut display related stuff (initialized once per session)
522 extern SFG_Display fgDisplay;
525 * Freeglut internal structure
527 extern SFG_Structure fgStructure;
530 * The current freeglut settings
532 extern SFG_State fgState;
535 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
538 * A call to this function makes us sure that the Display and Structure
539 * subsystems have been properly initialized and are ready to be used
541 #define freeglut_assert_ready assert( fgState.Time.Set );
544 * Following definitions are somewhat similiar to GLib's,
545 * but do not generate any log messages:
547 #define freeglut_return_if_fail( expr ) if( !(expr) ) return;
548 #define freeglut_return_val_if_fail( expr, val ) if( !(expr) ) return( val );
551 * A call to those macros assures us that there is a current
552 * window and menu set, respectively:
554 #define freeglut_assert_window assert( fgStructure.Window != NULL );
555 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
558 * The initialize and deinitialize functions get called on glutInit()
559 * and glutMainLoop() end respectively. They should create/clean up
560 * everything inside of the freeglut
562 void fgInitialize( const char* displayName );
563 void fgDeinitialize( void );
566 * Those two functions are used to create/destroy the freeglut internal
567 * structures. This actually happens when calling glutInit() and when
568 * quitting the glutMainLoop() (which actually happens, when all windows
571 void fgCreateStructure( void );
572 void fgDestroyStructure( void );
575 * A helper function to check if a display mode is possible to use
577 #if TARGET_HOST_UNIX_X11
578 XVisualInfo* fgChooseVisual( void );
582 * The window procedure for Win32 events handling
584 #if TARGET_HOST_WIN32
585 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
586 GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned char layer_type );
590 * Window creation, opening, closing and destruction.
591 * Defined in freeglut_structure.c, freeglut_window.c.
593 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, int x, int y, int w, int h, GLboolean gameMode );
594 void fgSetWindow ( SFG_Window *window ) ;
595 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode, int isSubWindow );
596 void fgCloseWindow( SFG_Window* window );
597 void fgAddToWindowDestroyList ( SFG_Window* window, GLboolean needToClose ) ;
598 void fgCloseWindows () ;
599 void fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
602 * Menu creation and destruction. Defined in freeglut_structure.c
604 SFG_Menu* fgCreateMenu( FGCBmenu menuCallback );
605 void fgDestroyMenu( SFG_Menu* menu );
608 * Joystick device management functions, defined in freeglut_joystick.c
610 void fgJoystickInit( int ident );
611 void fgJoystickClose( void );
612 void fgJoystickPollWindow( SFG_Window* window );
615 * Helper function to enumerate through all registered windows
616 * and one to enumerate all of a window's subwindows...
618 * The GFunc callback for those functions will be defined as:
620 * void enumCallback( gpointer window, gpointer enumerator );
622 * where window is the enumerated (sub)window pointer (SFG_Window *),
623 * and userData is the a custom user-supplied pointer. Functions
624 * are defined and exported from freeglut_structure.c file.
626 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
627 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
630 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
631 * first window in the queue matching the specified window handle.
632 * The function is defined in freeglut_structure.c file.
634 #if TARGET_HOST_UNIX_X11
635 SFG_Window* fgWindowByHandle( Window hWindow );
636 #elif TARGET_HOST_WIN32
638 SFG_Window* fgWindowByHandle( HWND hWindow );
642 * This function is similiar to the previous one, except it is
643 * looking for a specified (sub)window identifier. The function
644 * is defined in freeglut_structure.c file.
646 SFG_Window* fgWindowByID( int windowID );
649 * Looks up a menu given its ID. This is easier that fgWindowByXXX
650 * as all menus are placed in a single doubly linked list...
652 SFG_Menu* fgMenuByID( int menuID );
655 * The menu activation and deactivation the code. This is the meat
656 * of the menu user interface handling code...
658 void fgActivateMenu( SFG_Window* window, int button );
659 void fgExecuteMenuCallback( SFG_Menu* menu ) ;
660 GLboolean fgCheckActiveMenu ( SFG_Window *window, SFG_Menu *menu ) ;
661 void fgDeactivateMenu( SFG_Window *window );
664 * This function gets called just before the buffers swap, so that
665 * freeglut can display the pull-down menus via OpenGL. The function
666 * is defined in freeglut_menu.c file.
668 void fgDisplayMenu( void );
671 * Display the mouse cursor using OpenGL calls. The function
672 * is defined in freeglut_cursor.c file.
674 void fgDisplayCursor( void );
677 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
679 long fgElapsedTime( void );
684 void fgListInit(SFG_List *list);
685 void fgListAppend(SFG_List *list, SFG_Node *node);
686 void fgListRemove(SFG_List *list, SFG_Node *node);
687 int fgListLength(SFG_List *list);
690 * Error Messages functions
692 void fgError( const char *fmt, ... );
693 void fgWarning( const char *fmt, ... );
695 #endif /* FREEGLUT_INTERNAL_H */
697 /*** END OF FILE ***/