1
2/* Copyright (c) Mark J. Kilgard, 1994, 1997. */
3
4/* This program is freely distributable without licensing fees
5   and is provided without guarantee or warrantee expressed or
6   implied. This program is -not- in the public domain. */
7
8#include <stdlib.h>
9#include <string.h>
10
11#include "glutint.h"
12
13/* CENTRY */
14int GLUTAPIENTRY
15glutExtensionSupported(const char *extension)
16{
17  static const GLubyte *extensions = NULL;
18  const GLubyte *start;
19  GLubyte *where, *terminator;
20
21  /* Extension names should not have spaces. */
22  where = (GLubyte *) strchr(extension, ' ');
23  if (where || *extension == '\0')
24    return 0;
25
26  if (!extensions) {
27    extensions = glGetString(GL_EXTENSIONS);
28  }
29  /* It takes a bit of care to be fool-proof about parsing the
30     OpenGL extensions string.  Don't be fooled by sub-strings,
31     etc. */
32  start = extensions;
33  for (;;) {
34    /* If your application crashes in the strstr routine below,
35       you are probably calling glutExtensionSupported without
36       having a current window.  Calling glGetString without
37       a current OpenGL context has unpredictable results.
38       Please fix your program. */
39    where = (GLubyte *) strstr((const char *) start, extension);
40    if (!where)
41      break;
42    terminator = where + strlen(extension);
43    if (where == start || *(where - 1) == ' ') {
44      if (*terminator == ' ' || *terminator == '\0') {
45        return 1;
46      }
47    }
48    start = terminator;
49  }
50  return 0;
51}
52
53
54struct name_address_pair {
55   const char *name;
56   const GLUTproc address;
57};
58
59static struct name_address_pair glut_functions[] = {
60   { "glutInit", (const GLUTproc) glutInit },
61   { "glutInitDisplayMode", (const GLUTproc) glutInitDisplayMode },
62   { "glutInitDisplayString", (const GLUTproc) glutInitDisplayString },
63   { "glutInitWindowPosition", (const GLUTproc) glutInitWindowPosition },
64   { "glutInitWindowSize", (const GLUTproc) glutInitWindowSize },
65   { "glutMainLoop", (const GLUTproc) glutMainLoop },
66   { "glutCreateWindow", (const GLUTproc) glutCreateWindow },
67   { "glutCreateSubWindow", (const GLUTproc) glutCreateSubWindow },
68   { "glutDestroyWindow", (const GLUTproc) glutDestroyWindow },
69   { "glutPostRedisplay", (const GLUTproc) glutPostRedisplay },
70   { "glutPostWindowRedisplay", (const GLUTproc) glutPostWindowRedisplay },
71   { "glutSwapBuffers", (const GLUTproc) glutSwapBuffers },
72   { "glutGetWindow", (const GLUTproc) glutGetWindow },
73   { "glutSetWindow", (const GLUTproc) glutSetWindow },
74   { "glutSetWindowTitle", (const GLUTproc) glutSetWindowTitle },
75   { "glutSetIconTitle", (const GLUTproc) glutSetIconTitle },
76   { "glutPositionWindow", (const GLUTproc) glutPositionWindow },
77   { "glutReshapeWindow", (const GLUTproc) glutReshapeWindow },
78   { "glutPopWindow", (const GLUTproc) glutPopWindow },
79   { "glutPushWindow", (const GLUTproc) glutPushWindow },
80   { "glutIconifyWindow", (const GLUTproc) glutIconifyWindow },
81   { "glutShowWindow", (const GLUTproc) glutShowWindow },
82   { "glutHideWindow", (const GLUTproc) glutHideWindow },
83   { "glutFullScreen", (const GLUTproc) glutFullScreen },
84   { "glutSetCursor", (const GLUTproc) glutSetCursor },
85   { "glutWarpPointer", (const GLUTproc) glutWarpPointer },
86   { "glutEstablishOverlay", (const GLUTproc) glutEstablishOverlay },
87   { "glutRemoveOverlay", (const GLUTproc) glutRemoveOverlay },
88   { "glutUseLayer", (const GLUTproc) glutUseLayer },
89   { "glutPostOverlayRedisplay", (const GLUTproc) glutPostOverlayRedisplay },
90   { "glutPostWindowOverlayRedisplay", (const GLUTproc) glutPostWindowOverlayRedisplay },
91   { "glutShowOverlay", (const GLUTproc) glutShowOverlay },
92   { "glutHideOverlay", (const GLUTproc) glutHideOverlay },
93   { "glutCreateMenu", (const GLUTproc) glutCreateMenu },
94   { "glutDestroyMenu", (const GLUTproc) glutDestroyMenu },
95   { "glutGetMenu", (const GLUTproc) glutGetMenu },
96   { "glutSetMenu", (const GLUTproc) glutSetMenu },
97   { "glutAddMenuEntry", (const GLUTproc) glutAddMenuEntry },
98   { "glutAddSubMenu", (const GLUTproc) glutAddSubMenu },
99   { "glutChangeToMenuEntry", (const GLUTproc) glutChangeToMenuEntry },
100   { "glutChangeToSubMenu", (const GLUTproc) glutChangeToSubMenu },
101   { "glutRemoveMenuItem", (const GLUTproc) glutRemoveMenuItem },
102   { "glutAttachMenu", (const GLUTproc) glutAttachMenu },
103   { "glutDetachMenu", (const GLUTproc) glutDetachMenu },
104   { "glutDisplayFunc", (const GLUTproc) glutDisplayFunc },
105   { "glutReshapeFunc", (const GLUTproc) glutReshapeFunc },
106   { "glutKeyboardFunc", (const GLUTproc) glutKeyboardFunc },
107   { "glutMouseFunc", (const GLUTproc) glutMouseFunc },
108   { "glutMotionFunc", (const GLUTproc) glutMotionFunc },
109   { "glutPassiveMotionFunc", (const GLUTproc) glutPassiveMotionFunc },
110   { "glutEntryFunc", (const GLUTproc) glutEntryFunc },
111   { "glutVisibilityFunc", (const GLUTproc) glutVisibilityFunc },
112   { "glutIdleFunc", (const GLUTproc) glutIdleFunc },
113   { "glutTimerFunc", (const GLUTproc) glutTimerFunc },
114   { "glutMenuStateFunc", (const GLUTproc) glutMenuStateFunc },
115   { "glutSpecialFunc", (const GLUTproc) glutSpecialFunc },
116   { "glutSpaceballMotionFunc", (const GLUTproc) glutSpaceballMotionFunc },
117   { "glutSpaceballRotateFunc", (const GLUTproc) glutSpaceballRotateFunc },
118   { "glutSpaceballButtonFunc", (const GLUTproc) glutSpaceballButtonFunc },
119   { "glutButtonBoxFunc", (const GLUTproc) glutButtonBoxFunc },
120   { "glutDialsFunc", (const GLUTproc) glutDialsFunc },
121   { "glutTabletMotionFunc", (const GLUTproc) glutTabletMotionFunc },
122   { "glutTabletButtonFunc", (const GLUTproc) glutTabletButtonFunc },
123   { "glutMenuStatusFunc", (const GLUTproc) glutMenuStatusFunc },
124   { "glutOverlayDisplayFunc", (const GLUTproc) glutOverlayDisplayFunc },
125   { "glutWindowStatusFunc", (const GLUTproc) glutWindowStatusFunc },
126   { "glutKeyboardUpFunc", (const GLUTproc) glutKeyboardUpFunc },
127   { "glutSpecialUpFunc", (const GLUTproc) glutSpecialUpFunc },
128   { "glutJoystickFunc", (const GLUTproc) glutJoystickFunc },
129   { "glutSetColor", (const GLUTproc) glutSetColor },
130   { "glutGetColor", (const GLUTproc) glutGetColor },
131   { "glutCopyColormap", (const GLUTproc) glutCopyColormap },
132   { "glutGet", (const GLUTproc) glutGet },
133   { "glutDeviceGet", (const GLUTproc) glutDeviceGet },
134   { "glutExtensionSupported", (const GLUTproc) glutExtensionSupported },
135   { "glutGetModifiers", (const GLUTproc) glutGetModifiers },
136   { "glutLayerGet", (const GLUTproc) glutLayerGet },
137   { "glutGetProcAddress", (const GLUTproc) glutGetProcAddress },
138   { "glutBitmapCharacter", (const GLUTproc) glutBitmapCharacter },
139   { "glutBitmapWidth", (const GLUTproc) glutBitmapWidth },
140   { "glutStrokeCharacter", (const GLUTproc) glutStrokeCharacter },
141   { "glutStrokeWidth", (const GLUTproc) glutStrokeWidth },
142   { "glutBitmapLength", (const GLUTproc) glutBitmapLength },
143   { "glutStrokeLength", (const GLUTproc) glutStrokeLength },
144   { "glutWireSphere", (const GLUTproc) glutWireSphere },
145   { "glutSolidSphere", (const GLUTproc) glutSolidSphere },
146   { "glutWireCone", (const GLUTproc) glutWireCone },
147   { "glutSolidCone", (const GLUTproc) glutSolidCone },
148   { "glutWireCube", (const GLUTproc) glutWireCube },
149   { "glutSolidCube", (const GLUTproc) glutSolidCube },
150   { "glutWireTorus", (const GLUTproc) glutWireTorus },
151   { "glutSolidTorus", (const GLUTproc) glutSolidTorus },
152   { "glutWireDodecahedron", (const GLUTproc) glutWireDodecahedron },
153   { "glutSolidDodecahedron", (const GLUTproc) glutSolidDodecahedron },
154   { "glutWireTeapot", (const GLUTproc) glutWireTeapot },
155   { "glutSolidTeapot", (const GLUTproc) glutSolidTeapot },
156   { "glutWireOctahedron", (const GLUTproc) glutWireOctahedron },
157   { "glutSolidOctahedron", (const GLUTproc) glutSolidOctahedron },
158   { "glutWireTetrahedron", (const GLUTproc) glutWireTetrahedron },
159   { "glutSolidTetrahedron", (const GLUTproc) glutSolidTetrahedron },
160   { "glutWireIcosahedron", (const GLUTproc) glutWireIcosahedron },
161   { "glutSolidIcosahedron", (const GLUTproc) glutSolidIcosahedron },
162   { "glutVideoResizeGet", (const GLUTproc) glutVideoResizeGet },
163   { "glutSetupVideoResizing", (const GLUTproc) glutSetupVideoResizing },
164   { "glutStopVideoResizing", (const GLUTproc) glutStopVideoResizing },
165   { "glutVideoResize", (const GLUTproc) glutVideoResize },
166   { "glutVideoPan", (const GLUTproc) glutVideoPan },
167   { "glutReportErrors", (const GLUTproc) glutReportErrors },
168   { "glutIgnoreKeyRepeat", (const GLUTproc) glutIgnoreKeyRepeat },
169   { "glutSetKeyRepeat", (const GLUTproc) glutSetKeyRepeat },
170   { "glutForceJoystickFunc", (const GLUTproc) glutForceJoystickFunc },
171   { "glutGameModeString", (const GLUTproc) glutGameModeString },
172   { "glutEnterGameMode", (const GLUTproc) glutEnterGameMode },
173   { "glutLeaveGameMode", (const GLUTproc) glutLeaveGameMode },
174   { "glutGameModeGet", (const GLUTproc) glutGameModeGet },
175   { NULL, NULL }
176};
177
178
179/* XXX This isn't an official GLUT function, yet */
180GLUTproc GLUTAPIENTRY
181glutGetProcAddress(const char *procName)
182{
183   /* Try GLUT functions first */
184   int i;
185   for (i = 0; glut_functions[i].name; i++) {
186      if (strcmp(glut_functions[i].name, procName) == 0)
187         return glut_functions[i].address;
188   }
189
190   /* Try core GL functions */
191#if defined(_WIN32)
192  return (GLUTproc) wglGetProcAddress((LPCSTR) procName);
193#elif defined(GLX_ARB_get_proc_address)
194  return (GLUTproc) glXGetProcAddressARB((const GLubyte *) procName);
195#else
196  return NULL;
197#endif
198}
199
200
201/* ENDCENTRY */
202