From 11e58a92f540740a297eb131819c59d6a077567a Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 14 Mar 2012 22:41:46 +0100 Subject: wimmel_gl: Draw rects around matching subimages All red dots in the GL rendering represent a top-left corner of a matching rectangle. --- Makefile | 2 +- wimmel_gl.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 1b3255d..310f1d9 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ OBJS = wimmel.o wimmel_gl.o util.o all: $(PROGS) wimmel: wimmel.o util.o -wimmel_gl: wimmel_gl.o +wimmel_gl: wimmel_gl.o util.o .PHONY: clean all diff --git a/wimmel_gl.c b/wimmel_gl.c index 223a9de..cc08e02 100644 --- a/wimmel_gl.c +++ b/wimmel_gl.c @@ -6,7 +6,8 @@ #include #include -//int window = 0; +#include "util.h" + GLuint vbo; GLint proj_uniform, tex_uniform, pixelsize_uniform, search_rect_uniform, barrier_uniform; @@ -187,6 +188,10 @@ draw(void) int main(int argc, char **argv) { + GLuint fb, rb; + gint stride; + guchar *buffer; + g_type_init(); glutInit(&argc, argv); @@ -212,8 +217,6 @@ main(int argc, char **argv) int window = glutCreateWindow("wimmel"); glutDestroyWindow(window); - GLuint fb, rb; - glGenFramebuffersEXT(1, &fb); glGenRenderbuffersEXT(1, &rb); @@ -244,24 +247,30 @@ main(int argc, char **argv) glPixelStorei(GL_PACK_ALIGNMENT, 2); - gint stride = width * 4; - guchar *buffer = malloc(stride * height); + stride = width * 4; + buffer = malloc(stride * height); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - GdkPixbuf *t_output, *output; - - t_output = gdk_pixbuf_new_from_data(buffer, - GDK_COLORSPACE_RGB, - TRUE, 8, - width, height, stride, - NULL, NULL); - output = gdk_pixbuf_flip(t_output, FALSE); + for (int j = 0; j < height; ++j) { + guchar *row = buffer + (height - 1 - j) * stride; + for (int i = 0; i < width; ++i) { + if (*(row + i*4)) { + color_t color = COLOR(255, 0, 0, 0); + for (int k = i; k < i+mwidth; k++) { + put_pixel(pixbuf, POINT(k, j), color); + put_pixel(pixbuf, POINT(k, j+mheight), color); + } + for (int n = j; n < j+mheight; n++) { + put_pixel(pixbuf, POINT(i, n), color); + put_pixel(pixbuf, POINT(i+mwidth, n), color); + } + } + } + } - gdk_pixbuf_save(output, "output_gl.png", "png", NULL, NULL); - g_object_unref(output); - g_object_unref(t_output); + gdk_pixbuf_save(pixbuf, "output_gl.png", "png", NULL, NULL); free(buffer); g_object_unref(pixbuf); -- cgit