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:
62 * Those files should be available on every platform. GLib can be
63 * downloaded from ftp.gtk.org. Ports are available for most Unix
64 * systems and Win32 (for both native and posix-emulation modes).
74 * The system-dependant include files should go here:
76 #if TARGET_HOST_UNIX_X11
79 #include <X11/Xatom.h>
80 #include <X11/keysym.h>
83 * This will generate errors, but I don't have any idea how to fix it (will autoconf help?)
85 #include <X11/extensions/xf86vmode.h>
89 * Microsoft VisualC++ 5.0's <math.h> does not define the PI
92 # define M_PI 3.14159265358979323846
96 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
99 * Freeglut callbacks type definitions
101 typedef void (* FGCBdisplay )( void );
102 typedef void (* FGCBreshape )( int, int );
103 typedef void (* FGCBvisibility )( int );
104 typedef void (* FGCBkeyboard )( unsigned char, int, int );
105 typedef void (* FGCBspecial )( int, int, int );
106 typedef void (* FGCBmouse )( int, int, int, int );
107 typedef void (* FGCBmotion )( int, int );
108 typedef void (* FGCBpassive )( int, int );
109 typedef void (* FGCBentry )( int );
110 typedef void (* FGCBwindowStatus )( int );
111 typedef void (* FGCBmenuState )( int );
112 typedef void (* FGCBmenuStatus )( int, int, int );
113 typedef void (* FGCBselect )( int, int, int );
114 typedef void (* FGCBjoystick )( unsigned int, int, int, int );
115 typedef void (* FGCBkeyboardUp )( unsigned char, int, int );
116 typedef void (* FGCBspecialUp )( int, int, int );
117 typedef void (* FGCBoverlayDisplay)( void );
118 typedef void (* FGCBspaceMotion )( int, int, int );
119 typedef void (* FGCBspaceRotate )( int, int, int );
120 typedef void (* FGCBspaceButton )( int, int );
121 typedef void (* FGCBdials )( int, int );
122 typedef void (* FGCBbuttonBox )( int, int );
123 typedef void (* FGCBtabletMotion )( int, int );
124 typedef void (* FGCBtabletButton )( int, int, int, int );
127 * The global callbacks type definitions
129 typedef void (* FGCBidle )( void );
130 typedef void (* FGCBtimer )( int );
133 * The callback used when creating/using menus
135 typedef void (* FGCBmenu )( int );
138 * A helper structure holding two ints and a boolean
140 typedef struct tagSFG_XYUse SFG_XYUse;
143 gint X, Y; /* The two integers... */
144 gboolean Use; /* ...and a single boolean. */
148 * This structure holds different freeglut settings
150 typedef struct tagSFG_State SFG_State;
153 SFG_XYUse Position; /* The default windows' position */
154 SFG_XYUse Size; /* The default windows' size */
155 guint DisplayMode; /* The display mode for new windows */
157 gboolean ForceDirectContext; /* Should we force direct contexts? */
158 gboolean TryDirectContext; /* What about giving a try to? */
160 gboolean ForceIconic; /* All new top windows are iconified */
162 gboolean GLDebugSwitch; /* OpenGL state debugging switch */
163 gboolean XSyncSwitch; /* X11 sync protocol switch */
165 gboolean IgnoreKeyRepeat; /* Whether to ignore key repeat... */
167 GTimer* Timer; /* This timer is started on glutInit */
168 GList* Timers; /* The freeglut timer hooks */
170 FGCBidle IdleCallback; /* The global idle callback */
172 SFG_XYUse GameModeSize; /* The game mode screen's dimensions */
173 gint GameModeDepth; /* The pixel depth for game mode */
174 gint GameModeRefresh; /* The refresh rate for game mode */
178 * The structure used by display initialization in freeglut_init.c
180 typedef struct tagSFG_Display SFG_Display;
181 struct tagSFG_Display
183 #if TARGET_HOST_UNIX_X11
184 Display* Display; /* The display we are being run in. */
185 gint Screen; /* The screen we are about to use. */
186 Window RootWindow; /* The screen's root window. */
187 gint Connection; /* The display's connection number */
188 Atom DeleteWindow; /* The window deletion atom */
190 #ifdef X_XF86VidModeGetModeLine
191 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
192 gint DisplayModeClock; /* The display mode's refresh rate */
195 #elif TARGET_HOST_WIN32
196 HINSTANCE Instance; /* The application's instance */
197 DEVMODE DisplayMode; /* Desktop's display settings */
201 gint ScreenWidth; /* The screen's width in pixels */
202 gint ScreenHeight; /* The screen's height in pixels */
203 gint ScreenWidthMM; /* The screen's width in milimeters */
204 gint ScreenHeightMM; /* The screen's height in milimeters */
209 * The user can create any number of timer hooks
211 typedef struct tagSFG_Timer SFG_Timer;
214 gint32 ID; /* The timer ID integer */
215 FGCBtimer Callback; /* The timer callback */
216 double TriggerTime; /* The timer trigger time */
220 * A window and it's OpenGL context. The contents of this structure
221 * are highly dependant on the target operating system we aim at...
223 typedef struct tagSFG_Context SFG_Context;
224 struct tagSFG_Context
226 #if TARGET_HOST_UNIX_X11
227 Window Handle; /* The window's handle */
228 GLXContext Context; /* The OpenGL context */
229 XVisualInfo* VisualInfo; /* The window's visual information */
231 #elif TARGET_HOST_WIN32
232 HWND Handle; /* The window's handle */
233 HDC Device; /* The window's device context */
234 HGLRC Context; /* The window's WGL context */
240 * Window's state description. This structure should be kept portable.
242 typedef struct tagSFG_WindowState SFG_WindowState;
243 struct tagSFG_WindowState
245 gint Width; /* Window's width in pixels */
246 gint Height; /* The same about the height */
248 gboolean Redisplay; /* Do we have to redisplay? */
249 gboolean Visible; /* Is the window visible now */
251 gint Cursor; /* The currently selected cursor */
252 guint32 Modifiers; /* The current ALT/SHIFT/CTRL state */
254 double JoystickPollRate; /* The joystick polling rate */
255 double JoystickLastPoll; /* When the last poll has happened */
257 gint MouseX, MouseY; /* The most recent mouse position */
259 gboolean IsGameMode; /* Is this the game mode window? */
261 #if TARGET_HOST_WIN32
262 gboolean NeedToResize; /* Do we need to explicitly resize? */
267 * The window callbacks the user can supply us with. Should be kept portable.
269 typedef struct tagSFG_WindowCallbacks SFG_WindowCallbacks;
270 struct tagSFG_WindowCallbacks
273 * Following callbacks are fully supported right now
274 * and are ready to be tested for GLUT conformance:
278 FGCBkeyboard Keyboard;
284 FGCBvisibility Visibility;
285 FGCBwindowStatus WindowStatus;
288 * Those callbacks are required for the initial version
290 FGCBmenuState MenuState;
291 FGCBmenuStatus MenuStatus;
293 FGCBjoystick Joystick;
294 FGCBkeyboardUp KeyboardUp;
295 FGCBspecialUp SpecialUp;
298 * Those callbacks are being ignored for the moment
300 FGCBoverlayDisplay OverlayDisplay;
301 FGCBspaceMotion SpaceMotion;
302 FGCBspaceRotate SpaceRotation;
303 FGCBspaceButton SpaceButton;
305 FGCBbuttonBox ButtonBox;
306 FGCBtabletMotion TabletMotion;
307 FGCBtabletButton TabletButton;
311 * This structure describes a menu
313 typedef struct tagSFG_Menu SFG_Menu;
316 gint ID; /* The global menu ID */
317 GList* Entries; /* The menu entries list */
318 FGCBmenu Callback; /* The menu callback */
319 gboolean IsActive; /* Is the menu selected? */
320 gint Width; /* Menu box width in pixels */
321 gint Height; /* Menu box height in pixels */
322 gint X, Y; /* Menu box raster position */
326 * This is a menu entry
328 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
329 struct tagSFG_MenuEntry
331 gint ID; /* The menu entry ID (local) */
332 gint Ordinal; /* The menu's ordinal number */
333 GString* Text; /* The text to be displayed */
334 SFG_Menu* SubMenu; /* Optional sub-menu tree */
335 gboolean IsActive; /* Is the entry highlighted? */
336 gint Width; /* Label's width in pixels */
340 * A window, making part of FreeGLUT windows hierarchy. Should be kept portable.
342 typedef struct tagSFG_Window SFG_Window;
345 gint ID; /* Window's ID number */
347 SFG_Context Window; /* Window and OpenGL context */
348 SFG_WindowState State; /* The window state */
349 SFG_WindowCallbacks Callbacks; /* The window callbacks */
351 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
352 gboolean MenuActive[ FREEGLUT_MAX_MENUS ]; /* The menus activity flags */
354 SFG_Window* Parent; /* The parent to this window */
355 GList* Children; /* The subwindows d.l. list */
359 * This holds information about all the windows, menus etc.
361 typedef struct tagSFG_Structure SFG_Structure;
362 struct tagSFG_Structure
364 GList* Windows; /* The global windows list */
365 GList* Menus; /* The global menus list */
367 SFG_Window* Window; /* The currently active win. */
368 SFG_Menu* Menu; /* Same, but menu... */
370 SFG_Window* GameMode; /* The game mode window */
372 gint WindowID; /* The new current window ID */
373 gint MenuID; /* The new current menu ID */
377 * This structure is used for the enumeration purposes.
378 * You can easily extend it's functionalities by declaring
379 * a structure containing enumerator's contents and custom
380 * data, then casting it's pointer to (SFG_Enumerator *).
382 typedef struct tagSFG_Enumerator SFG_Enumerator;
383 struct tagSFG_Enumerator
385 gboolean found; /* Used to terminate search */
386 gpointer data; /* Custom data pointer */
390 * The bitmap font structure
392 typedef struct tagSFG_Font SFG_Font;
395 gchar* Name; /* The source font name */
396 gint Quantity; /* Number of chars in font */
397 gint Height; /* Height of the characters */
398 const guchar** Characters; /* The characters mapping */
402 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
405 * Freeglut display related stuff (initialized once per session)
407 extern SFG_Display fgDisplay;
410 * Freeglut internal structure
412 extern SFG_Structure fgStructure;
415 * The current freeglut settings
417 extern SFG_State fgState;
420 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
423 * A call to this function makes us sure that the Display and Structure
424 * subsystems have been properly initialized and are ready to be used
426 #define freeglut_assert_ready g_assert( fgState.Timer != NULL );
429 * Following definitions are somewhat similiar to GLib's,
430 * but do not generate any log messages:
432 #define freeglut_return_if_fail( expr ) if( !(expr) ) return;
433 #define freeglut_return_val_if_fail( expr, val ) if( !(expr) ) return( val );
436 * A call to those macros assures us that there is a current
437 * window and menu set, respectively:
439 #define freeglut_assert_window g_assert( fgStructure.Window != NULL );
440 #define freeglut_assert_menu g_assert( fgStructure.Menu != NULL );
443 * The initialize and deinitialize functions get called on glutInit()
444 * and glutMainLoop() end respectively. They should create/clean up
445 * everything inside of the freeglut
447 void fgInitialize( const gchar* displayName );
448 void fgDeinitialize( void );
451 * Those two functions are used to create/destroy the freeglut internal
452 * structures. This actually happens when calling glutInit() and when
453 * quitting the glutMainLoop() (which actually happens, when all windows
456 void fgCreateStructure( void );
457 void fgDestroyStructure( void );
460 * A helper function to check if a display mode is possible to use
462 #if TARGET_HOST_UNIX_X11
463 XVisualInfo* fgChooseVisual( void );
467 * The window procedure for Win32 events handling
469 #if TARGET_HOST_WIN32
470 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
471 gboolean fgSetupPixelFormat( SFG_Window* window, gboolean checkOnly );
475 * Window creation, opening, closing and destruction.
476 * Defined in freeglut_structure.c, freeglut_window.c.
478 SFG_Window* fgCreateWindow( SFG_Window* parent, const gchar* title, gint x, gint y, gint w, gint h, gboolean gameMode );
479 void fgOpenWindow( SFG_Window* window, const gchar* title, gint x, gint y, gint w, gint h, gboolean gameMode );
480 void fgCloseWindow( SFG_Window* window );
481 void fgDestroyWindow( SFG_Window* window, gboolean needToClose );
484 * Menu creation and destruction. Defined in freeglut_structure.c
486 SFG_Menu* fgCreateMenu( FGCBmenu menuCallback );
487 void fgDestroyMenu( SFG_Menu* menu );
490 * Joystick device management functions, defined in freeglut_joystick.c
492 void fgJoystickInit( gint ident );
493 void fgJoystickClose( void );
494 void fgJoystickPollWindow( SFG_Window* window );
497 * Helper function to enumerate through all registered windows
498 * and one to enumerate all of a window's subwindows...
500 * The GFunc callback for those functions will be defined as:
502 * void enumCallback( gpointer window, gpointer enumerator );
504 * where window is the enumerated (sub)window pointer (SFG_Window *),
505 * and userData is the a custom user-supplied pointer. Functions
506 * are defined and exported from freeglut_structure.c file.
508 void fgEnumWindows( GFunc enumCallback, SFG_Enumerator* enumerator );
509 void fgEnumSubWindows( SFG_Window* window, GFunc enumCallback, SFG_Enumerator* enumerator );
512 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
513 * first window in the queue matching the specified window handle.
514 * The function is defined in freeglut_structure.c file.
516 #if TARGET_HOST_UNIX_X11
517 SFG_Window* fgWindowByHandle( Window hWindow );
518 #elif TARGET_HOST_WIN32
520 SFG_Window* fgWindowByHandle( HWND hWindow );
524 * This function is similiar to the previous one, except it is
525 * looking for a specified (sub)window identifier. The function
526 * is defined in freeglut_structure.c file.
528 SFG_Window* fgWindowByID( gint windowID );
531 * Looks up a menu given it's ID. This is easier that fgWindowByXXX
532 * as all menus are placed in a single doubly linked list...
534 SFG_Menu* fgMenuByID( gint menuID );
537 * The menu activation and deactivation the code. This is the meat
538 * of the menu user interface handling code...
540 void fgActivateMenu( gint button );
541 void fgDeactivateMenu( gint button );
544 * This function gets called just before the buffers swap, so that
545 * freeglut can display the pull-down menus via OpenGL. The function
546 * is defined in freeglut_menu.c file.
548 void fgDisplayMenu( void );
551 * Display the mouse cursor using OpenGL calls. The function
552 * is defined in freeglut_cursor.c file.
554 void fgDisplayCursor( void );
556 #endif /* FREEGLUT_INTERNAL_H */
558 /*** END OF FILE ***/