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.
75 * The system-dependant include files should go here:
77 #if TARGET_HOST_UNIX_X11
80 #include <X11/Xatom.h>
81 #include <X11/keysym.h>
84 * This will generate errors, but I don't have any idea how to fix it (will autoconf help?)
86 #include <X11/extensions/xf86vmode.h>
90 * Microsoft VisualC++ 5.0's <math.h> does not define the PI
93 # define M_PI 3.14159265358979323846
104 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
107 * Freeglut callbacks type definitions
109 typedef void (* FGCBdisplay )( void );
110 typedef void (* FGCBreshape )( int, int );
111 typedef void (* FGCBvisibility )( int );
112 typedef void (* FGCBkeyboard )( unsigned char, int, int );
113 typedef void (* FGCBspecial )( int, int, int );
114 typedef void (* FGCBmouse )( int, int, int, int );
115 typedef void (* FGCBmotion )( int, int );
116 typedef void (* FGCBpassive )( int, int );
117 typedef void (* FGCBentry )( int );
118 typedef void (* FGCBwindowStatus )( int );
119 typedef void (* FGCBmenuState )( int );
120 typedef void (* FGCBmenuStatus )( int, int, int );
121 typedef void (* FGCBselect )( int, int, int );
122 typedef void (* FGCBjoystick )( unsigned int, int, int, int );
123 typedef void (* FGCBkeyboardUp )( unsigned char, int, int );
124 typedef void (* FGCBspecialUp )( int, int, int );
125 typedef void (* FGCBoverlayDisplay)( void );
126 typedef void (* FGCBspaceMotion )( int, int, int );
127 typedef void (* FGCBspaceRotate )( int, int, int );
128 typedef void (* FGCBspaceButton )( int, int );
129 typedef void (* FGCBdials )( int, int );
130 typedef void (* FGCBbuttonBox )( int, int );
131 typedef void (* FGCBtabletMotion )( int, int );
132 typedef void (* FGCBtabletButton )( int, int, int, int );
135 * The global callbacks type definitions
137 typedef void (* FGCBidle )( void );
138 typedef void (* FGCBtimer )( int );
141 * The callback used when creating/using menus
143 typedef void (* FGCBmenu )( int );
149 typedef struct tagSFG_List SFG_List;
157 * A list node structure
159 typedef struct tagSFG_Node SFG_Node;
167 * A helper structure holding two ints and a boolean
169 typedef struct tagSFG_XYUse SFG_XYUse;
172 GLint X, Y; /* The two integers... */
173 GLboolean Use; /* ...and a single boolean. */
177 * A helper structure holding a timeval and a boolean
179 typedef struct tagSFG_Time SFG_Time;
182 struct timeval Value;
187 * This structure holds different freeglut settings
189 typedef struct tagSFG_State SFG_State;
192 SFG_XYUse Position; /* The default windows' position */
193 SFG_XYUse Size; /* The default windows' size */
194 unsigned int DisplayMode; /* The display mode for new windows */
196 GLboolean ForceDirectContext; /* Should we force direct contexts? */
197 GLboolean TryDirectContext; /* What about giving a try to? */
199 GLboolean ForceIconic; /* All new top windows are iconified */
201 GLboolean GLDebugSwitch; /* OpenGL state debugging switch */
202 GLboolean XSyncSwitch; /* X11 sync protocol switch */
204 GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat... */
206 SFG_Time Time; /* The time that glutInit was called */
207 SFG_List Timers; /* The freeglut timer hooks */
209 FGCBidle IdleCallback; /* The global idle callback */
211 SFG_XYUse GameModeSize; /* The game mode screen's dimensions */
212 int GameModeDepth; /* The pixel depth for game mode */
213 int GameModeRefresh; /* The refresh rate for game mode */
217 * The structure used by display initialization in freeglut_init.c
219 typedef struct tagSFG_Display SFG_Display;
220 struct tagSFG_Display
222 #if TARGET_HOST_UNIX_X11
223 Display* Display; /* The display we are being run in. */
224 int Screen; /* The screen we are about to use. */
225 Window RootWindow; /* The screen's root window. */
226 int Connection; /* The display's connection number */
227 Atom DeleteWindow; /* The window deletion atom */
229 #ifdef X_XF86VidModeGetModeLine
230 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
231 int DisplayModeClock; /* The display mode's refresh rate */
234 #elif TARGET_HOST_WIN32
235 HINSTANCE Instance; /* The application's instance */
236 DEVMODE DisplayMode; /* Desktop's display settings */
240 int ScreenWidth; /* The screen's width in pixels */
241 int ScreenHeight; /* The screen's height in pixels */
242 int ScreenWidthMM; /* The screen's width in milimeters */
243 int ScreenHeightMM; /* The screen's height in milimeters */
248 * The user can create any number of timer hooks
250 typedef struct tagSFG_Timer SFG_Timer;
254 int ID; /* The timer ID integer */
255 FGCBtimer Callback; /* The timer callback */
256 long TriggerTime; /* The timer trigger time */
260 * A window and it's OpenGL context. The contents of this structure
261 * are highly dependant on the target operating system we aim at...
263 typedef struct tagSFG_Context SFG_Context;
264 struct tagSFG_Context
266 #if TARGET_HOST_UNIX_X11
267 Window Handle; /* The window's handle */
268 GLXContext Context; /* The OpenGL context */
269 XVisualInfo* VisualInfo; /* The window's visual information */
271 #elif TARGET_HOST_WIN32
272 HWND Handle; /* The window's handle */
273 HDC Device; /* The window's device context */
274 HGLRC Context; /* The window's WGL context */
280 * Window's state description. This structure should be kept portable.
282 typedef struct tagSFG_WindowState SFG_WindowState;
283 struct tagSFG_WindowState
285 int Width; /* Window's width in pixels */
286 int Height; /* The same about the height */
288 GLboolean Redisplay; /* Do we have to redisplay? */
289 GLboolean Visible; /* Is the window visible now */
291 int Cursor; /* The currently selected cursor */
292 int Modifiers; /* The current ALT/SHIFT/CTRL state */
294 long JoystickPollRate; /* The joystick polling rate */
295 long JoystickLastPoll; /* When the last poll has happened */
297 int MouseX, MouseY; /* The most recent mouse position */
299 GLboolean IsGameMode; /* Is this the game mode window? */
301 #if TARGET_HOST_WIN32
302 GLboolean NeedToResize; /* Do we need to explicitly resize? */
307 * The window callbacks the user can supply us with. Should be kept portable.
309 typedef struct tagSFG_WindowCallbacks SFG_WindowCallbacks;
310 struct tagSFG_WindowCallbacks
313 * Following callbacks are fully supported right now
314 * and are ready to be tested for GLUT conformance:
318 FGCBkeyboard Keyboard;
324 FGCBvisibility Visibility;
325 FGCBwindowStatus WindowStatus;
328 * Those callbacks are required for the initial version
330 FGCBmenuState MenuState;
331 FGCBmenuStatus MenuStatus;
333 FGCBjoystick Joystick;
334 FGCBkeyboardUp KeyboardUp;
335 FGCBspecialUp SpecialUp;
338 * Those callbacks are being ignored for the moment
340 FGCBoverlayDisplay OverlayDisplay;
341 FGCBspaceMotion SpaceMotion;
342 FGCBspaceRotate SpaceRotation;
343 FGCBspaceButton SpaceButton;
345 FGCBbuttonBox ButtonBox;
346 FGCBtabletMotion TabletMotion;
347 FGCBtabletButton TabletButton;
351 * This structure describes a menu
353 typedef struct tagSFG_Menu SFG_Menu;
357 int ID; /* The global menu ID */
358 SFG_List Entries; /* The menu entries list */
359 FGCBmenu Callback; /* The menu callback */
360 GLboolean IsActive; /* Is the menu selected? */
361 int Width; /* Menu box width in pixels */
362 int Height; /* Menu box height in pixels */
363 int X, Y; /* Menu box raster position */
367 * This is a menu entry
369 typedef struct tagSFG_MenuEntry SFG_MenuEntry;
370 struct tagSFG_MenuEntry
373 int ID; /* The menu entry ID (local) */
374 int Ordinal; /* The menu's ordinal number */
375 char* Text; /* The text to be displayed */
376 SFG_Menu* SubMenu; /* Optional sub-menu tree */
377 GLboolean IsActive; /* Is the entry highlighted? */
378 int Width; /* Label's width in pixels */
382 * A window, making part of FreeGLUT windows hierarchy. Should be kept portable.
384 typedef struct tagSFG_Window SFG_Window;
388 int ID; /* Window's ID number */
390 SFG_Context Window; /* Window and OpenGL context */
391 SFG_WindowState State; /* The window state */
392 SFG_WindowCallbacks Callbacks; /* The window callbacks */
394 SFG_Menu* Menu[ FREEGLUT_MAX_MENUS ]; /* Menus appended to window */
395 GLboolean MenuActive[ FREEGLUT_MAX_MENUS ]; /* The menus activity flags */
397 SFG_Window* Parent; /* The parent to this window */
398 SFG_List Children; /* The subwindows d.l. list */
402 * This holds information about all the windows, menus etc.
404 typedef struct tagSFG_Structure SFG_Structure;
405 struct tagSFG_Structure
407 SFG_List Windows; /* The global windows list */
408 SFG_List Menus; /* The global menus list */
410 SFG_Window* Window; /* The currently active win. */
411 SFG_Menu* Menu; /* Same, but menu... */
413 SFG_Window* GameMode; /* The game mode window */
415 int WindowID; /* The new current window ID */
416 int MenuID; /* The new current menu ID */
420 * This structure is used for the enumeration purposes.
421 * You can easily extend it's functionalities by declaring
422 * a structure containing enumerator's contents and custom
423 * data, then casting it's pointer to (SFG_Enumerator *).
425 typedef struct tagSFG_Enumerator SFG_Enumerator;
426 struct tagSFG_Enumerator
428 GLboolean found; /* Used to terminate search */
429 void* data; /* Custom data pointer */
431 typedef void (* FGCBenumerator )( SFG_Window *, SFG_Enumerator * );
434 * The bitmap font structure
436 typedef struct tagSFG_Font SFG_Font;
439 char* Name; /* The source font name */
440 int Quantity; /* Number of chars in font */
441 int Height; /* Height of the characters */
442 const GLubyte** Characters; /* The characters mapping */
446 /* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */
449 * Freeglut display related stuff (initialized once per session)
451 extern SFG_Display fgDisplay;
454 * Freeglut internal structure
456 extern SFG_Structure fgStructure;
459 * The current freeglut settings
461 extern SFG_State fgState;
464 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
467 * A call to this function makes us sure that the Display and Structure
468 * subsystems have been properly initialized and are ready to be used
470 #define freeglut_assert_ready assert( fgState.Time.Set );
473 * Following definitions are somewhat similiar to GLib's,
474 * but do not generate any log messages:
476 #define freeglut_return_if_fail( expr ) if( !(expr) ) return;
477 #define freeglut_return_val_if_fail( expr, val ) if( !(expr) ) return( val );
480 * A call to those macros assures us that there is a current
481 * window and menu set, respectively:
483 #define freeglut_assert_window assert( fgStructure.Window != NULL );
484 #define freeglut_assert_menu assert( fgStructure.Menu != NULL );
487 * The initialize and deinitialize functions get called on glutInit()
488 * and glutMainLoop() end respectively. They should create/clean up
489 * everything inside of the freeglut
491 void fgInitialize( const char* displayName );
492 void fgDeinitialize( void );
495 * Those two functions are used to create/destroy the freeglut internal
496 * structures. This actually happens when calling glutInit() and when
497 * quitting the glutMainLoop() (which actually happens, when all windows
500 void fgCreateStructure( void );
501 void fgDestroyStructure( void );
504 * A helper function to check if a display mode is possible to use
506 #if TARGET_HOST_UNIX_X11
507 XVisualInfo* fgChooseVisual( void );
511 * The window procedure for Win32 events handling
513 #if TARGET_HOST_WIN32
514 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
515 gboolean fgSetupPixelFormat( SFG_Window* window, gboolean checkOnly );
519 * Window creation, opening, closing and destruction.
520 * Defined in freeglut_structure.c, freeglut_window.c.
522 SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, int x, int y, int w, int h, GLboolean gameMode );
523 void fgOpenWindow( SFG_Window* window, const char* title, int x, int y, int w, int h, GLboolean gameMode );
524 void fgCloseWindow( SFG_Window* window );
525 void fgDestroyWindow( SFG_Window* window, GLboolean needToClose );
528 * Menu creation and destruction. Defined in freeglut_structure.c
530 SFG_Menu* fgCreateMenu( FGCBmenu menuCallback );
531 void fgDestroyMenu( SFG_Menu* menu );
534 * Joystick device management functions, defined in freeglut_joystick.c
536 void fgJoystickInit( int ident );
537 void fgJoystickClose( void );
538 void fgJoystickPollWindow( SFG_Window* window );
541 * Helper function to enumerate through all registered windows
542 * and one to enumerate all of a window's subwindows...
544 * The GFunc callback for those functions will be defined as:
546 * void enumCallback( gpointer window, gpointer enumerator );
548 * where window is the enumerated (sub)window pointer (SFG_Window *),
549 * and userData is the a custom user-supplied pointer. Functions
550 * are defined and exported from freeglut_structure.c file.
552 void fgEnumWindows( FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
553 void fgEnumSubWindows( SFG_Window* window, FGCBenumerator enumCallback, SFG_Enumerator* enumerator );
556 * fgWindowByHandle returns a (SFG_Window *) value pointing to the
557 * first window in the queue matching the specified window handle.
558 * The function is defined in freeglut_structure.c file.
560 #if TARGET_HOST_UNIX_X11
561 SFG_Window* fgWindowByHandle( Window hWindow );
562 #elif TARGET_HOST_WIN32
564 SFG_Window* fgWindowByHandle( HWND hWindow );
568 * This function is similiar to the previous one, except it is
569 * looking for a specified (sub)window identifier. The function
570 * is defined in freeglut_structure.c file.
572 SFG_Window* fgWindowByID( int windowID );
575 * Looks up a menu given it's ID. This is easier that fgWindowByXXX
576 * as all menus are placed in a single doubly linked list...
578 SFG_Menu* fgMenuByID( int menuID );
581 * The menu activation and deactivation the code. This is the meat
582 * of the menu user interface handling code...
584 void fgActivateMenu( int button );
585 void fgDeactivateMenu( int button );
588 * This function gets called just before the buffers swap, so that
589 * freeglut can display the pull-down menus via OpenGL. The function
590 * is defined in freeglut_menu.c file.
592 void fgDisplayMenu( void );
595 * Display the mouse cursor using OpenGL calls. The function
596 * is defined in freeglut_cursor.c file.
598 void fgDisplayCursor( void );
601 * Elapsed time as per glutGet(GLUT_ELAPSED_TIME).
603 long fgElapsedTime( void );
608 void fgListInit(SFG_List *list);
609 void fgListAppend(SFG_List *list, SFG_Node *node);
610 void fgListRemove(SFG_List *list, SFG_Node *node);
611 int fgListLength(SFG_List *list);
614 * Error Messages functions
616 void fgError( const char *fmt, ... );
617 void fgWarning( const char *fmt, ... );
619 #endif /* FREEGLUT_INTERNAL_H */
621 /*** END OF FILE ***/