From a73b8978d147d3e2da9057713823dc51ddc4c17e Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 9 Jul 2012 23:01:52 -0700 Subject: [PATCH] vwebp: add checkboard background for alpha display Change-Id: Iefb02f38c0479e61334844d9110cd1b735f0395d --- examples/vwebp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/examples/vwebp.c b/examples/vwebp.c index 90e98d29..2407c6ea 100644 --- a/examples/vwebp.c +++ b/examples/vwebp.c @@ -112,6 +112,26 @@ static void PrintString(const char* const text) { } } +static void DrawCheckerBoard(void) { + const int square_size = 8; // must be a power of 2 + int x, y; + GLint viewport[4]; // x, y, width, height + + glPushMatrix(); + + glGetIntegerv(GL_VIEWPORT, viewport); + // shift to integer coordinates with (0,0) being top-left. + glOrtho(0, viewport[2], viewport[3], 0, -1, 1); + for (y = 0; y < viewport[3]; y += square_size) { + for (x = 0; x < viewport[2]; x += square_size) { + const GLubyte color = 128 + 64 * (!((x + y) & square_size)); + glColor3ub(color, color, color); + glRecti(x, y, x + square_size, y + square_size); + } + } + glPopMatrix(); +} + static void HandleDisplay(void) { const WebPDecBuffer* pic = kParams.pic; if (pic == NULL) return; @@ -121,6 +141,7 @@ static void HandleDisplay(void) { glRasterPos2f(-1, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ROW_LENGTH, pic->u.RGBA.stride / 4); + DrawCheckerBoard(); glDrawPixels(pic->width, pic->height, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)pic->u.RGBA.rgba); @@ -136,6 +157,7 @@ static void HandleDisplay(void) { glRasterPos2f(-0.95f, 0.80f); PrintString(tmp); } + glPopMatrix(); glFlush(); }