[waffle] [PATCH 3/3] examples/gl_basic: use glReadPixels to verify correct drawing

Jordan Justen jordan.l.justen at intel.com
Wed Aug 8 16:18:36 PDT 2012


Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 examples/gl_basic.c |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/examples/gl_basic.c b/examples/gl_basic.c
index 628c25d..940d651 100644
--- a/examples/gl_basic.c
+++ b/examples/gl_basic.c
@@ -244,8 +244,9 @@ parse_args(int argc, char *argv[], struct options *opts)
 static bool
 draw(struct waffle_window *window)
 {
-    int i;
+    int i, j;
     bool ok;
+    unsigned char *colors;
 
     static const struct timespec sleep_time = {
          // 0.5 sec
@@ -263,6 +264,23 @@ draw(struct waffle_window *window)
 
         glClear(GL_COLOR_BUFFER_BIT);
         ok = waffle_window_swap_buffers(window);
+
+        colors = calloc(WINDOW_WIDTH * WINDOW_HEIGHT * 4, sizeof(*colors));
+        glReadPixels(0, 0,
+                     WINDOW_WIDTH, WINDOW_HEIGHT,
+                     GL_RGBA, GL_UNSIGNED_BYTE,
+                     colors);
+        for (j = 0; j < WINDOW_WIDTH * WINDOW_HEIGHT * 4; j += 4) {
+           if ((colors[j]   != (i == 0 ? 0xff : 0)) ||
+               (colors[j+1] != (i == 1 ? 0xff : 0)) ||
+               (colors[j+2] != (i == 2 ? 0xff : 0)) ||
+               (colors[j+3] != 0xff)) {
+              ok = false;
+              break;
+           }
+        }
+        free(colors);
+
         if (!ok)
             return false;
         nanosleep(&sleep_time, NULL);
-- 
1.7.9.5



More information about the waffle mailing list