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);
49 /* -- LOCAL DEFINITIONS ---------------------------------------------------- */
51 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
54 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
57 * General settings assignment method
59 void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
61 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetOption" );
64 * XXX In chronological code add order. (WHY in that order?)
68 case GLUT_INIT_WINDOW_X:
69 fgState.Position.X = (GLint)value;
72 case GLUT_INIT_WINDOW_Y:
73 fgState.Position.Y = (GLint)value;
76 case GLUT_INIT_WINDOW_WIDTH:
77 fgState.Size.X = (GLint)value;
80 case GLUT_INIT_WINDOW_HEIGHT:
81 fgState.Size.Y = (GLint)value;
84 case GLUT_INIT_DISPLAY_MODE:
85 fgState.DisplayMode = (unsigned int)value;
88 case GLUT_ACTION_ON_WINDOW_CLOSE:
89 fgState.ActionOnWindowClose = value;
92 case GLUT_RENDERING_CONTEXT:
93 fgState.UseCurrentContext =
94 ( value == GLUT_USE_CURRENT_CONTEXT ) ? GL_TRUE : GL_FALSE;
97 case GLUT_DIRECT_RENDERING:
98 fgState.DirectContext = value;
101 case GLUT_WINDOW_CURSOR:
102 if( fgStructure.CurrentWindow != NULL )
103 fgStructure.CurrentWindow->State.Cursor = value;
107 fgState.AuxiliaryBufferNumber = value;
110 case GLUT_MULTISAMPLE:
111 fgState.SampleNumber = value;
115 fgWarning( "glutSetOption(): missing enum handle %d", eWhat );
121 * General settings query method
123 int FGAPIENTRY glutGet( GLenum eWhat )
127 case GLUT_INIT_STATE:
128 return fgState.Initialised;
130 case GLUT_ELAPSED_TIME:
131 return (int) fgElapsedTime();
134 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGet" );
136 /* XXX In chronological code add order. (WHY in that order?) */
139 /* Following values are stored in fgState and fgDisplay global structures */
140 case GLUT_SCREEN_WIDTH: return fgDisplay.ScreenWidth ;
141 case GLUT_SCREEN_HEIGHT: return fgDisplay.ScreenHeight ;
142 case GLUT_SCREEN_WIDTH_MM: return fgDisplay.ScreenWidthMM ;
143 case GLUT_SCREEN_HEIGHT_MM: return fgDisplay.ScreenHeightMM;
144 case GLUT_INIT_WINDOW_X: return fgState.Position.Use ?
145 fgState.Position.X : -1 ;
146 case GLUT_INIT_WINDOW_Y: return fgState.Position.Use ?
147 fgState.Position.Y : -1 ;
148 case GLUT_INIT_WINDOW_WIDTH: return fgState.Size.Use ?
149 fgState.Size.X : -1 ;
150 case GLUT_INIT_WINDOW_HEIGHT: return fgState.Size.Use ?
151 fgState.Size.Y : -1 ;
152 case GLUT_INIT_DISPLAY_MODE: return fgState.DisplayMode ;
153 case GLUT_INIT_MAJOR_VERSION: return fgState.MajorVersion ;
154 case GLUT_INIT_MINOR_VERSION: return fgState.MinorVersion ;
155 case GLUT_INIT_FLAGS: return fgState.ContextFlags ;
156 case GLUT_INIT_PROFILE: return fgState.ContextProfile ;
158 /* The window structure queries */
159 case GLUT_WINDOW_PARENT:
160 if( fgStructure.CurrentWindow == NULL ) return 0;
161 if( fgStructure.CurrentWindow->Parent == NULL ) return 0;
162 return fgStructure.CurrentWindow->Parent->ID;
164 case GLUT_WINDOW_NUM_CHILDREN:
165 if( fgStructure.CurrentWindow == NULL )
167 return fgListLength( &fgStructure.CurrentWindow->Children );
169 case GLUT_WINDOW_CURSOR:
170 if( fgStructure.CurrentWindow == NULL )
172 return fgStructure.CurrentWindow->State.Cursor;
174 case GLUT_MENU_NUM_ITEMS:
175 if( fgStructure.CurrentMenu == NULL )
177 return fgListLength( &fgStructure.CurrentMenu->Entries );
179 case GLUT_ACTION_ON_WINDOW_CLOSE:
180 return fgState.ActionOnWindowClose;
183 return VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH;
185 case GLUT_RENDERING_CONTEXT:
186 return fgState.UseCurrentContext ? GLUT_USE_CURRENT_CONTEXT
187 : GLUT_CREATE_NEW_CONTEXT;
189 case GLUT_DIRECT_RENDERING:
190 return fgState.DirectContext;
192 case GLUT_FULL_SCREEN:
193 return fgStructure.CurrentWindow->State.IsFullscreen;
196 return fgState.AuxiliaryBufferNumber;
198 case GLUT_MULTISAMPLE:
199 return fgState.SampleNumber;
202 return fgPlatformGlutGet ( eWhat );
209 * Returns various device information.
211 int FGAPIENTRY glutDeviceGet( GLenum eWhat )
213 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDeviceGet" );
215 /* XXX WARNING: we are mostly lying in this function. */
218 case GLUT_HAS_JOYSTICK:
219 return fgJoystickDetect ();
221 case GLUT_OWNS_JOYSTICK:
222 return fgState.JoysticksInitialised;
224 case GLUT_JOYSTICK_POLL_RATE:
225 return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.JoystickPollRate : 0;
227 /* XXX The following two are only for Joystick 0 but this is an improvement */
228 case GLUT_JOYSTICK_BUTTONS:
229 return glutJoystickGetNumButtons ( 0 );
231 case GLUT_JOYSTICK_AXES:
232 return glutJoystickGetNumAxes ( 0 );
234 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
235 return fgInputDeviceDetect ();
238 if ( fgState.InputDevsInitialised ) return 8;
241 case GLUT_NUM_BUTTON_BOX_BUTTONS:
244 case GLUT_HAS_SPACEBALL:
245 return fgHasSpaceball();
247 case GLUT_HAS_TABLET:
250 case GLUT_NUM_SPACEBALL_BUTTONS:
251 return fgSpaceballNumButtons();
253 case GLUT_NUM_TABLET_BUTTONS:
256 case GLUT_DEVICE_IGNORE_KEY_REPEAT:
257 return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.IgnoreKeyRepeat : 0;
259 case GLUT_DEVICE_KEY_REPEAT:
260 return fgState.KeyRepeat;
263 return fgPlatformGlutDeviceGet ( eWhat );
266 /* And now -- the failure. */
271 * This should return the current state of ALT, SHIFT and CTRL keys.
273 int FGAPIENTRY glutGetModifiers( void )
275 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetModifiers" );
276 if( fgState.Modifiers == INVALID_MODIFIERS )
278 fgWarning( "glutGetModifiers() called outside an input callback" );
282 return fgState.Modifiers;
286 * Return the state of the GLUT API overlay subsystem. A misery ;-)
288 int FGAPIENTRY glutLayerGet( GLenum eWhat )
290 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLayerGet" );
293 * This is easy as layers are not implemented and
294 * overlay support is not planned. E.g. on Windows,
295 * overlay requests in PFDs are ignored
296 * (see iLayerType at http://msdn.microsoft.com/en-us/library/dd368826(v=vs.85).aspx)
301 case GLUT_OVERLAY_POSSIBLE:
304 case GLUT_LAYER_IN_USE:
307 case GLUT_HAS_OVERLAY:
310 case GLUT_TRANSPARENT_INDEX:
312 * Return just anything, which is always defined as zero
318 case GLUT_NORMAL_DAMAGED:
319 /* XXX Actually I do not know. Maybe. */
322 case GLUT_OVERLAY_DAMAGED:
326 fgWarning( "glutLayerGet(): missing enum handle %d", eWhat );
330 /* And fail. That's good. Programs do love failing. */
334 int * FGAPIENTRY glutGetModeValues(GLenum eWhat, int *size)
338 FREEGLUT_EXIT_IF_NOT_INITIALISED("glutGetModeValues");
341 array = fgPlatformGlutGetModeValues ( eWhat, size );
346 /*** END OF FILE ***/