home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / bonus / demos / CS / exp / SOURCES / GLENGINE / glext.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-11  |  2.1 KB  |  77 lines

  1. #ifdef WIN32
  2. #include <windows.h>
  3. #endif
  4.  
  5. #ifndef WIN32
  6. #define APIENTRY
  7. #define CALLBACK
  8. #endif
  9.  
  10. #include <GL/gl.h>
  11. #include <string.h>
  12. #include <iostream>
  13.  
  14. /* GL_EXT_compiled_vertex_array */
  15. typedef void APIENTRY ( * PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count);
  16. typedef void APIENTRY ( * PFNGLUNLOCKARRAYSEXTPROC) (void);
  17.  
  18. void APIENTRY glLockArraysOGL2 (GLint first, GLsizei count) {
  19.   return;
  20. }
  21. void APIENTRY glUnlockArraysOGL2 (void) {
  22.   return;
  23. }
  24.  
  25. PFNGLLOCKARRAYSEXTPROC glLockArraysEXT = &glLockArraysOGL2;
  26. PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT = &glUnlockArraysOGL2;
  27.  
  28. int isExtensionSupported(const char *extension)
  29. {
  30.   const GLubyte *extensions = NULL;
  31.   const GLubyte *start;
  32.   GLubyte *where, *terminator;
  33.  
  34.   /* Extension names should not have spaces. */
  35.   where = (GLubyte *) strchr(extension, ' ');
  36.   if (where || *extension == '\0')
  37.     return 0;
  38.   extensions = glGetString(GL_EXTENSIONS);
  39.   /* It takes a bit of care to be fool-proof about parsing the
  40.      OpenGL extensions string. Don't be fooled by sub-strings,
  41.      etc. */
  42.   start = extensions;
  43.   for (;;) {
  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.     start = terminator;
  52.   }
  53.   return 0;
  54. }
  55.  
  56. void InitOpenGLExtensions()
  57. {
  58.   if(isExtensionSupported("GL_EXT_compiled_vertex_array")) {
  59. //    cout << "Using extension: GL_EXT_compiled_vertex_array" << endl;
  60.  
  61.     glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC)
  62.       wglGetProcAddress("glLockArraysEXT");
  63.     glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC)
  64.       wglGetProcAddress("glUnlockArraysEXT");
  65.   }
  66.   else {
  67.     if(isExtensionSupported("GL_SGI_compiled_vertex_array")) {
  68.       cout << "Using extension: GL_SGI_compiled_vertex_array" << endl;
  69.   
  70.       glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC)
  71.         wglGetProcAddress("glLockArraysSGI");
  72.       glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC)
  73.         wglGetProcAddress("glUnlockArraysSGI");
  74.     }
  75.   }
  76. }
  77.