Fixed the 'ptr + len' problem in freeglut_misc.c:90
[freeglut] / src / freeglut_misc.c
1 /*
2  * freeglut_misc.c
3  *
4  * Functions that didn't fit anywhere else...
5  *
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
9  *
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:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
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.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #define  G_LOG_DOMAIN  "freeglut-misc"
33
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
36
37 /*
38  * TODO BEFORE THE STABLE RELEASE:
39  *
40  *  glutSetColor()     --
41  *  glutGetColor()     --
42  *  glutCopyColormap() --
43  *  glutSetKeyRepeat() -- this is evil and should be removed from API
44  */
45
46 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
47
48 /*
49  * This functions checks if an OpenGL extension is supported or not
50  */
51 int FGAPIENTRY glutExtensionSupported( const char* extension )
52 {
53   const char *extensions;
54   const char *ptr;
55   int len = strlen ( extension ) ;
56
57   /*
58    * Make sure there is a current window, and thus -- a current context available
59    */
60   freeglut_assert_ready;
61   freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 );
62
63   /*
64    * Note it is safe to query the extensions
65    */
66   extensions = glGetString(GL_EXTENSIONS);
67
68   freeglut_return_val_if_fail( extensions != NULL, 0 );
69
70   /*
71    * Check if the extension itself looks valid
72    */
73   if ( strchr ( extension, ' ' ) != NULL )
74     return( 0 );
75
76   /*
77    * Look for our extension
78    */
79   for (ptr = extensions; *ptr;)
80   {
81     /*
82      * Is it the current extension?
83      */
84     if ( strncmp ( extension, extensions, len ) == 0 )
85       return 1 ;
86
87     /*
88      * No, go find the next extension.  They are separated from each other by one or more blank spaces.
89      */
90     ptr = strchr ( ptr, ' ' ) ;
91
92     /*
93      * If we ran off the end of the "extensions" character string, we didn't find it.  Return failure.
94      */
95     if ( !ptr ) return 0 ;
96
97     while ( *ptr == ' ' )
98       ptr++ ;
99   }
100
101   return 0 ;
102 }
103
104 /*
105  * This function reports all the OpenGL errors that happened till now
106  */
107 void FGAPIENTRY glutReportErrors( void )
108 {
109     GLenum error = glGetError();
110
111     /*
112      * Keep reporting errors as long as there are any...
113      */
114     while( error != GL_NO_ERROR )
115     {
116         /*
117          * Print the current error
118          */
119 #       undef  G_LOG_DOMAIN
120 #       define G_LOG_DOMAIN ((gchar *) 0)
121
122         fgWarning( "GL error: %s", gluErrorString( error ) );
123
124 #       undef   G_LOG_DOMAIN
125 #       define  G_LOG_DOMAIN  "freeglut_misc.c"
126
127         /*
128          * Grab the next error value
129          */
130         error = glGetError();
131     };
132 }
133
134 /*
135  * Turns the ignore key auto repeat feature on and off
136  */
137 void FGAPIENTRY glutIgnoreKeyRepeat( int ignore )  /* DEPRECATED 11/4/02 - Do not use */
138 {
139     /*
140      * This is simple and not damaging...
141      */
142     fgState.IgnoreKeyRepeat = ignore ? TRUE : FALSE;
143 }
144
145 /*
146  * Hints the window system whether to generate key auto repeat, or not. This is evil.
147  */
148 void FGAPIENTRY glutSetKeyRepeat( int repeatMode )
149 {
150 #if TARGET_HOST_UNIX_X11
151
152     freeglut_assert_ready;
153
154     /*
155      * This is really evil, but let's have this done.
156      */
157     switch( repeatMode )
158     {
159     case GLUT_KEY_REPEAT_OFF:   XAutoRepeatOff( fgDisplay.Display ); break;
160     case GLUT_KEY_REPEAT_ON:    XAutoRepeatOn( fgDisplay.Display );  break;
161     case GLUT_KEY_REPEAT_DEFAULT:
162         {
163             XKeyboardState keyboardState;
164
165             /*
166              * Query the current keyboard state
167              */
168             XGetKeyboardControl( fgDisplay.Display, &keyboardState );
169
170             /*
171              * Set the auto key repeat basing on the global settings
172              */
173             glutSetKeyRepeat(
174                 keyboardState.global_auto_repeat == AutoRepeatModeOn ?
175                 GLUT_KEY_REPEAT_ON : GLUT_KEY_REPEAT_OFF
176             );
177         }
178         break;
179
180     default:
181         /*
182          * Whoops, this was not expected at all
183          */
184         break;
185     }
186
187 #endif
188 }
189
190 /*
191  * Forces the joystick callback to be executed
192  */
193 void FGAPIENTRY glutForceJoystickFunc( void )
194 {
195     freeglut_assert_ready;
196
197     /*
198      * Is there a current window selected?
199      */
200     freeglut_return_if_fail( fgStructure.Window != NULL );
201
202     /*
203      * Check if there is a joystick callback hooked to the current window
204      */
205     freeglut_return_if_fail( fgStructure.Window->Callbacks.Joystick != NULL );
206
207     /*
208      * Poll the joystick now, using the current window's joystick callback
209      */
210     fgJoystickPollWindow( fgStructure.Window );
211 }
212
213 /*
214  *
215  */
216 void FGAPIENTRY glutSetColor( int nColor, GLfloat red, GLfloat green, GLfloat blue )
217 {
218     /*
219      *
220      */
221 }
222
223 /*
224  *
225  */
226 GLfloat FGAPIENTRY glutGetColor( int color, int component )
227 {
228     /*
229      *
230      */
231     return( 0.0f );
232 }
233
234 /*
235  *
236  */
237 void FGAPIENTRY glutCopyColormap( int window )
238 {
239     /*
240      *
241      */
242 }
243
244 /*** END OF FILE ***/