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