Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

oglinfo.c 5.5KB

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