Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
Brian Paul | 1cfae1a | 2002-11-07 16:23:40 +0000 | [diff] [blame] | 3 | * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 19 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * Test that glXGetProcAddress works. |
| 25 | */ |
| 26 | |
Brian Paul | d4ece7b | 2001-11-21 17:21:41 +0000 | [diff] [blame] | 27 | #define GLX_GLXEXT_PROTOTYPES |
| 28 | |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 29 | #include <X11/Xlib.h> |
| 30 | #include <X11/Xutil.h> |
| 31 | #include <GL/gl.h> |
| 32 | #include <GL/glx.h> |
| 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <string.h> |
| 36 | |
| 37 | |
Brian Paul | 9a2121c | 2003-06-10 14:54:37 +0000 | [diff] [blame^] | 38 | #define EQUAL(X, Y) (fabs((X) - (Y)) < 0.001) |
| 39 | |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 40 | static GLboolean |
| 41 | test_ActiveTextureARB(void *func) |
| 42 | { |
| 43 | PFNGLACTIVETEXTUREARBPROC activeTexture = (PFNGLACTIVETEXTUREARBPROC) func; |
| 44 | GLint t; |
| 45 | GLboolean pass; |
| 46 | (*activeTexture)(GL_TEXTURE1_ARB); |
| 47 | glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &t); |
| 48 | pass = (t == GL_TEXTURE1_ARB); |
| 49 | (*activeTexture)(GL_TEXTURE0_ARB); /* restore default */ |
| 50 | return pass; |
| 51 | } |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 52 | |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 53 | |
| 54 | static GLboolean |
| 55 | test_SecondaryColor3fEXT(void *func) |
| 56 | { |
| 57 | PFNGLSECONDARYCOLOR3FEXTPROC secColor3f = (PFNGLSECONDARYCOLOR3FEXTPROC) func; |
| 58 | GLfloat color[4]; |
| 59 | GLboolean pass; |
| 60 | (*secColor3f)(1.0, 1.0, 0.0); |
| 61 | glGetFloatv(GL_CURRENT_SECONDARY_COLOR_EXT, color); |
| 62 | pass = (color[0] == 1.0 && color[1] == 1.0 && color[2] == 0.0); |
| 63 | (*secColor3f)(0.0, 0.0, 0.0); /* restore default */ |
| 64 | return pass; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | static GLboolean |
| 69 | test_ActiveStencilFaceEXT(void *func) |
| 70 | { |
| 71 | PFNGLACTIVESTENCILFACEEXTPROC activeFace = (PFNGLACTIVESTENCILFACEEXTPROC) func; |
| 72 | GLint face; |
| 73 | GLboolean pass; |
| 74 | (*activeFace)(GL_BACK); |
| 75 | glGetIntegerv(GL_ACTIVE_STENCIL_FACE_EXT, &face); |
| 76 | pass = (face == GL_BACK); |
| 77 | (*activeFace)(GL_FRONT); /* restore default */ |
| 78 | return pass; |
| 79 | } |
| 80 | |
| 81 | |
Brian Paul | 9a2121c | 2003-06-10 14:54:37 +0000 | [diff] [blame^] | 82 | static GLboolean |
| 83 | test_VertexAttrib1fvARB(void *func) |
| 84 | { |
| 85 | PFNGLVERTEXATTRIB1FVARBPROC vertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC) func; |
| 86 | PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB"); |
| 87 | |
| 88 | const GLfloat v[1] = {25.0}; |
| 89 | const GLfloat def[1] = {0}; |
| 90 | GLfloat res[4]; |
| 91 | GLboolean pass; |
| 92 | (*vertexAttrib1fvARB)(6, v); |
| 93 | (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res); |
| 94 | pass = (res[0] == 25.0 && res[1] == 0.0 && res[2] == 0.0 && res[3] == 1.0); |
| 95 | (*vertexAttrib1fvARB)(6, def); |
| 96 | return pass; |
| 97 | } |
| 98 | |
| 99 | static GLboolean |
| 100 | test_VertexAttrib4NubvARB(void *func) |
| 101 | { |
| 102 | PFNGLVERTEXATTRIB4NUBVARBPROC vertexAttrib4NubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) func; |
| 103 | PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB"); |
| 104 | |
| 105 | const GLubyte v[4] = {255, 0, 255, 0}; |
| 106 | const GLubyte def[4] = {0, 0, 0, 255}; |
| 107 | GLfloat res[4]; |
| 108 | GLboolean pass; |
| 109 | (*vertexAttrib4NubvARB)(6, v); |
| 110 | (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res); |
| 111 | pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0); |
| 112 | (*vertexAttrib4NubvARB)(6, def); |
| 113 | return pass; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | static GLboolean |
| 118 | test_VertexAttrib4NuivARB(void *func) |
| 119 | { |
| 120 | PFNGLVERTEXATTRIB4NUIVARBPROC vertexAttrib4NuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC) func; |
| 121 | PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB"); |
| 122 | |
| 123 | const GLuint v[4] = {0xffffffff, 0, 0xffffffff, 0}; |
| 124 | const GLuint def[4] = {0, 0, 0, 0xffffffff}; |
| 125 | GLfloat res[4]; |
| 126 | GLboolean pass; |
| 127 | (*vertexAttrib4NuivARB)(6, v); |
| 128 | (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res); |
| 129 | pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 0.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0)); |
| 130 | (*vertexAttrib4NuivARB)(6, def); |
| 131 | return pass; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | static GLboolean |
| 136 | test_VertexAttrib4ivARB(void *func) |
| 137 | { |
| 138 | PFNGLVERTEXATTRIB4IVARBPROC vertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC) func; |
| 139 | PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB"); |
| 140 | |
| 141 | const GLint v[4] = {1, 2, -3, 4}; |
| 142 | const GLint def[4] = {0, 0, 0, 1}; |
| 143 | GLfloat res[4]; |
| 144 | GLboolean pass; |
| 145 | (*vertexAttrib4ivARB)(6, v); |
| 146 | (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res); |
| 147 | pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 2.0) && EQUAL(res[2], -3.0) && EQUAL(res[3], 4.0)); |
| 148 | (*vertexAttrib4ivARB)(6, def); |
| 149 | return pass; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | static GLboolean |
| 154 | test_VertexAttrib4NsvARB(void *func) |
| 155 | { |
| 156 | PFNGLVERTEXATTRIB4NSVARBPROC vertexAttrib4NsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC) func; |
| 157 | PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB"); |
| 158 | |
| 159 | const GLshort v[4] = {0, 32767, 32767, 0}; |
| 160 | const GLshort def[4] = {0, 0, 0, 32767}; |
| 161 | GLfloat res[4]; |
| 162 | GLboolean pass; |
| 163 | (*vertexAttrib4NsvARB)(6, v); |
| 164 | (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res); |
| 165 | pass = (EQUAL(res[0], 0.0) && EQUAL(res[1], 1.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0)); |
| 166 | (*vertexAttrib4NsvARB)(6, def); |
| 167 | return pass; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | static GLboolean |
| 172 | test_VertexAttrib4NusvARB(void *func) |
| 173 | { |
| 174 | PFNGLVERTEXATTRIB4NUSVARBPROC vertexAttrib4NusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC) func; |
| 175 | PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB"); |
| 176 | |
| 177 | const GLushort v[4] = {0xffff, 0, 0xffff, 0}; |
| 178 | const GLushort def[4] = {0, 0, 0, 0xffff}; |
| 179 | GLfloat res[4]; |
| 180 | GLboolean pass; |
| 181 | (*vertexAttrib4NusvARB)(6, v); |
| 182 | (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res); |
| 183 | pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 0.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0)); |
| 184 | (*vertexAttrib4NusvARB)(6, def); |
| 185 | return pass; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | static GLboolean |
| 190 | test_VertexAttrib4ubNV(void *func) |
| 191 | { |
| 192 | PFNGLVERTEXATTRIB4UBNVPROC vertexAttrib4ubNV = (PFNGLVERTEXATTRIB4UBNVPROC) func; |
| 193 | PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); |
| 194 | |
| 195 | const GLubyte v[4] = {255, 0, 255, 0}; |
| 196 | const GLubyte def[4] = {0, 0, 0, 255}; |
| 197 | GLfloat res[4]; |
| 198 | GLboolean pass; |
| 199 | (*vertexAttrib4ubNV)(6, v[0], v[1], v[2], v[3]); |
| 200 | (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); |
| 201 | pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0); |
| 202 | (*vertexAttrib4ubNV)(6, def[0], def[1], def[2], def[3]); |
| 203 | return pass; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | static GLboolean |
| 208 | test_VertexAttrib2sNV(void *func) |
| 209 | { |
| 210 | PFNGLVERTEXATTRIB2SNVPROC vertexAttrib2sNV = (PFNGLVERTEXATTRIB2SNVPROC) func; |
| 211 | PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); |
| 212 | |
| 213 | const GLshort v[2] = {2, -4,}; |
| 214 | const GLshort def[2] = {0, 0}; |
| 215 | GLfloat res[4]; |
| 216 | GLboolean pass; |
| 217 | (*vertexAttrib2sNV)(6, v[0], v[1]); |
| 218 | (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); |
| 219 | pass = (EQUAL(res[0], 2) && EQUAL(res[1], -4) && EQUAL(res[2], 0) && res[3] == 1.0); |
| 220 | (*vertexAttrib2sNV)(6, def[0], def[1]); |
| 221 | return pass; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | static GLboolean |
| 226 | test_VertexAttrib3fNV(void *func) |
| 227 | { |
| 228 | PFNGLVERTEXATTRIB3FNVPROC vertexAttrib3fNV = (PFNGLVERTEXATTRIB3FNVPROC) func; |
| 229 | PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); |
| 230 | |
| 231 | const GLfloat v[3] = {0.2, 0.4, 0.8}; |
| 232 | const GLfloat def[3] = {0, 0, 0}; |
| 233 | GLfloat res[4]; |
| 234 | GLboolean pass; |
| 235 | (*vertexAttrib3fNV)(6, v[0], v[1], v[2]); |
| 236 | (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); |
| 237 | pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && res[3] == 1.0); |
| 238 | (*vertexAttrib3fNV)(6, def[0], def[1], def[2]); |
| 239 | return pass; |
| 240 | } |
| 241 | |
| 242 | |
| 243 | static GLboolean |
| 244 | test_VertexAttrib4dvNV(void *func) |
| 245 | { |
| 246 | PFNGLVERTEXATTRIB4DVNVPROC vertexAttrib4dvNV = (PFNGLVERTEXATTRIB4DVNVPROC) func; |
| 247 | PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); |
| 248 | |
| 249 | const GLdouble v[4] = {0.2, 0.4, 0.8, 1.2}; |
| 250 | const GLdouble def[4] = {0, 0, 0, 1}; |
| 251 | GLfloat res[4]; |
| 252 | GLboolean pass; |
| 253 | (*vertexAttrib4dvNV)(6, v); |
| 254 | (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); |
| 255 | pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && EQUAL(res[3], 1.2)); |
| 256 | (*vertexAttrib4dvNV)(6, def); |
| 257 | return pass; |
| 258 | } |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 259 | |
| 260 | |
| 261 | /* |
| 262 | * The following header file is auto-generated with Python. The Python |
| 263 | * script looks in this file for functions named "test_*" as seen above. |
| 264 | */ |
| 265 | #include "getproclist.h" |
| 266 | |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 267 | |
| 268 | |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 269 | static int |
| 270 | extension_supported(const char *haystack, const char *needle) |
| 271 | { |
| 272 | if (strstr(haystack, needle)) |
| 273 | return 1; |
| 274 | else |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | static void |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 280 | check_functions( const char *extensions ) |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 281 | { |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 282 | struct name_test_pair *entry; |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 283 | int failures = 0, passes = 0; |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 284 | int totalFail = 0, totalPass = 0; |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 285 | int doTests; |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 286 | |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 287 | for (entry = functions; entry->name; entry++) { |
| 288 | if (entry->name[0] == '-') { |
| 289 | if (entry->name[1] == '1') { |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 290 | doTests = 1; |
| 291 | } |
| 292 | else { |
| 293 | /* check if the named extension is available */ |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 294 | doTests = extension_supported(extensions, entry->name+1); |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 295 | } |
| 296 | if (doTests) |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 297 | printf("Testing %s functions\n", entry->name + 1); |
| 298 | totalFail += failures; |
| 299 | totalPass += passes; |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 300 | failures = 0; |
| 301 | passes = 0; |
| 302 | } |
| 303 | else if (doTests) { |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 304 | void *funcPtr = (void *) glXGetProcAddressARB((const GLubyte *) entry->name); |
| 305 | if (funcPtr) { |
| 306 | if (entry->test) { |
| 307 | GLboolean b; |
| 308 | printf(" Validating %s:", entry->name); |
| 309 | b = (*entry->test)(funcPtr); |
| 310 | if (b) { |
| 311 | printf(" Pass\n"); |
| 312 | passes++; |
| 313 | } |
| 314 | else { |
| 315 | printf(" FAIL!!!\n"); |
| 316 | failures++; |
| 317 | } |
| 318 | } |
| 319 | else { |
| 320 | passes++; |
| 321 | } |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 322 | } |
| 323 | else { |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 324 | printf(" glXGetProcAddress(%s) failed!\n", entry->name); |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 325 | failures++; |
| 326 | } |
| 327 | } |
| 328 | |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 329 | if (doTests && (!(entry+1)->name || (entry+1)->name[0] == '-')) { |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 330 | if (failures > 0) { |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 331 | printf(" %d failed.\n", failures); |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 332 | } |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 333 | if (passes > 0) { |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 334 | printf(" %d passed.\n", passes); |
| 335 | } |
| 336 | } |
| 337 | } |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 338 | totalFail += failures; |
| 339 | totalPass += passes; |
| 340 | |
| 341 | printf("-----------------------------\n"); |
| 342 | printf("Total: %d pass %d fail\n", totalPass, totalFail); |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | |
| 346 | |
| 347 | static void |
| 348 | print_screen_info(Display *dpy, int scrnum, Bool allowDirect) |
| 349 | { |
| 350 | Window win; |
| 351 | int attribSingle[] = { |
| 352 | GLX_RGBA, |
| 353 | GLX_RED_SIZE, 1, |
| 354 | GLX_GREEN_SIZE, 1, |
| 355 | GLX_BLUE_SIZE, 1, |
| 356 | None }; |
| 357 | int attribDouble[] = { |
| 358 | GLX_RGBA, |
| 359 | GLX_RED_SIZE, 1, |
| 360 | GLX_GREEN_SIZE, 1, |
| 361 | GLX_BLUE_SIZE, 1, |
| 362 | GLX_DOUBLEBUFFER, |
| 363 | None }; |
| 364 | |
| 365 | XSetWindowAttributes attr; |
| 366 | unsigned long mask; |
| 367 | Window root; |
| 368 | GLXContext ctx; |
| 369 | XVisualInfo *visinfo; |
| 370 | int width = 100, height = 100; |
| 371 | |
| 372 | root = RootWindow(dpy, scrnum); |
| 373 | |
| 374 | visinfo = glXChooseVisual(dpy, scrnum, attribSingle); |
| 375 | if (!visinfo) { |
| 376 | visinfo = glXChooseVisual(dpy, scrnum, attribDouble); |
| 377 | if (!visinfo) { |
| 378 | fprintf(stderr, "Error: couldn't find RGB GLX visual\n"); |
| 379 | return; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | attr.background_pixel = 0; |
| 384 | attr.border_pixel = 0; |
| 385 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); |
| 386 | attr.event_mask = StructureNotifyMask | ExposureMask; |
| 387 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; |
| 388 | win = XCreateWindow(dpy, root, 0, 0, width, height, |
| 389 | 0, visinfo->depth, InputOutput, |
| 390 | visinfo->visual, mask, &attr); |
| 391 | |
| 392 | ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect ); |
| 393 | if (!ctx) { |
| 394 | fprintf(stderr, "Error: glXCreateContext failed\n"); |
| 395 | XDestroyWindow(dpy, win); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | if (glXMakeCurrent(dpy, win, ctx)) { |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 400 | check_functions( (const char *) glGetString(GL_EXTENSIONS) ); |
Brian Paul | 17fe22d | 2001-11-18 23:16:56 +0000 | [diff] [blame] | 401 | } |
| 402 | else { |
| 403 | fprintf(stderr, "Error: glXMakeCurrent failed\n"); |
| 404 | } |
| 405 | |
| 406 | glXDestroyContext(dpy, ctx); |
| 407 | XDestroyWindow(dpy, win); |
| 408 | } |
| 409 | |
| 410 | |
| 411 | int |
| 412 | main(int argc, char *argv[]) |
| 413 | { |
| 414 | char *displayName = NULL; |
| 415 | Display *dpy; |
| 416 | |
| 417 | dpy = XOpenDisplay(displayName); |
| 418 | if (!dpy) { |
| 419 | fprintf(stderr, "Error: unable to open display %s\n", displayName); |
| 420 | return -1; |
| 421 | } |
| 422 | |
| 423 | print_screen_info(dpy, 0, GL_TRUE); |
| 424 | |
| 425 | XCloseDisplay(dpy); |
| 426 | |
| 427 | return 0; |
| 428 | } |