Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

miniglxsample.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #define USE_MINIGLX 1 /* 1 = use Mini GLX, 0 = use Xlib/GLX */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <GL/gl.h>
  6. #if USE_MINIGLX
  7. #include <GL/miniglx.h>
  8. #else
  9. #include <GL/glx.h>
  10. #include <X11/Xlib.h>
  11. #endif
  12. static void _subset_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
  13. {
  14. glBegin( GL_QUADS );
  15. glVertex2f( x1, y1 );
  16. glVertex2f( x2, y1 );
  17. glVertex2f( x2, y2 );
  18. glVertex2f( x1, y2 );
  19. glEnd();
  20. }
  21. /*
  22. * Create a simple double-buffered RGBA window.
  23. */
  24. static Window
  25. MakeWindow(Display * dpy, unsigned int width, unsigned int height)
  26. {
  27. int visAttributes[] = {
  28. GLX_RGBA,
  29. GLX_RED_SIZE, 1,
  30. GLX_GREEN_SIZE, 1,
  31. GLX_BLUE_SIZE, 1,
  32. GLX_DOUBLEBUFFER,
  33. None
  34. };
  35. XSetWindowAttributes attr;
  36. unsigned long attrMask;
  37. Window root;
  38. Window win;
  39. GLXContext ctx;
  40. XVisualInfo *visinfo;
  41. root = RootWindow(dpy, 0);
  42. /* Choose GLX visual / pixel format */
  43. visinfo = glXChooseVisual(dpy, 0, visAttributes);
  44. if (!visinfo) {
  45. printf("Error: couldn't get an RGB, Double-buffered visual\n");
  46. exit(1);
  47. }
  48. /* Create the window */
  49. attr.background_pixel = 0;
  50. attr.border_pixel = 0;
  51. attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  52. attrMask = CWBackPixel | CWBorderPixel | CWColormap;
  53. win = XCreateWindow(dpy, root, 0, 0, width, height,
  54. 0, visinfo->depth, InputOutput,
  55. visinfo->visual, attrMask, &attr);
  56. if (!win) {
  57. printf("Error: XCreateWindow failed\n");
  58. exit(1);
  59. }
  60. /* Display the window */
  61. XMapWindow(dpy, win);
  62. /* Create GLX rendering context */
  63. ctx = glXCreateContext(dpy, visinfo, NULL, True);
  64. if (!ctx) {
  65. printf("Error: glXCreateContext failed\n");
  66. exit(1);
  67. }
  68. /* Bind the rendering context and window */
  69. glXMakeCurrent(dpy, win, ctx);
  70. glViewport(0, 0, width, height);
  71. return win;
  72. }
  73. /*
  74. * Draw a few frames of a rotating square.
  75. */
  76. static void
  77. DrawFrames(Display * dpy, Window win)
  78. {
  79. int angle;
  80. glShadeModel(GL_FLAT);
  81. glClearColor(0.5, 0.5, 0.5, 1.0);
  82. for (angle = 0; angle < 360; angle += 10) {
  83. glClear(GL_COLOR_BUFFER_BIT);
  84. glColor3f(1.0, 1.0, 0.0);
  85. glPushMatrix();
  86. glRotatef(angle, 0, 0, 1);
  87. _subset_Rectf(-0.8, -0.8, 0.8, 0.8);
  88. glPopMatrix();
  89. glXSwapBuffers(dpy, win);
  90. sleep(1);
  91. }
  92. }
  93. int
  94. main(int argc, char *argv[])
  95. {
  96. Display *dpy;
  97. Window win;
  98. dpy = XOpenDisplay(NULL);
  99. if (!dpy) {
  100. printf("Error: XOpenDisplay failed\n");
  101. return 1;
  102. }
  103. win = MakeWindow(dpy, 300, 300);
  104. DrawFrames(dpy, win);
  105. return 0;
  106. }