4 * Functions that didn't fit anywhere else...
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 9 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.
32 #define G_LOG_DOMAIN "freeglut-misc"
34 #include "../include/GL/freeglut.h"
35 #include "../include/GL/freeglut_internal.h"
38 * TODO BEFORE THE STABLE RELEASE:
42 * glutCopyColormap() --
43 * glutSetKeyRepeat() -- this is evil and should be removed from API
46 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
49 * This functions checks if an OpenGL extension is supported or not
51 int FGAPIENTRY glutExtensionSupported( const char* extension )
54 * Grab the current context's OpenGL extensions
55 * and create a new GLib lexical analyzer...
57 gchar *glExtensions = (gchar *) glGetString( GL_EXTENSIONS );
58 GScanner* scanner = g_scanner_new( NULL );
62 * Make sure there is a current window, and thus -- a current context available
64 freeglut_assert_ready; freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 );
67 * Fail if there is no extension, extensions or scanner available
69 freeglut_return_val_if_fail( (scanner != NULL) && (strlen( extension ) > 0)
70 && (strlen( glExtensions ) > 0), 0 );
73 * Check if the extension itself looks valid
75 for( i=0; i<(gint) strlen( extension ); i++ )
76 if( extension[ i ] == ' ' )
80 * Set the scanner's input name (for debugging)
82 scanner->input_name = "glutExtensionSupported()";
85 * Start the lexical analysis of the extensions string
87 g_scanner_input_text( scanner, glExtensions, strlen( glExtensions ) );
90 * While there are any more tokens to be checked...
92 while( !g_scanner_eof( scanner ) )
95 * Actually we're expecting only string tokens
97 GTokenType tokenType = g_scanner_get_next_token( scanner );
100 * We are looking for identifiers
102 if( tokenType == G_TOKEN_IDENTIFIER )
105 * Compare the token and the extension string
107 if( strcmp( scanner->value.v_identifier, extension ) == 0 )
110 * OKi, we have found the extension string we've been looking for
112 g_scanner_destroy( scanner );
119 * Well, looks like we have failed to find the extension string
121 g_scanner_destroy( scanner );
126 * This function reports all the errors that happened till now
128 void FGAPIENTRY glutReportErrors( void )
130 GLenum error = glGetError();
133 * Keep reporting errors as long as there are any...
135 while( error != GL_NO_ERROR )
138 * Print the current error
141 # define G_LOG_DOMAIN ((gchar *) 0)
143 g_warning( "GL error: %s", gluErrorString( error ) );
146 # define G_LOG_DOMAIN "freeglut_misc.c"
149 * Grab the next error value
151 error = glGetError();
156 * Turns the ignore key auto repeat feature on and off
158 void FGAPIENTRY glutIgnoreKeyRepeat( int ignore )
161 * This is simple and not demanging...
163 fgState.IgnoreKeyRepeat = ignore ? TRUE : FALSE;
167 * Hints the window system whether to generate key auto repeat, or not. This is evil.
169 void FGAPIENTRY glutSetKeyRepeat( int repeatMode )
171 #if TARGET_HOST_UNIX_X11
173 freeglut_assert_ready;
176 * This is really evil, but let's have this done.
180 case GLUT_KEY_REPEAT_OFF: XAutoRepeatOff( fgDisplay.Display ); break;
181 case GLUT_KEY_REPEAT_ON: XAutoRepeatOn( fgDisplay.Display ); break;
182 case GLUT_KEY_REPEAT_DEFAULT:
184 XKeyboardState keyboardState;
187 * Query the current keyboard state
189 XGetKeyboardControl( fgDisplay.Display, &keyboardState );
192 * Set the auto key repeat basing on the global settings
195 keyboardState.global_auto_repeat == AutoRepeatModeOn ?
196 GLUT_KEY_REPEAT_ON : GLUT_KEY_REPEAT_OFF
203 * Whoops, this was not expected at all
205 g_assert_not_reached();
212 * Forces the joystick callback to be executed
214 void FGAPIENTRY glutForceJoystickFunc( void )
216 freeglut_assert_ready;
219 * Is there a current window selected?
221 freeglut_return_if_fail( fgStructure.Window != NULL );
224 * Check if there is a joystick callback hooked to the current window
226 freeglut_return_if_fail( fgStructure.Window->Callbacks.Joystick != NULL );
229 * Poll the joystick now, using the current window's joystick callback
231 fgJoystickPollWindow( fgStructure.Window );
237 void FGAPIENTRY glutSetColor( int nColor, GLfloat red, GLfloat green, GLfloat blue )
247 GLfloat FGAPIENTRY glutGetColor( int color, int component )
258 void FGAPIENTRY glutCopyColormap( int window )
265 /*** END OF FILE ***/