1 /* $Id: miniglxtest.c,v 1.3 2004/03/25 14:58:39 brianp Exp $ */
4 * Test the mini GLX interface.
12 #define USE_MINI_GLX 1
14 #include <GL/miniglx.h>
27 static void _subset_Rectf( GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
39 static void redraw( Display
*dpy
, Window w
, int rot
)
41 printf("Redraw event\n");
44 glDrawBuffer( GL_FRONT
);
46 /* glDrawBuffer( GL_BACK ); */
49 glClearColor( rand()/(float)RAND_MAX
,
50 rand()/(float)RAND_MAX
,
51 rand()/(float)RAND_MAX
,
54 glClear( GL_COLOR_BUFFER_BIT
);
57 glColor3f( rand()/(float)RAND_MAX
,
58 rand()/(float)RAND_MAX
,
59 rand()/(float)RAND_MAX
);
61 glRotatef(rot
, 0, 0, 1);
63 _subset_Rectf( -1, -1, 1, 1 );
70 glXSwapBuffers( dpy
, w
);
76 static Window
make_rgb_db_window( Display
*dpy
,
77 unsigned int width
, unsigned int height
)
79 int attrib
[] = { GLX_RGBA
,
88 XSetWindowAttributes attr
;
95 root
= RootWindow( dpy
, scrnum
);
97 if (!(visinfo
= glXChooseVisual( dpy
, scrnum
, attrib
))) {
98 printf("Error: couldn't get an RGB, Double-buffered visual\n");
102 if(!(ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
))) {
103 printf("Error: glXCreateContext failed\n");
107 /* window attributes */
108 attr
.background_pixel
= 0;
109 attr
.border_pixel
= 0;
110 attr
.colormap
= XCreateColormap( dpy
, root
, visinfo
->visual
, AllocNone
);
111 attr
.event_mask
= StructureNotifyMask
| ExposureMask
;
112 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
114 win
= XCreateWindow( dpy
, root
, 0, 0, width
, height
,
115 0, visinfo
->depth
, InputOutput
,
116 visinfo
->visual
, mask
, &attr
);
118 printf("Error: XCreateWindow failed\n");
122 glXMakeCurrent( dpy
, win
, ctx
);
124 glViewport(0, 0, width
, height
);
130 static void event_loop( Display
*dpy
, Window win
)
134 printf("Hang on... drawing %d frames\n", NR
);
135 for (i
= 0; i
< NR
; i
++) {
136 redraw( dpy
, win
, i
*10 );
138 printf("sleep(1)\n");
145 static int foo( void )
150 dpy
= XOpenDisplay(NULL
);
152 printf("Error: XOpenDisplay failed\n");
156 win
= make_rgb_db_window( dpy
, 800, 600);
160 glShadeModel( GL_FLAT
);
161 glClearColor( 0.5, 0.5, 0.5, 1.0 );
163 XMapWindow( dpy
, win
);
168 XNextEvent( dpy
, &e
);
169 if (e
.type
== MapNotify
&& e
.xmap
.window
== win
) {
175 event_loop( dpy
, win
);
177 glXDestroyContext( dpy
, ctx
);
178 XDestroyWindow( dpy
, win
);
180 XCloseDisplay( dpy
);
189 for (i
= 0 ; i
< NR_DISPLAYS
; i
++) {