summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-09-20 22:26:33 +0100
committerMartin Jansa <Martin.Jansa@gmail.com>2010-02-18 15:39:26 +0100
commit443678151543b7d28e5c7a6d19481b795a4e78fa (patch)
treed5cd586ed7b59e355c118afeec8d3eb424286bbb
parent20b41db143ff7fec33da4463da1656769afb560f (diff)
Jazz up glxdemo
Since we're modifying glxdemo anyway, this changes it so that clicking on the window changes the clear colour to a randomly chosen one and redraws.
-rw-r--r--progs/xdemos/glxdemo.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/progs/xdemos/glxdemo.c b/progs/xdemos/glxdemo.c
index 843aabb329..75e11443d2 100644
--- a/progs/xdemos/glxdemo.c
+++ b/progs/xdemos/glxdemo.c
@@ -69,7 +69,7 @@ static Window make_rgb_db_window( Display *dpy,
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
- attr.event_mask = StructureNotifyMask | ExposureMask;
+ attr.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
win = XCreateWindow( dpy, root, 0, 0, width, height,
@@ -90,6 +90,17 @@ static Window make_rgb_db_window( Display *dpy,
}
+static void new_colour(Display *dpy, Window win)
+{
+ GLfloat r, g, b;
+ r = (GLfloat)random() / (GLfloat)RAND_MAX;
+ g = (GLfloat)random() / (GLfloat)RAND_MAX;
+ b = (GLfloat)random() / (GLfloat)RAND_MAX;
+ glClearColor(r, g, b, 1.0);
+ redraw(dpy, win);
+}
+
+
static void event_loop( Display *dpy )
{
XEvent event;
@@ -104,6 +115,9 @@ static void event_loop( Display *dpy )
case ConfigureNotify:
resize( event.xconfigure.width, event.xconfigure.height );
break;
+ case ButtonPress:
+ new_colour(dpy, event.xany.window);
+ break;
}
}
}