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