9d44470b7b428cfdcc237524279a9d51c16cdcf1
[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, *start;
54   const int len = strlen( extension ) ;
55
56   /*
57    * Make sure there is a current window, and thus -- a current context available
58    */
59   freeglut_assert_ready;
60   freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 );
61
62   /*
63    * Check if the extension itself looks valid (contains no spaces)
64    */
65   if (strchr(extension, ' '))
66     return 0;
67
68   /*
69    * Note it is safe to query the extensions
70    */
71   start = extensions = (const char *) glGetString(GL_EXTENSIONS);
72
73   /* XXX consider printing a warning to stderr that there's no current
74    * rendering context.
75    */
76   freeglut_return_val_if_fail( extensions != NULL, 0 );
77
78   while (1) {
79      const char *p = strstr(extensions, extension);
80      if (!p)
81         return 0;  /* not found */
82      /* check that the match isn't a super string */
83      if ((p == start || p[-1] == ' ') && (p[len] == ' ' || p[len] == 0))
84         return 1;
85      /* skip the false match and continue */
86      extensions = p + len;
87   }
88
89   return 0 ;
90 }
91
92 /*
93  * This function reports all the OpenGL errors that happened till now
94  */
95 void FGAPIENTRY glutReportErrors( void )
96 {
97     GLenum error = glGetError();
98
99     /*
100      * Keep reporting errors as long as there are any...
101      */
102     while( error != GL_NO_ERROR )
103     {
104         /*
105          * Print the current error
106          */
107 #       undef  G_LOG_DOMAIN
108 #       define G_LOG_DOMAIN ((gchar *) 0)
109
110         fgWarning( "GL error: %s", gluErrorString( error ) );
111
112 #       undef   G_LOG_DOMAIN
113 #       define  G_LOG_DOMAIN  "freeglut_misc.c"
114
115         /*
116          * Grab the next error value
117          */
118         error = glGetError();
119     };
120 }
121
122 /*
123  * Turns the ignore key auto repeat feature on and off
124  */
125 void FGAPIENTRY glutIgnoreKeyRepeat( int ignore )  /* DEPRECATED 11/4/02 - Do not use */
126 {
127     /*
128      * This is simple and not damaging...
129      */
130     fgState.IgnoreKeyRepeat = ignore ? TRUE : FALSE;
131 }
132
133 /*
134  * Hints the window system whether to generate key auto repeat, or not. This is evil.
135  */
136 void FGAPIENTRY glutSetKeyRepeat( int repeatMode )
137 {
138 #if TARGET_HOST_UNIX_X11
139
140     freeglut_assert_ready;
141
142     /*
143      * This is really evil, but let's have this done.
144      */
145     switch( repeatMode )
146     {
147     case GLUT_KEY_REPEAT_OFF:   XAutoRepeatOff( fgDisplay.Display ); break;
148     case GLUT_KEY_REPEAT_ON:    XAutoRepeatOn( fgDisplay.Display );  break;
149     case GLUT_KEY_REPEAT_DEFAULT:
150         {
151             XKeyboardState keyboardState;
152
153             /*
154              * Query the current keyboard state
155              */
156             XGetKeyboardControl( fgDisplay.Display, &keyboardState );
157
158             /*
159              * Set the auto key repeat basing on the global settings
160              */
161             glutSetKeyRepeat(
162                 keyboardState.global_auto_repeat == AutoRepeatModeOn ?
163                 GLUT_KEY_REPEAT_ON : GLUT_KEY_REPEAT_OFF
164             );
165         }
166         break;
167
168     default:
169         /*
170          * Whoops, this was not expected at all
171          */
172         break;
173     }
174
175 #endif
176 }
177
178 /*
179  * Forces the joystick callback to be executed
180  */
181 void FGAPIENTRY glutForceJoystickFunc( void )
182 {
183     freeglut_assert_ready;
184
185     /*
186      * Is there a current window selected?
187      */
188     freeglut_return_if_fail( fgStructure.Window != NULL );
189
190     /*
191      * Check if there is a joystick callback hooked to the current window
192      */
193     freeglut_return_if_fail( fgStructure.Window->Callbacks.Joystick != NULL );
194
195     /*
196      * Poll the joystick now, using the current window's joystick callback
197      */
198     fgJoystickPollWindow( fgStructure.Window );
199 }
200
201 /*
202  *
203  */
204 void FGAPIENTRY glutSetColor( int nColor, GLfloat red, GLfloat green, GLfloat blue )
205 {
206     /*
207      *
208      */
209 }
210
211 /*
212  *
213  */
214 GLfloat FGAPIENTRY glutGetColor( int color, int component )
215 {
216     /*
217      *
218      */
219     return( 0.0f );
220 }
221
222 /*
223  *
224  */
225 void FGAPIENTRY glutCopyColormap( int window )
226 {
227     /*
228      *
229      */
230 }
231
232 /*** END OF FILE ***/