1 | /*!
|
---|
2 | \file og_misc.c
|
---|
3 | \brief Miscellaneous functions
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Portions copyright (C) 2004, the OpenGLUT project contributors.
|
---|
8 | * OpenGLUT branched from freeglut in February, 2004.
|
---|
9 | *
|
---|
10 | * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
|
---|
11 | * Written by Pawel W. Olszta, <olszta@sourceforge.net>
|
---|
12 | * Creation date: Thu Dec 9 1999
|
---|
13 | *
|
---|
14 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
15 | * copy of this software and associated documentation files (the "Software"),
|
---|
16 | * to deal in the Software without restriction, including without limitation
|
---|
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
18 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
19 | * Software is furnished to do so, subject to the following conditions:
|
---|
20 | *
|
---|
21 | * The above copyright notice and this permission notice shall be included
|
---|
22 | * in all copies or substantial portions of the Software.
|
---|
23 | *
|
---|
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
---|
25 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
27 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
---|
28 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
---|
29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
30 | */
|
---|
31 |
|
---|
32 | #ifdef HAVE_CONFIG_H
|
---|
33 | #include "config.h"
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #include <GL/openglut.h>
|
---|
37 | #include "og_internal.h"
|
---|
38 |
|
---|
39 | /* -- INTERNAL FUNCTIONS --------------------------------------------------- */
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * Similar to the de facto strdup(), but since strdup() is not
|
---|
43 | * actually a standard C function, we provide our own.
|
---|
44 | */
|
---|
45 | char *ogStrDup( const char *str )
|
---|
46 | {
|
---|
47 | char *ret = malloc( strlen( str ) + 1 );
|
---|
48 | char *dst = ret;
|
---|
49 | if( ret )
|
---|
50 | while( *dst++ = *str++ )
|
---|
51 | ;
|
---|
52 | return ret;
|
---|
53 | }
|
---|
54 |
|
---|
55 | /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
|
---|
56 |
|
---|
57 | /*!
|
---|
58 | \fn
|
---|
59 | \brief Determine if an OpenGL extension is available.
|
---|
60 | \ingroup opengl
|
---|
61 | \param extension A string-name of an extension.
|
---|
62 |
|
---|
63 | Returns 0 if OpenGLUT cannot determine that the requested
|
---|
64 | extension is definitely present. Only checks extensions
|
---|
65 | from glGetString().
|
---|
66 |
|
---|
67 | \todo Wouldn't this be simpler and clearer if we used strtok()?
|
---|
68 | \todo Consider an ogWarning() if there is no current rendering
|
---|
69 | context.
|
---|
70 | \todo This is an ugly bit of code with 3 return statements,
|
---|
71 | one of which is never reached.
|
---|
72 | \see glGetString()
|
---|
73 | */
|
---|
74 | int OGAPIENTRY glutExtensionSupported( const char *extension )
|
---|
75 | {
|
---|
76 | const char *extensions, *start;
|
---|
77 | const int len = strlen( extension );
|
---|
78 |
|
---|
79 | freeglut_assert_ready;
|
---|
80 | /* Check for current window and thus a current context */
|
---|
81 | if( !ogStructure.Window )
|
---|
82 | return 0;
|
---|
83 |
|
---|
84 | if( strchr( extension, ' ' ) )
|
---|
85 | return 0;
|
---|
86 | start = extensions = ( const char * )glGetString( GL_EXTENSIONS );
|
---|
87 |
|
---|
88 | if( !extensions )
|
---|
89 | return 0;
|
---|
90 |
|
---|
91 | while( 1 )
|
---|
92 | {
|
---|
93 | const char *p = strstr( extensions, extension );
|
---|
94 | if (!p)
|
---|
95 | return 0;
|
---|
96 |
|
---|
97 | /* Check that we matched at a word boundary */
|
---|
98 | if( ( p == start || ' ' == p[ -1 ] ) &&
|
---|
99 | ( ' ' == p[ len ] || 0 == p[ len ] ) )
|
---|
100 | return 1;
|
---|
101 | /* skip the false match and continue */
|
---|
102 | extensions = p + len;
|
---|
103 | }
|
---|
104 |
|
---|
105 | return 0;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /*!
|
---|
109 | \fn
|
---|
110 | \brief Reports all available OpenGL errors.
|
---|
111 | \ingroup opengl
|
---|
112 |
|
---|
113 | Displays as an OpenGLUT warning every OpenGL error
|
---|
114 | that OpenGL remembers giving to us and which
|
---|
115 | we have not processed. Uses gluErrorString().
|
---|
116 |
|
---|
117 | This is forcibly done by OpenGLUT periodically if
|
---|
118 | "-gldebug" is one of the strings passed into
|
---|
119 | glutInit() via \argv.
|
---|
120 |
|
---|
121 | \see gluErrorString(), glutInit()
|
---|
122 | */
|
---|
123 | void OGAPIENTRY glutReportErrors( void )
|
---|
124 | {
|
---|
125 | GLenum error;
|
---|
126 | while( ( error = glGetError( ) ) != GL_NO_ERROR )
|
---|
127 | ogWarning( "GL error: %s", gluErrorString( error ) );
|
---|
128 | }
|
---|
129 |
|
---|
130 | /*!
|
---|
131 | \fn
|
---|
132 | \brief Set autorepeat status.
|
---|
133 | \ingroup inputstate
|
---|
134 | \param ignore Whether to ignore autorepeated keys.
|
---|
135 |
|
---|
136 | If \a ignore is non-zero, then auto-repeat is
|
---|
137 | disabled for keyboard callbacks for the
|
---|
138 | <i>current window</i>.
|
---|
139 |
|
---|
140 | \see glutSetKeyRepeat()
|
---|
141 | */
|
---|
142 | void OGAPIENTRY glutIgnoreKeyRepeat( int ignore )
|
---|
143 | {
|
---|
144 | freeglut_assert_ready;
|
---|
145 | freeglut_assert_window;
|
---|
146 |
|
---|
147 | ogStructure.Window->State.IgnoreKeyRepeat = ignore ? GL_TRUE : GL_FALSE;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /*!
|
---|
151 | \fn
|
---|
152 | \brief Sets autorepeat behavior for all OpenGLUT windows.
|
---|
153 | \ingroup inputstate
|
---|
154 | \param repeatMode On, Off or Default.
|
---|
155 |
|
---|
156 | glutSetKeyRepeat() is similar to glutIgnoreKeyRepeat()
|
---|
157 | but sets the behavior
|
---|
158 | for OpenGLUT in general, rather than for a particular
|
---|
159 | window. The options for \a repeatMode are:
|
---|
160 |
|
---|
161 | - \a GLUT_KEY_REPEAT_OFF \n Turn off repeat for all windows.
|
---|
162 | - \a GLUT_KEY_REPEAT_ON \n Turn on repeat for all windows.
|
---|
163 | - \a GLUT_KEY_REPEAT_DEFAULT \n Respect the window's setting.
|
---|
164 |
|
---|
165 | \see glutIgnoreKeyRepeat()
|
---|
166 | */
|
---|
167 | void OGAPIENTRY glutSetKeyRepeat( int repeatMode )
|
---|
168 | {
|
---|
169 | freeglut_assert_ready;
|
---|
170 |
|
---|
171 | switch( repeatMode )
|
---|
172 | {
|
---|
173 | case GLUT_KEY_REPEAT_OFF:
|
---|
174 | case GLUT_KEY_REPEAT_ON:
|
---|
175 | ogState.KeyRepeat = repeatMode;
|
---|
176 | break;
|
---|
177 |
|
---|
178 | case GLUT_KEY_REPEAT_DEFAULT:
|
---|
179 | ogState.KeyRepeat = GLUT_KEY_REPEAT_ON;
|
---|
180 | break;
|
---|
181 |
|
---|
182 | default:
|
---|
183 | ogError( "Invalid glutSetKeyRepeat mode: %d", repeatMode );
|
---|
184 | break;
|
---|
185 | }
|
---|
186 | }
|
---|
187 |
|
---|
188 | /*!
|
---|
189 | \fn
|
---|
190 | \brief Forces a joystick poll and callback.
|
---|
191 | \ingroup input
|
---|
192 |
|
---|
193 | Forces the OpenGLUT joystick code to poll your
|
---|
194 | joystick(s) and to call your joystick callbacks
|
---|
195 | with the result. The operation completes, including
|
---|
196 | callbacks, before glutForceJoystickFunc() returns.
|
---|
197 |
|
---|
198 | \bug The original WINCE import used a #if to turn this function
|
---|
199 | off. That is wrong. The proper way to handle the joystick
|
---|
200 | code is to generate "null" events. The WINCE code needs
|
---|
201 | to be fixed in og_joystick.c, not here.
|
---|
202 | \see glutJoystickFunc()
|
---|
203 | */
|
---|
204 | void OGAPIENTRY glutForceJoystickFunc( void )
|
---|
205 | {
|
---|
206 | freeglut_assert_ready;
|
---|
207 | if( ogStructure.Window && FETCH_WCB( *( ogStructure.Window ), Joystick ) )
|
---|
208 | ogJoystickPollWindow( ogStructure.Window );
|
---|
209 | }
|
---|
210 |
|
---|
211 | /*!
|
---|
212 | \fn
|
---|
213 | \brief Sets an indexed color-mode entry.
|
---|
214 | \ingroup colormap
|
---|
215 | \param nColor The palette entry to change.
|
---|
216 | \param red New red value for palette entry.
|
---|
217 | \param green New green value for palette entry.
|
---|
218 | \param blue New blue value for palette entry.
|
---|
219 |
|
---|
220 | glutSetCursor() allows you to set individual color-map entries
|
---|
221 | in a \a GLUT_INDEX type of display. Respects the
|
---|
222 | current overlay setting.
|
---|
223 |
|
---|
224 | \bug Unimplemented.
|
---|
225 | \see glutGetColor(), glutCopyColorMap()
|
---|
226 | */
|
---|
227 | void OGAPIENTRY glutSetColor(
|
---|
228 | int nColor, GLfloat red, GLfloat green, GLfloat blue
|
---|
229 | )
|
---|
230 | {
|
---|
231 | }
|
---|
232 |
|
---|
233 | /*!
|
---|
234 | \fn
|
---|
235 | \brief Gets an indexed color-mode entry's Red, Green, or Blue value.
|
---|
236 | \ingroup colormap
|
---|
237 | \param color The palette entry to fetch.
|
---|
238 | \param component Whether to fetch Red, Green, or Blue.
|
---|
239 |
|
---|
240 | Allows you to get individual color-map entries
|
---|
241 | in a \a GLUT_INDEX type of display. Respects the
|
---|
242 | current layer setting.
|
---|
243 |
|
---|
244 | \a component may be any of:
|
---|
245 |
|
---|
246 | - \a GLUT_RED
|
---|
247 | - \a GLUT_GREEN
|
---|
248 | - \a GLUT_BLUE
|
---|
249 |
|
---|
250 | \bug Unimplemented.
|
---|
251 | \see glutSetColor(), glutCopyColorMap()
|
---|
252 | */
|
---|
253 | GLfloat OGAPIENTRY glutGetColor( int color, int component )
|
---|
254 | {
|
---|
255 | return 0.0f;
|
---|
256 | }
|
---|
257 |
|
---|
258 | /*!
|
---|
259 | \fn
|
---|
260 | \brief Copies a color map between windows.
|
---|
261 | \ingroup colormap
|
---|
262 | \param window The window to copy <i>to</i>
|
---|
263 |
|
---|
264 | Allows you to copy an entire color map from
|
---|
265 | one window to another. This function copies
|
---|
266 | <b>from</b> the <i>current window</i>. It
|
---|
267 | copies <b>to</b> the indicated \a window.
|
---|
268 | Respects the current layer setting.
|
---|
269 |
|
---|
270 | \bug Unimplemented.
|
---|
271 | \see glutSetColor(), glutGetColor()
|
---|
272 | */
|
---|
273 | void OGAPIENTRY glutCopyColormap( int window )
|
---|
274 | {
|
---|
275 | }
|
---|