5891f4ca89abce8771e391c5f3ddadfda2191c76
[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  * XXX Wouldn't this be simpler and clearer if we used strtok()?
52  */
53 int FGAPIENTRY glutExtensionSupported( const char* extension )
54 {
55   const char *extensions, *start;
56   const int len = strlen( extension ) ;
57
58   /*
59    * Make sure there is a current window, and thus a current context available
60    */
61   freeglut_assert_ready;
62   freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 );
63
64   if (strchr(extension, ' '))
65     return 0;
66   start = extensions = (const char *) glGetString(GL_EXTENSIONS);
67
68   /* XXX consider printing a warning to stderr that there's no current
69    * rendering context.
70    */
71   freeglut_return_val_if_fail( extensions != NULL, 0 );
72
73   while (1) {
74      const char *p = strstr(extensions, extension);
75      if (!p)
76         return 0;  /* not found */
77      /* check that the match isn't a super string */
78      if ((p == start || p[-1] == ' ') && (p[len] == ' ' || p[len] == 0))
79         return 1;
80      /* skip the false match and continue */
81      extensions = p + len;
82   }
83
84   return 0 ;
85 }
86
87 /*
88  * This function reports all the OpenGL errors that happened till now
89  */
90 void FGAPIENTRY glutReportErrors( void )
91 {
92     GLenum error;
93     while( ( error = glGetError() ) != GL_NO_ERROR )
94 #       undef  G_LOG_DOMAIN
95 #       define G_LOG_DOMAIN ((gchar *) 0)
96
97         fgWarning( "GL error: %s", gluErrorString( error ) );
98
99 #       undef   G_LOG_DOMAIN
100 #       define  G_LOG_DOMAIN  "freeglut_misc.c"
101 }
102
103 /*
104  * Turns the ignore key auto repeat feature on and off
105  *
106  * DEPRECATED 11/4/02 - Do not use
107  */
108 void FGAPIENTRY glutIgnoreKeyRepeat( int ignore )
109 {
110     fgState.IgnoreKeyRepeat = ignore ? TRUE : FALSE;
111 }
112
113 /*
114  * Hints the window system whether to generate key auto repeat, or not.
115  * This is evil.
116  *
117  * XXX Is this also deprecated as of 20021104?
118  */
119 void FGAPIENTRY glutSetKeyRepeat( int repeatMode )
120 {
121 #if TARGET_HOST_UNIX_X11
122
123     freeglut_assert_ready;
124
125     switch( repeatMode )
126     {
127     case GLUT_KEY_REPEAT_OFF:   XAutoRepeatOff( fgDisplay.Display ); break;
128     case GLUT_KEY_REPEAT_ON:    XAutoRepeatOn( fgDisplay.Display );  break;
129     case GLUT_KEY_REPEAT_DEFAULT:
130         {
131             XKeyboardState keyboardState;
132
133             XGetKeyboardControl( fgDisplay.Display, &keyboardState );
134             glutSetKeyRepeat(
135                 keyboardState.global_auto_repeat == AutoRepeatModeOn ?
136                 GLUT_KEY_REPEAT_ON : GLUT_KEY_REPEAT_OFF
137             );
138         }
139         break;
140
141     default:
142         fgError ("Invalid glutSetKeyRepeat mode: %d", repeatMode);
143         break;
144     }
145
146 #endif
147 }
148
149 /*
150  * Forces the joystick callback to be executed
151  */
152 void FGAPIENTRY glutForceJoystickFunc( void )
153 {
154     freeglut_assert_ready;
155     freeglut_return_if_fail( fgStructure.Window != NULL );
156     freeglut_return_if_fail( fgStructure.Window->Callbacks.Joystick != NULL );
157     fgJoystickPollWindow( fgStructure.Window );
158 }
159
160 /*
161  *
162  */
163 void FGAPIENTRY glutSetColor( int nColor, GLfloat red, GLfloat green, GLfloat blue )
164 {
165     /*
166      *
167      */
168 }
169
170 /*
171  *
172  */
173 GLfloat FGAPIENTRY glutGetColor( int color, int component )
174 {
175     /*
176      *
177      */
178     return( 0.0f );
179 }
180
181 /*
182  *
183  */
184 void FGAPIENTRY glutCopyColormap( int window )
185 {
186     /*
187      *
188      */
189 }
190
191 /*** END OF FILE ***/