diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-03-14 22:41:46 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-03-14 22:41:46 +0100 |
commit | 11e58a92f540740a297eb131819c59d6a077567a (patch) | |
tree | 9adb5035f0ed563b11f3b2c5ffc7cfc72f8a92e3 | |
parent | 741859d0bda6ae5281ed6b7e5169a1d2d1746744 (diff) | |
download | cv-11e58a92f540740a297eb131819c59d6a077567a.tar.gz cv-11e58a92f540740a297eb131819c59d6a077567a.tar.bz2 cv-11e58a92f540740a297eb131819c59d6a077567a.zip |
wimmel_gl: Draw rects around matching subimages
All red dots in the GL rendering represent a top-left
corner of a matching rectangle.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | wimmel_gl.c | 41 |
2 files changed, 26 insertions, 17 deletions
@@ -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 <GL/gl.h> #include <GL/glext.h> -//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); |