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.

miniglxtest.c 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* $Id: miniglxtest.c,v 1.1.4.4 2002/12/09 22:34:40 brianp Exp $ */
  2. /*
  3. * Test the mini GLX interface.
  4. */
  5. #define USE_MINI_GLX 1
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <GL/gl.h>
  9. #if USE_MINI_GLX
  10. #include <GL/miniglx.h>
  11. #else
  12. #include <GL/glx.h>
  13. #define WRAP(x) x /* temporary! */
  14. #endif
  15. static void redraw( Display *dpy, Window w, int rot )
  16. {
  17. printf("Redraw event\n");
  18. glClear( GL_COLOR_BUFFER_BIT );
  19. glColor3f( 1.0, 1.0, 0.0 );
  20. glPushMatrix();
  21. glRotatef(rot, 0, 0, 1);
  22. glScalef(.5, .5, .5);
  23. glRectf( -1, -1, 1, 1 );
  24. glPopMatrix();
  25. WRAP(glXSwapBuffers)( dpy, w );
  26. }
  27. static Window make_rgb_db_window( Display *dpy,
  28. unsigned int width, unsigned int height )
  29. {
  30. int attrib[] = { GLX_RGBA,
  31. GLX_RED_SIZE, 1,
  32. GLX_GREEN_SIZE, 1,
  33. GLX_BLUE_SIZE, 1,
  34. GLX_DOUBLEBUFFER,
  35. None };
  36. int scrnum;
  37. XSetWindowAttributes attr;
  38. unsigned long mask;
  39. Window root;
  40. Window win;
  41. GLXContext ctx;
  42. XVisualInfo *visinfo;
  43. scrnum = 0;
  44. root = WRAP(RootWindow)( dpy, scrnum );
  45. visinfo = WRAP(glXChooseVisual)( dpy, scrnum, attrib );
  46. if (!visinfo) {
  47. printf("Error: couldn't get an RGB, Double-buffered visual\n");
  48. exit(1);
  49. }
  50. /* window attributes */
  51. attr.background_pixel = 0;
  52. attr.border_pixel = 0;
  53. attr.colormap = WRAP(XCreateColormap)( dpy, root, visinfo->visual, AllocNone);
  54. attr.event_mask = StructureNotifyMask | ExposureMask;
  55. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  56. win = WRAP(XCreateWindow)( dpy, root, 0, 0, width, height,
  57. 0, visinfo->depth, InputOutput,
  58. visinfo->visual, mask, &attr );
  59. ctx = WRAP(glXCreateContext)( dpy, visinfo, NULL, True );
  60. if (!ctx) {
  61. printf("Error: glXCreateContext failed\n");
  62. exit(1);
  63. }
  64. WRAP(glXMakeCurrent)( dpy, win, ctx );
  65. return win;
  66. }
  67. static void event_loop( Display *dpy, Window win )
  68. {
  69. int i;
  70. printf("Hang on... drawing 5 frames\n");
  71. for (i = 0; i < 5; i++) {
  72. redraw( dpy, win, i*10 );
  73. }
  74. }
  75. int main( int argc, char *argv[] )
  76. {
  77. Display *dpy;
  78. Window win;
  79. dpy = WRAP(XOpenDisplay)(NULL);
  80. if (!dpy) {
  81. printf("Error: XOpenDisplay failed\n");
  82. return 1;
  83. }
  84. win = make_rgb_db_window( dpy, 800, 600);
  85. glShadeModel( GL_FLAT );
  86. glClearColor( 0.5, 0.5, 0.5, 1.0 );
  87. WRAP(XMapWindow)( dpy, win );
  88. event_loop( dpy, win );
  89. WRAP(XDestroyWindow)( dpy, win );
  90. WRAP(XCloseDisplay)( dpy );
  91. return 0;
  92. }