jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1 | /* oglinfo.c */ |
| 2 | |
| 3 | /* This demo modified by BrianP to accomodate Mesa and test |
| 4 | * the GLX 1.1 functions. |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | |
| 9 | #include <GL/gl.h> |
| 10 | #include <GL/glx.h> |
| 11 | #include <GL/glu.h> |
| 12 | #include <stdio.h> |
| 13 | #include <string.h> |
| 14 | |
| 15 | int visual_request0[] = { None }; /* don't need much of a visual */ |
| 16 | int visual_request1[] = { GLX_RGBA, None }; /* in case CI failed */ |
| 17 | |
| 18 | int main(int argc, char **argv) |
| 19 | { |
| 20 | char *display_name = NULL; |
| 21 | char *string; |
| 22 | Display *dpy; |
| 23 | int screen_num; |
| 24 | int major, minor; |
| 25 | XVisualInfo *vis; |
| 26 | GLXContext ctx; |
| 27 | Window root, win; |
| 28 | Colormap cmap; |
| 29 | XSetWindowAttributes swa; |
| 30 | int dontcare; |
| 31 | |
| 32 | /* parse arguments */ |
| 33 | if(argc > 1) { |
| 34 | if(!strcmp(argv[1],"-display")) |
| 35 | display_name = argv[2]; |
| 36 | else { |
| 37 | fprintf(stderr, "Usage: %s [-display <display>]\n",argv[0]); |
| 38 | return 0; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /* get display */ |
| 43 | if (!(dpy = XOpenDisplay(display_name))) { |
| 44 | fprintf(stderr,"Error: XOpenDisplay() failed.\n"); |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | /* does the server know about OpenGL & GLX? */ |
| 49 | #ifndef MESA |
| 50 | if(!XQueryExtension(dpy, "GLX", &dontcare, &dontcare, &dontcare)) { |
| 51 | fprintf(stderr,"This system doesn't appear to support OpenGL\n"); |
| 52 | return 1; |
| 53 | } |
| 54 | #else |
| 55 | (void) dontcare; |
| 56 | #endif |
| 57 | |
| 58 | /* find the glx version */ |
| 59 | if(glXQueryVersion(dpy, &major, &minor)) |
| 60 | printf("GLX Version: %d.%d\n", major, minor); |
| 61 | else { |
| 62 | fprintf(stderr, "Error: glXQueryVersion() failed.\n"); |
| 63 | return 1; |
| 64 | } |
| 65 | |
| 66 | /* get screen number */ |
| 67 | screen_num = DefaultScreen(dpy); |
| 68 | |
| 69 | /* This #ifdef isn't redundant. It keeps the build from breaking |
| 70 | ** if you are building on a machine that has an old (1.0) version |
| 71 | ** of glx. |
| 72 | ** |
| 73 | ** This program could still be *run* on a machine that has an old |
| 74 | ** version of glx, even if it was *compiled* on a version that has |
| 75 | ** a new version. |
| 76 | ** |
| 77 | ** If compiled on a system with an old version of glx, then it will |
| 78 | ** never recognize glx extensions, since that code would have been |
| 79 | ** #ifdef'ed out. |
| 80 | */ |
| 81 | #ifdef GLX_VERSION_1_1 |
| 82 | |
| 83 | /* |
| 84 | ** This test guarantees that glx, on the display you are inquiring, |
| 85 | ** suppports glXQueryExtensionsString(). |
| 86 | */ |
| 87 | if(minor > 0 || major > 1) |
| 88 | string = (char *) glXQueryExtensionsString(dpy, screen_num); |
| 89 | else |
| 90 | string = ""; |
| 91 | |
| 92 | if(string) |
| 93 | printf("GLX Extensions (client & server): %s\n", |
| 94 | string); |
| 95 | else { |
| 96 | fprintf(stderr, "Error: glXQueryExtensionsString() failed.\n"); |
| 97 | return 1; |
| 98 | } |
| 99 | |
| 100 | if (minor>0 || major>1) { |
| 101 | printf("glXGetClientString(GLX_VENDOR): %s\n", glXGetClientString(dpy,GLX_VENDOR)); |
| 102 | printf("glXGetClientString(GLX_VERSION): %s\n", glXGetClientString(dpy,GLX_VERSION)); |
| 103 | printf("glXGetClientString(GLX_EXTENSIONS): %s\n", glXGetClientString(dpy,GLX_EXTENSIONS)); |
| 104 | printf("glXQueryServerString(GLX_VENDOR): %s\n", glXQueryServerString(dpy,screen_num,GLX_VENDOR)); |
| 105 | printf("glXQueryServerString(GLX_VERSION): %s\n", glXQueryServerString(dpy,screen_num,GLX_VERSION)); |
| 106 | printf("glXQueryServerString(GLX_EXTENSIONS): %s\n", glXQueryServerString(dpy,screen_num,GLX_EXTENSIONS)); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | #endif |
| 111 | |
| 112 | /* get any valid OpenGL visual */ |
| 113 | if (!(vis = glXChooseVisual(dpy, screen_num, visual_request0))) { |
| 114 | if (!(vis = glXChooseVisual(dpy, screen_num, visual_request1))) { |
| 115 | fprintf(stderr,"Error: glXChooseVisual() failed.\n"); |
| 116 | return 1; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /* get context */ |
| 121 | ctx = glXCreateContext(dpy,vis,0,GL_TRUE); |
| 122 | |
| 123 | /* root window */ |
| 124 | root = RootWindow(dpy,vis->screen); |
| 125 | |
| 126 | /* get RGBA colormap */ |
| 127 | cmap = XCreateColormap(dpy, root, vis->visual, AllocNone); |
| 128 | |
| 129 | /* get window */ |
| 130 | swa.colormap = cmap; |
| 131 | swa.border_pixel = 0; |
| 132 | swa.event_mask = StructureNotifyMask; |
| 133 | win = XCreateWindow(dpy, root, 0, 0, 1, 1, 0, vis->depth, |
| 134 | InputOutput,vis->visual, |
| 135 | CWBorderPixel|CWColormap|CWEventMask, |
| 136 | &swa); |
| 137 | |
| 138 | glXMakeCurrent(dpy,win,ctx); |
| 139 | |
| 140 | string = (char *) glGetString(GL_VERSION); |
| 141 | if(string) |
| 142 | #ifdef MESA |
| 143 | printf("Mesa Version: %s\n", string); |
| 144 | #else |
| 145 | printf("OpenGL Version: %s\n", string); |
| 146 | #endif |
| 147 | else { |
| 148 | fprintf(stderr, "Error: glGetString(GL_VERSION) failed.\n"); |
| 149 | return 1; |
| 150 | } |
| 151 | |
| 152 | string = (char *) glGetString(GL_EXTENSIONS); |
| 153 | |
| 154 | if(string) |
| 155 | #ifdef MESA |
| 156 | printf("Mesa Extensions: %s\n", string); |
| 157 | #else |
| 158 | printf("OpenGL Extensions: %s\n", string); |
| 159 | #endif |
| 160 | else { |
| 161 | fprintf(stderr, "Error: glGetString(GL_EXTENSIONS) failed.\n"); |
| 162 | return 1; |
| 163 | } |
| 164 | |
| 165 | string = (char *) glGetString(GL_RENDERER); |
| 166 | |
| 167 | if(string) |
| 168 | #ifdef MESA |
| 169 | printf("Mesa Renderer: %s\n", string); |
| 170 | #else |
| 171 | printf("OpenGL renderer: %s\n", string); |
| 172 | #endif |
| 173 | else { |
| 174 | fprintf(stderr, "Error: glGetString(GL_RENDERER) failed.\n"); |
| 175 | return 1; |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | ** This #ifdef prevents a build failure if you compile on an a |
| 180 | ** machine with an old GLU library. |
| 181 | ** |
| 182 | ** If you build on a pre GLU 1.1 machine, you will never be able |
| 183 | ** to get glu info, even if you run on a GLU 1.1 or latter machine, |
| 184 | ** since the code has been #ifdef'ed out. |
| 185 | */ |
| 186 | #ifdef GLU_VERSION_1_1 |
| 187 | |
| 188 | /* |
| 189 | ** If the glx version is 1.1 or latter, gluGetString() is guaranteed |
| 190 | ** to exist. |
| 191 | */ |
| 192 | if(minor > 0 || major > 1) |
| 193 | string = (char *) gluGetString(GLU_VERSION); |
| 194 | else |
| 195 | string = "1.0"; |
| 196 | |
| 197 | if(string) |
| 198 | printf("GLU Version: %s\n", string); |
| 199 | else { |
| 200 | fprintf(stderr, "Error: gluGetString(GLU_VERSION) failed.\n"); |
| 201 | return 1; |
| 202 | } |
| 203 | |
| 204 | if(minor > 0 || major > 1) |
| 205 | string = (char *) gluGetString(GLU_EXTENSIONS); |
| 206 | else |
| 207 | string = ""; |
| 208 | |
| 209 | if(string) |
| 210 | printf("GLU Extensions: %s\n", string); |
| 211 | else { |
| 212 | fprintf(stderr, "Error: gluGetString(GLU_EXTENSIONS) failed.\n"); |
| 213 | return 1; |
| 214 | } |
| 215 | |
| 216 | #endif |
| 217 | return 0; |
| 218 | } |