Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

glxdemo.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* $Id: glxdemo.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */
  2. /*
  3. * A demonstration of using the GLX functions. This program is in the
  4. * public domain.
  5. *
  6. * Brian Paul
  7. */
  8. /*
  9. * $Log: glxdemo.c,v $
  10. * Revision 1.1 1999/08/19 00:55:43 jtg
  11. * Initial revision
  12. *
  13. * Revision 3.0 1998/02/21 02:16:54 brianp
  14. * initial rev
  15. *
  16. */
  17. #include <GL/gl.h>
  18. #include <GL/glx.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. static void redraw( Display *dpy, Window w )
  22. {
  23. printf("Redraw event\n");
  24. glClear( GL_COLOR_BUFFER_BIT );
  25. glColor3f( 1.0, 1.0, 0.0 );
  26. glRectf( -0.8, -0.8, 0.8, 0.8 );
  27. glXSwapBuffers( dpy, w );
  28. }
  29. static void resize( unsigned int width, unsigned int height )
  30. {
  31. printf("Resize event\n");
  32. glViewport( 0, 0, width, height );
  33. glMatrixMode( GL_PROJECTION );
  34. glLoadIdentity();
  35. glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
  36. }
  37. static Window make_rgb_db_window( Display *dpy,
  38. unsigned int width, unsigned int height )
  39. {
  40. int attrib[] = { GLX_RGBA,
  41. GLX_RED_SIZE, 1,
  42. GLX_GREEN_SIZE, 1,
  43. GLX_BLUE_SIZE, 1,
  44. GLX_DOUBLEBUFFER,
  45. None };
  46. int scrnum;
  47. XSetWindowAttributes attr;
  48. unsigned long mask;
  49. Window root;
  50. Window win;
  51. GLXContext ctx;
  52. XVisualInfo *visinfo;
  53. scrnum = DefaultScreen( dpy );
  54. root = RootWindow( dpy, scrnum );
  55. visinfo = glXChooseVisual( dpy, scrnum, attrib );
  56. if (!visinfo) {
  57. printf("Error: couldn't get an RGB, Double-buffered visual\n");
  58. exit(1);
  59. }
  60. /* window attributes */
  61. attr.background_pixel = 0;
  62. attr.border_pixel = 0;
  63. attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  64. attr.event_mask = StructureNotifyMask | ExposureMask;
  65. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  66. win = XCreateWindow( dpy, root, 0, 0, width, height,
  67. 0, visinfo->depth, InputOutput,
  68. visinfo->visual, mask, &attr );
  69. ctx = glXCreateContext( dpy, visinfo, NULL, True );
  70. glXMakeCurrent( dpy, win, ctx );
  71. return win;
  72. }
  73. static void event_loop( Display *dpy )
  74. {
  75. XEvent event;
  76. while (1) {
  77. XNextEvent( dpy, &event );
  78. switch (event.type) {
  79. case Expose:
  80. redraw( dpy, event.xany.window );
  81. break;
  82. case ConfigureNotify:
  83. resize( event.xconfigure.width, event.xconfigure.height );
  84. break;
  85. }
  86. }
  87. }
  88. int main( int argc, char *argv[] )
  89. {
  90. Display *dpy;
  91. Window win;
  92. dpy = XOpenDisplay(NULL);
  93. win = make_rgb_db_window( dpy, 300, 300 );
  94. glShadeModel( GL_FLAT );
  95. glClearColor( 0.5, 0.5, 0.5, 1.0 );
  96. XMapWindow( dpy, win );
  97. event_loop( dpy );
  98. return 0;
  99. }