aboutsummaryrefslogtreecommitdiff
path: root/samples/OpenGL/x11argb_opengl_glsl
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2016-08-02 16:39:18 +0200
committerWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2016-08-02 16:39:18 +0200
commit5f280e26b131fd5f2b569ce0ff48a2b9cfa9b128 (patch)
tree4fe74ee7bd34eb21f40ef803310cbe08470a85d3 /samples/OpenGL/x11argb_opengl_glsl
parentff5c0c58953aa679b2b794906428f8a7cd2b2696 (diff)
downloadcodesamples-5f280e26b131fd5f2b569ce0ff48a2b9cfa9b128.tar.gz
codesamples-5f280e26b131fd5f2b569ce0ff48a2b9cfa9b128.tar.bz2
xcb
Diffstat (limited to 'samples/OpenGL/x11argb_opengl_glsl')
-rw-r--r--samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
index 7aae5a8..2813e11 100644
--- a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
+++ b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
@@ -26,6 +26,7 @@
#define _GNU_SOURCE
+#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -41,8 +42,8 @@
#include <X11/extensions/Xrender.h>
#include <X11/Xutil.h>
-#define USE_CHOOSE_FBCONFIG
-#define USE_GLX_CREATE_WINDOW
+#define USE_GLX_CREATE_WINDOW 1
+#define USE_DOUBLEBUFFER 1
static const GLchar *vertex_shader_source =
"#version 120\n"
@@ -182,7 +183,11 @@ static int width, height;
static int VisData[] = {
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+#if USE_DOUBLEBUFFER
GLX_DOUBLEBUFFER, True,
+#else
+GLX_DOUBLEBUFFER, False,
+#endif
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
@@ -296,7 +301,7 @@ static void createTheWindow()
fatalError("Couldn't create the window\n");
}
-#ifdef USE_GLX_CREATE_WINDOW
+#if USE_GLX_CREATE_WINDOW
int glXattr[] = { None };
glX_window_handle = glXCreateWindow(Xdisplay, fbconfig, window_handle, glXattr);
if( !glX_window_handle ) {
@@ -578,8 +583,12 @@ static void redrawTheWindow(double T)
struct timespec Ta, Tb;
+#if USE_DOUBLEBUFFER
glXSwapBuffers(Xdisplay, glX_window_handle);
- glXWaitGL();
+#else
+ glFlush();
+ usleep(10000);
+#endif
}
static double getftime(void) {
@@ -608,8 +617,23 @@ int main(int argc, char *argv[])
if( !init_resources() )
return -1;
- while (updateTheMessageQueue()) {
- redrawTheWindow(getftime());
+ int n_dT_accum = 0;
+ float dT_accum = 0;
+ while( updateTheMessageQueue() ) {
+ float const dT = getftime();
+ redrawTheWindow(dT);
+
+ dT_accum += dT;
+ ++n_dT_accum;
+
+ if( 100 < n_dT_accum ) {
+ fprintf(stderr, "%d frames in %fs (~%fFPS)\n",
+ n_dT_accum,
+ dT_accum,
+ (float)n_dT_accum / dT_accum);
+ dT_accum = 0.f;
+ n_dT_accum = 0;
+ }
}
return 0;