4 * Gestion des extensions sous OpenGL
9 * Ce package a ete teste sur SGI, OSF, SUN, HP et WNT.
13 * Le InitExtensionGLX permet d'initialiser le display. Ceci est necessaire
14 * pour travailler sur les extensions de GLX. On ne peut appeler QueryExtensionGLX
15 * si on n'a pas fait cette manip.
16 * Par contre QueryExtension gere les extensions a GL, on n'a pas besoin du
19 * Pour l'instant on ne gere pas les extensions a GLU et a WGL.
21 * Historique des modifications
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 * 14-10-97: FMN ; creation
24 * 23-10-97: FMN ; ajout gestion glx
25 * 04-11-97: FMN ; Gestion des differentes versions GLX
26 * 19-11-97: FMN ; Ajout GetCurrentDisplay
27 * 04-12-97: FMN ; Ajout supportsOneDotOne
28 * 22-07-98: FMN ; InitExtensionGLX n'est execute qu'une fois
29 * 28-07-98: FMN ; Renomme theDisplay en mytheDisplay
31 /*----------------------------------------------------------------------*/
33 /*----------------------------------------------------------------------*/
42 #include <OpenGl_Extension.hxx>
46 /*----------------------------------------------------------------------*/
52 /*----------------------------------------------------------------------*/
57 static Display *mytheDisplay = NULL;
58 static int screen_num;
59 static int GLXmajor, GLXminor;
60 static int GLmajor, GLminor;
62 static GLboolean flag_InitExtensionGLX = GL_FALSE;
64 static GLboolean OneDotOne = GL_FALSE;
65 static GLboolean initOneDotOne = GL_FALSE;
67 /*----------------------------------------------------------------------*/
72 /*----------------------------------------------------------------------*/
73 extern GLboolean CheckExtension(char *extName, const char *extString)
76 ** Search for extName in the extensions string. Use of strstr()
77 ** is not sufficient because extension names can be prefixes of
78 ** other extension names. Could use strtok() but the constant
79 ** string returned by glGetString can be in read-only memory.
81 char *p = (char *)extString;
85 extNameLen = strlen(extName);
89 int n = strcspn(p, " ");
90 if ((extNameLen == n) && (strncmp(extName, p, n) == 0)) {
98 extern GLboolean InitExtensionGLX(Display *display)
102 int dontcare; /* for returned arguments we don't care about */
104 if (display == NULL) return GL_FALSE;
106 if (!flag_InitExtensionGLX)
108 /* does the server know about OpenGL & GLX? */
109 if(!XQueryExtension(display, "GLX", &dontcare, &dontcare, &dontcare)) {
111 fprintf(stderr,"This system doesn't appear to support OpenGL\n");
116 /* find the glx version */
117 if(glXQueryVersion(display, &GLXmajor, &GLXminor)) {
119 printf("GLX Version: %d.%d\n", GLXmajor, GLXminor);
123 fprintf(stderr, "Error: glXQueryVersion() failed.\n");
128 /* get screen number */
129 screen_num = DefaultScreen(display);
131 flag_InitExtensionGLX = GL_TRUE;
132 mytheDisplay = display;
134 } /* (!flag_InitExtensionGLX) */
145 /*----------------------------------------------------------------------*/
146 extern GLboolean QueryExtensionGLX(char *extName)
148 GLboolean result = GL_FALSE;
150 #ifdef GLX_VERSION_1_1
151 if (flag_InitExtensionGLX)
153 if ( GLXminor > 1 || GLXmajor > 1 ) /* GLX_VERSION_1_2 */
155 /* Certaines extensions sont par defaut dans la version 1.2 */
156 if (strcmp(extName,"GLX_EXT_import_context")) return GL_TRUE;
157 result = CheckExtension(extName, glXQueryExtensionsString(mytheDisplay, screen_num));
159 else if( GLXminor > 0 || GLXmajor > 1 ) /* GLX_VERSION_1_1 */
161 result = CheckExtension(extName, glXQueryExtensionsString(mytheDisplay, screen_num));
166 printf("QueryExtensionGLX: %s %d", extName, result);
171 /*----------------------------------------------------------------------*/
172 extern Display *GetCurrentDisplay(void)
175 printf("GetCurrentDisplay %x \n", mytheDisplay);
180 /*----------------------------------------------------------------------*/
181 extern GLboolean QueryExtension(char *extName)
183 GLboolean result = GL_FALSE;
185 if (supportsOneDotOne()) /* GL_VERSION_1_1 ou more */
187 /* Certaines extensions sont par defaut dans la version 1.1 */
188 /* Certain extensions are the defaut in version 1.1 */
189 if ((strcmp(extName,"GL_EXT_vertex_array")) ||
190 (strcmp(extName,"GL_EXT_polygon_offset")) ||
191 (strcmp(extName,"GL_EXT_blend_logic_op")) ||
192 (strcmp(extName,"GL_EXT_texture")) ||
193 (strcmp(extName,"GL_EXT_copy_texture")) ||
194 (strcmp(extName,"GL_EXT_subtexture")) ||
195 (strcmp(extName,"GL_EXT_texture_object")))
198 result = CheckExtension(extName, (char *)glGetString(GL_EXTENSIONS));
200 else /* GL_VERSION_1_0 */
202 result = CheckExtension(extName, (char *)glGetString(GL_EXTENSIONS));
206 printf("QueryExtension: %s %d \n", extName, result);
210 /*----------------------------------------------------------------------*/
212 extern GLboolean supportsOneDotOne(void)
214 const GLubyte *version;
218 version = glGetString(GL_VERSION);
219 if(sscanf((const char *)version, "%d.%d", &GLmajor, &GLminor) == 2)
221 OneDotOne = (GLmajor>=1 && GLminor >=1);
223 initOneDotOne = GL_TRUE;
226 printf("GL Version: %d.%d\n", GLmajor, GLminor);
231 /*----------------------------------------------------------------------*/