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