aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--samples/OpenGL/x11argb_opengl/x11argb_opengl.c10
-rw-r--r--samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c14
-rw-r--r--samples/X11/clobberme/Makefile3
-rw-r--r--samples/X11/clobberme/clobberme.c171
4 files changed, 198 insertions, 0 deletions
diff --git a/samples/OpenGL/x11argb_opengl/x11argb_opengl.c b/samples/OpenGL/x11argb_opengl/x11argb_opengl.c
index 1c1e2e0..723c6ae 100644
--- a/samples/OpenGL/x11argb_opengl/x11argb_opengl.c
+++ b/samples/OpenGL/x11argb_opengl/x11argb_opengl.c
@@ -23,12 +23,16 @@
\_____/ FTB.
------------------------------------------------------------------------*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
+#include <sys/types.h>
+#include <time.h>
+
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glxext.h>
@@ -461,7 +465,13 @@ static void redrawTheWindow()
b = fmod(b+0.5, 360.);
c = fmod(c+0.25, 360.);
+ struct timespec Ta, Tb;
+
+ clock_gettime(CLOCK_MONOTONIC_RAW, &Ta);
glXSwapBuffers(Xdisplay, glX_window_handle);
+ clock_gettime(CLOCK_MONOTONIC_RAW, &Tb);
+
+ fprintf(stderr, "glXSwapBuffers returned after %f ms\n", 1e3*((double)Tb.tv_sec + 1e-6*(double)Tb.tv_nsec) - 1e3*((double)Ta.tv_sec + 1e-6*(double)Ta.tv_nsec));
}
int main(int argc, char *argv[])
diff --git a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
index b658f5c..0852cbc 100644
--- a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
+++ b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
@@ -24,12 +24,17 @@
------------------------------------------------------------------------*/
+#define _GNU_SOURCE
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+
#include <GL/glew.h>
#include <GL/glx.h>
#include <X11/Xatom.h>
@@ -571,7 +576,16 @@ static void redrawTheWindow(double T)
draw_cube();
popModelview();
+ struct timespec Ta, Tb;
+
+ clock_gettime(CLOCK_MONOTONIC_RAW, &Ta);
glXSwapBuffers(Xdisplay, glX_window_handle);
+ glXWaitGL();
+ clock_gettime(CLOCK_MONOTONIC_RAW, &Tb);
+
+ fprintf(stderr, "glXSwapBuffers + glXWaitGL returned after %f ms\n",
+ 1e3*( (double)Tb.tv_sec + 1e-9*(double)Tb.tv_nsec ) -
+ 1e3*( (double)Ta.tv_sec + 1e-9*(double)Ta.tv_nsec ) );
}
static double getftime(void) {
diff --git a/samples/X11/clobberme/Makefile b/samples/X11/clobberme/Makefile
new file mode 100644
index 0000000..52dfca8
--- /dev/null
+++ b/samples/X11/clobberme/Makefile
@@ -0,0 +1,3 @@
+clobberme: clobberme.c Makefile
+ $(CC) -o clobberme -lX11 clobberme.c
+
diff --git a/samples/X11/clobberme/clobberme.c b/samples/X11/clobberme/clobberme.c
new file mode 100644
index 0000000..ac58dc5
--- /dev/null
+++ b/samples/X11/clobberme/clobberme.c
@@ -0,0 +1,171 @@
+/*------------------------------------------------------------------------
+ * A demonstration of a clobberable X11 window, i.e. a window that will
+ * assume the contents of whatever was visible above it, without clearing
+ * or tidying up itself.
+ *
+ * (c) 2013 by Wolfgang 'datenwolf' Draxinger
+
+ * License agreement: This source code is provided "as is". You
+ * can use this source code however you want for your own personal
+ * use. If you give this source code to anybody else then you must
+ * leave this message in it.
+------------------------------------------------------------------------*/
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include <sys/types.h>
+#include <time.h>
+
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+static void fatalError(const char *why)
+{
+ fprintf(stderr, "%s", why);
+ exit(0x666);
+}
+
+static int Xscreen;
+static Atom del_atom;
+static Colormap cmap;
+static Display *Xdisplay;
+static Visual *Xvisual;
+static Window Xroot, window_handle;
+static int width, height;
+
+static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg)
+{
+ return d && e && arg && (e->type == MapNotify) && (e->xmap.window == *(Window*)arg);
+}
+
+static void createTheWindow()
+{
+ XEvent event;
+ int x,y, attr_mask;
+ XSizeHints hints;
+ XWMHints *startup_state;
+ XTextProperty textprop;
+ XSetWindowAttributes attr = {0,};
+ static char *title = "FTB's little OpenGL example - ARGB extension by WXD";
+
+ Xdisplay = XOpenDisplay(NULL);
+ if (!Xdisplay) {
+ fatalError("Couldn't connect to X server\n");
+ }
+ Xscreen = DefaultScreen(Xdisplay);
+ Xroot = RootWindow(Xdisplay, Xscreen);
+ Xvisual = DefaultVisual(Xdisplay, Xscreen);
+
+ /* Create a colormap - only needed on some X clients, eg. IRIX */
+ cmap = XCreateColormap(Xdisplay, Xroot, Xvisual, AllocNone);
+
+ attr.colormap = cmap;
+ attr.background_pixmap = None;
+ attr.border_pixmap = None;
+ attr.border_pixel = 0;
+ attr.event_mask =
+ StructureNotifyMask |
+ EnterWindowMask |
+ LeaveWindowMask |
+ ExposureMask |
+ ButtonPressMask |
+ ButtonReleaseMask |
+ OwnerGrabButtonMask |
+ KeyPressMask |
+ KeyReleaseMask;
+
+ attr_mask = 0
+ // | CWBackPixmap
+ | CWColormap
+ // | CWBorderPixel
+ | CWEventMask ;
+
+ width = DisplayWidth(Xdisplay, DefaultScreen(Xdisplay))/2;
+ height = DisplayHeight(Xdisplay, DefaultScreen(Xdisplay))/2;
+ x=width/2, y=height/2;
+
+ window_handle = XCreateWindow( Xdisplay,
+ Xroot,
+ x, y, width, height,
+ 0,
+ CopyFromParent,
+ InputOutput,
+ Xvisual,
+ attr_mask, &attr);
+
+ if( !window_handle ) {
+ fatalError("Couldn't create the window\n");
+ }
+
+ textprop.value = (unsigned char*)title;
+ textprop.encoding = XA_STRING;
+ textprop.format = 8;
+ textprop.nitems = strlen(title);
+
+ hints.x = x;
+ hints.y = y;
+ hints.width = width;
+ hints.height = height;
+ hints.flags = USPosition|USSize;
+
+ startup_state = XAllocWMHints();
+ startup_state->initial_state = NormalState;
+ startup_state->flags = StateHint;
+
+ XSetWMProperties(Xdisplay, window_handle,&textprop, &textprop,
+ NULL, 0,
+ &hints,
+ startup_state,
+ NULL);
+
+ XFree(startup_state);
+
+ XMapWindow(Xdisplay, window_handle);
+ XIfEvent(Xdisplay, &event, WaitForMapNotify, (char*)&window_handle);
+
+ if ((del_atom = XInternAtom(Xdisplay, "WM_DELETE_WINDOW", 0)) != None) {
+ XSetWMProtocols(Xdisplay, window_handle, &del_atom, 1);
+ }
+}
+
+static int updateTheMessageQueue()
+{
+ XEvent event;
+ XConfigureEvent *xc;
+
+ while (XPending(Xdisplay))
+ {
+ XNextEvent(Xdisplay, &event);
+ switch (event.type)
+ {
+ case ClientMessage:
+ if (event.xclient.data.l[0] == del_atom)
+ {
+ return 0;
+ }
+ break;
+
+ case ConfigureNotify:
+ xc = &(event.xconfigure);
+ width = xc->width;
+ height = xc->height;
+ break;
+ }
+ }
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ createTheWindow();
+
+ while (updateTheMessageQueue()) {
+ }
+
+ return 0;
+}
+