4 * Freeglut state query methods.
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 16 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 #include <GL/freeglut.h>
29 #include "fg_internal.h"
32 * TODO BEFORE THE STABLE RELEASE:
34 * glutGet() -- X11 tests passed, but check if all enums
35 * handled (what about Win32?)
36 * glutDeviceGet() -- X11 tests passed, but check if all enums
37 * handled (what about Win32?)
38 * glutGetModifiers() -- OK, but could also remove the limitation
39 * glutLayerGet() -- what about GLUT_NORMAL_DAMAGED?
41 * The fail-on-call policy will help adding the most needed things imho.
44 extern int fgPlatformGlutGet ( GLenum eWhat );
45 extern int fgPlatformGlutDeviceGet ( GLenum eWhat );
46 extern int *fgPlatformGlutGetModeValues(GLenum eWhat, int *size);
47 extern SFG_Font* fghFontByID( void* font );
50 /* -- LOCAL DEFINITIONS ---------------------------------------------------- */
52 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
55 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
58 * General settings assignment method
60 void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
62 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetOption" );
66 case GLUT_INIT_WINDOW_X:
67 fgState.Position.X = (GLint)value;
70 case GLUT_INIT_WINDOW_Y:
71 fgState.Position.Y = (GLint)value;
74 case GLUT_INIT_WINDOW_WIDTH:
75 fgState.Size.X = (GLint)value;
78 case GLUT_INIT_WINDOW_HEIGHT:
79 fgState.Size.Y = (GLint)value;
82 case GLUT_INIT_DISPLAY_MODE:
83 fgState.DisplayMode = (unsigned int)value;
86 case GLUT_ACTION_ON_WINDOW_CLOSE:
87 fgState.ActionOnWindowClose = value;
90 case GLUT_RENDERING_CONTEXT:
91 fgState.UseCurrentContext =
92 ( value == GLUT_USE_CURRENT_CONTEXT ) ? GL_TRUE : GL_FALSE;
95 case GLUT_DIRECT_RENDERING:
96 fgState.DirectContext = value;
99 case GLUT_WINDOW_CURSOR:
100 if( fgStructure.CurrentWindow != NULL )
101 fgStructure.CurrentWindow->State.Cursor = value;
105 fgState.AuxiliaryBufferNumber = value;
108 case GLUT_MULTISAMPLE:
109 fgState.SampleNumber = value;
112 case GLUT_SKIP_STALE_MOTION_EVENTS:
113 fgState.SkipStaleMotion = value;
116 case GLUT_GEOMETRY_VISUALIZE_NORMALS:
117 if( fgStructure.CurrentWindow != NULL )
118 fgStructure.CurrentWindow->State.VisualizeNormals = value;
123 void* fontID = (void*)value;
125 font = fghFontByID( fontID );
127 fgWarning("glutSetOption(GLUT_MENU_FONT,...): bitmap font 0x%08x not found. Make sure you're not passing a stroke font. Ignoring...\n",fontID);
129 fgState.MenuFont = fontID;
134 fgWarning( "glutSetOption(): missing enum handle %d", eWhat );
140 * General settings query method
142 int FGAPIENTRY glutGet( GLenum eWhat )
146 case GLUT_INIT_STATE:
147 return fgState.Initialised;
149 /* Although internally the time store is 64bits wide, the return value
150 * here still wraps every 49.7 days. Integer overflows cancel however
151 * when subtracting an initial start time, unless the total time exceeds
152 * 32-bit, so you can still work with this.
153 * XXX: a glutGet64 to return the time might be an idea...
155 case GLUT_ELAPSED_TIME:
156 return (int) fgElapsedTime();
159 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGet" );
163 /* Following values are stored in fgState and fgDisplay global structures */
164 case GLUT_SCREEN_WIDTH: return fgDisplay.ScreenWidth ;
165 case GLUT_SCREEN_HEIGHT: return fgDisplay.ScreenHeight ;
166 case GLUT_SCREEN_WIDTH_MM: return fgDisplay.ScreenWidthMM ;
167 case GLUT_SCREEN_HEIGHT_MM: return fgDisplay.ScreenHeightMM;
168 case GLUT_INIT_WINDOW_X: return fgState.Position.Use ?
169 fgState.Position.X : -1 ;
170 case GLUT_INIT_WINDOW_Y: return fgState.Position.Use ?
171 fgState.Position.Y : -1 ;
172 case GLUT_INIT_WINDOW_WIDTH: return fgState.Size.Use ?
173 fgState.Size.X : -1 ;
174 case GLUT_INIT_WINDOW_HEIGHT: return fgState.Size.Use ?
175 fgState.Size.Y : -1 ;
176 case GLUT_INIT_DISPLAY_MODE: return fgState.DisplayMode ;
177 case GLUT_INIT_MAJOR_VERSION: return fgState.MajorVersion ;
178 case GLUT_INIT_MINOR_VERSION: return fgState.MinorVersion ;
179 case GLUT_INIT_FLAGS: return fgState.ContextFlags ;
180 case GLUT_INIT_PROFILE: return fgState.ContextProfile ;
182 /* The window structure queries */
183 case GLUT_WINDOW_PARENT:
184 if( fgStructure.CurrentWindow == NULL ) return 0;
185 if( fgStructure.CurrentWindow->Parent == NULL ) return 0;
186 return fgStructure.CurrentWindow->Parent->ID;
188 case GLUT_WINDOW_NUM_CHILDREN:
189 if( fgStructure.CurrentWindow == NULL )
191 return fgListLength( &fgStructure.CurrentWindow->Children );
193 case GLUT_WINDOW_CURSOR:
194 if( fgStructure.CurrentWindow == NULL )
196 return fgStructure.CurrentWindow->State.Cursor;
198 case GLUT_MENU_NUM_ITEMS:
199 if( fgStructure.CurrentMenu == NULL )
201 return fgListLength( &fgStructure.CurrentMenu->Entries );
203 case GLUT_ACTION_ON_WINDOW_CLOSE:
204 return fgState.ActionOnWindowClose;
207 return VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH;
209 case GLUT_RENDERING_CONTEXT:
210 return fgState.UseCurrentContext ? GLUT_USE_CURRENT_CONTEXT
211 : GLUT_CREATE_NEW_CONTEXT;
213 case GLUT_DIRECT_RENDERING:
214 return fgState.DirectContext;
216 case GLUT_FULL_SCREEN:
217 return fgStructure.CurrentWindow->State.IsFullscreen;
220 return fgState.AuxiliaryBufferNumber;
222 case GLUT_MULTISAMPLE:
223 return fgState.SampleNumber;
225 case GLUT_SKIP_STALE_MOTION_EVENTS:
226 return fgState.SkipStaleMotion;
228 case GLUT_GEOMETRY_VISUALIZE_NORMALS:
229 if( fgStructure.CurrentWindow == NULL )
231 return fgStructure.CurrentWindow->State.VisualizeNormals;
234 return fgPlatformGlutGet ( eWhat );
241 * Returns various device information.
243 int FGAPIENTRY glutDeviceGet( GLenum eWhat )
245 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDeviceGet" );
247 /* XXX WARNING: we are mostly lying in this function. */
250 case GLUT_HAS_JOYSTICK:
251 return fgJoystickDetect ();
253 case GLUT_OWNS_JOYSTICK:
254 return fgState.JoysticksInitialised;
256 case GLUT_JOYSTICK_POLL_RATE:
257 return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.JoystickPollRate : 0;
259 /* XXX The following two are only for Joystick 0 but this is an improvement */
260 case GLUT_JOYSTICK_BUTTONS:
261 return glutJoystickGetNumButtons ( 0 );
263 case GLUT_JOYSTICK_AXES:
264 return glutJoystickGetNumAxes ( 0 );
266 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
267 return fgInputDeviceDetect ();
270 if ( fgState.InputDevsInitialised ) return 8;
273 case GLUT_NUM_BUTTON_BOX_BUTTONS:
276 case GLUT_HAS_SPACEBALL:
277 return fgHasSpaceball();
279 case GLUT_HAS_TABLET:
282 case GLUT_NUM_SPACEBALL_BUTTONS:
283 return fgSpaceballNumButtons();
285 case GLUT_NUM_TABLET_BUTTONS:
288 case GLUT_DEVICE_IGNORE_KEY_REPEAT:
289 return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.IgnoreKeyRepeat : 0;
291 case GLUT_DEVICE_KEY_REPEAT:
292 return fgState.KeyRepeat;
295 return fgPlatformGlutDeviceGet ( eWhat );
298 /* And now -- the failure. */
303 * This should return the current state of ALT, SHIFT and CTRL keys.
305 int FGAPIENTRY glutGetModifiers( void )
307 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetModifiers" );
308 if( fgState.Modifiers == INVALID_MODIFIERS )
310 fgWarning( "glutGetModifiers() called outside an input callback" );
314 return fgState.Modifiers;
318 * Return the state of the GLUT API overlay subsystem. A misery ;-)
320 int FGAPIENTRY glutLayerGet( GLenum eWhat )
322 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLayerGet" );
325 * This is easy as layers are not implemented and
326 * overlay support is not planned. E.g. on Windows,
327 * overlay requests in PFDs are ignored
328 * (see iLayerType at http://msdn.microsoft.com/en-us/library/dd368826(v=vs.85).aspx)
333 case GLUT_OVERLAY_POSSIBLE:
336 case GLUT_LAYER_IN_USE:
339 case GLUT_HAS_OVERLAY:
342 case GLUT_TRANSPARENT_INDEX:
344 * Return just anything, which is always defined as zero
350 case GLUT_NORMAL_DAMAGED:
351 /* XXX Actually I do not know. Maybe. */
354 case GLUT_OVERLAY_DAMAGED:
358 fgWarning( "glutLayerGet(): missing enum handle %d", eWhat );
362 /* And fail. That's good. Programs do love failing. */
366 int * FGAPIENTRY glutGetModeValues(GLenum eWhat, int *size)
370 FREEGLUT_EXIT_IF_NOT_INITIALISED("glutGetModeValues");
373 array = fgPlatformGlutGetModeValues ( eWhat, size );
378 /*** END OF FILE ***/