summaryrefslogtreecommitdiff
path: root/progs/xdemos/glxdemo.c
diff options
context:
space:
mode:
authorjtg <jtg>1999-08-19 00:55:39 +0000
committerjtg <jtg>1999-08-19 00:55:39 +0000
commitafb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1c (patch)
tree59d65b4da12fb5379224cf5f6b808fde91523c7f /progs/xdemos/glxdemo.c
parentf2544d4920ce168bec9cd94d774b7ea5103a3d74 (diff)
Initial revision
Diffstat (limited to 'progs/xdemos/glxdemo.c')
-rw-r--r--progs/xdemos/glxdemo.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/progs/xdemos/glxdemo.c b/progs/xdemos/glxdemo.c
new file mode 100644
index 0000000000..c49cd85140
--- /dev/null
+++ b/progs/xdemos/glxdemo.c
@@ -0,0 +1,136 @@
+/* $Id: glxdemo.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */
+
+
+/*
+ * A demonstration of using the GLX functions. This program is in the
+ * public domain.
+ *
+ * Brian Paul
+ */
+
+
+/*
+ * $Log: glxdemo.c,v $
+ * Revision 1.1 1999/08/19 00:55:43 jtg
+ * Initial revision
+ *
+ * Revision 3.0 1998/02/21 02:16:54 brianp
+ * initial rev
+ *
+ */
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+static void redraw( Display *dpy, Window w )
+{
+ printf("Redraw event\n");
+
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ glColor3f( 1.0, 1.0, 0.0 );
+ glRectf( -0.8, -0.8, 0.8, 0.8 );
+
+ glXSwapBuffers( dpy, w );
+}
+
+
+
+static void resize( unsigned int width, unsigned int height )
+{
+ printf("Resize event\n");
+ glViewport( 0, 0, width, height );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
+}
+
+
+
+static Window make_rgb_db_window( Display *dpy,
+ unsigned int width, unsigned int height )
+{
+ int attrib[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None };
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ GLXContext ctx;
+ XVisualInfo *visinfo;
+
+ scrnum = DefaultScreen( dpy );
+ root = RootWindow( dpy, scrnum );
+
+ visinfo = glXChooseVisual( dpy, scrnum, attrib );
+ if (!visinfo) {
+ printf("Error: couldn't get an RGB, Double-buffered visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( dpy, root, 0, 0, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr );
+
+ ctx = glXCreateContext( dpy, visinfo, NULL, True );
+
+ glXMakeCurrent( dpy, win, ctx );
+
+ return win;
+}
+
+
+static void event_loop( Display *dpy )
+{
+ XEvent event;
+
+ while (1) {
+ XNextEvent( dpy, &event );
+
+ switch (event.type) {
+ case Expose:
+ redraw( dpy, event.xany.window );
+ break;
+ case ConfigureNotify:
+ resize( event.xconfigure.width, event.xconfigure.height );
+ break;
+ }
+ }
+}
+
+
+
+int main( int argc, char *argv[] )
+{
+ Display *dpy;
+ Window win;
+
+ dpy = XOpenDisplay(NULL);
+
+ win = make_rgb_db_window( dpy, 300, 300 );
+
+ glShadeModel( GL_FLAT );
+ glClearColor( 0.5, 0.5, 0.5, 1.0 );
+
+ XMapWindow( dpy, win );
+
+ event_loop( dpy );
+ return 0;
+}