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