4 * A demonstration of using the GLX functions. This program is in the
17 static void redraw( Display
*dpy
, Window w
)
19 printf("Redraw event\n");
21 glClear( GL_COLOR_BUFFER_BIT
);
23 glColor3f( 1.0, 1.0, 0.0 );
24 glRectf( -0.8, -0.8, 0.8, 0.8 );
26 glXSwapBuffers( dpy
, w
);
31 static void resize( unsigned int width
, unsigned int height
)
33 printf("Resize event\n");
34 glViewport( 0, 0, width
, height
);
35 glMatrixMode( GL_PROJECTION
);
37 glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
42 static Window
make_rgb_db_window( Display
*dpy
,
43 unsigned int width
, unsigned int height
)
45 int attrib
[] = { GLX_RGBA
,
52 XSetWindowAttributes attr
;
59 scrnum
= DefaultScreen( dpy
);
60 root
= RootWindow( dpy
, scrnum
);
62 visinfo
= glXChooseVisual( dpy
, scrnum
, attrib
);
64 printf("Error: couldn't get an RGB, Double-buffered visual\n");
68 /* window attributes */
69 attr
.background_pixel
= 0;
70 attr
.border_pixel
= 0;
71 attr
.colormap
= XCreateColormap( dpy
, root
, visinfo
->visual
, AllocNone
);
72 attr
.event_mask
= StructureNotifyMask
| ExposureMask
;
73 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
75 win
= XCreateWindow( dpy
, root
, 0, 0, width
, height
,
76 0, visinfo
->depth
, InputOutput
,
77 visinfo
->visual
, mask
, &attr
);
79 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
);
81 printf("Error: glXCreateContext failed\n");
85 glXMakeCurrent( dpy
, win
, ctx
);
91 static void event_loop( Display
*dpy
)
96 XNextEvent( dpy
, &event
);
100 redraw( dpy
, event
.xany
.window
);
102 case ConfigureNotify
:
103 resize( event
.xconfigure
.width
, event
.xconfigure
.height
);
111 int main( int argc
, char *argv
[] )
116 dpy
= XOpenDisplay(NULL
);
118 win
= make_rgb_db_window( dpy
, 300, 300 );
120 glShadeModel( GL_FLAT
);
121 glClearColor( 0.5, 0.5, 0.5, 1.0 );
123 XMapWindow( dpy
, win
);