From ca612872a602435913932f5a31e92cd011bea475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 28 Feb 2012 15:59:35 +0100 Subject: [PATCH] screen-grabber: Fix area screenshots Our DBus API (and mostly every other API in existence) define an area as the top-left corner and width/height; glReadPixels on the other hand uses the bottom-left corner, so we have to transform the coordinates before passing them to GL. https://bugzilla.gnome.org/show_bug.cgi?id=670979 --- src/shell-screen-grabber.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shell-screen-grabber.c b/src/shell-screen-grabber.c index f8ddaa179..74caa8935 100644 --- a/src/shell-screen-grabber.c +++ b/src/shell-screen-grabber.c @@ -107,6 +107,7 @@ shell_screen_grabber_grab (ShellScreenGrabber *grabber, GLubyte *mapped_data; GLint old_swap_bytes, old_lsb_first, old_row_length, old_skip_pixels, old_skip_rows, old_alignment; GLint old_pack_invert = GL_FALSE; + GLint vp_size[4]; guchar *src_row, *dest_row; int i; @@ -165,6 +166,10 @@ shell_screen_grabber_grab (ShellScreenGrabber *grabber, pf_glBindBufferARB (GL_PIXEL_PACK_BUFFER_ARB, grabber->pixel_buffer); } + /* In OpenGL, (x,y) specifies the bottom-left corner rather than the + * top-left */ + glGetIntegerv (GL_VIEWPORT, vp_size); + y = vp_size[3] - (y + height); glReadPixels (x, y, width, height, GL_BGRA, GL_UNSIGNED_BYTE, 0); mapped_data = pf_glMapBufferARB (GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);