diff src/video/SDL_renderer_gl.c @ 3447:294b770c1989

Fixed GL_RenderReadPixels() - thanks Ryan!
author Sam Lantinga <slouken@libsdl.org>
date Wed, 18 Nov 2009 08:07:37 +0000
parents 0f969d273f65
children 77366fae0094
line wrap: on
line diff
--- a/src/video/SDL_renderer_gl.c	Wed Nov 18 07:35:00 2009 +0000
+++ b/src/video/SDL_renderer_gl.c	Wed Nov 18 08:07:37 2009 +0000
@@ -1257,6 +1257,7 @@
                     Uint32 pixel_format, void * pixels, int pitch)
 {
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
     GLint internalFormat;
     GLenum format, type;
     Uint8 *src, *dst, *tmp;
@@ -1276,13 +1277,10 @@
     data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
     data->glPixelStorei(GL_PACK_ROW_LENGTH,
                         (pitch / bytes_per_pixel(pixel_format)));
-    data->glReadBuffer(GL_FRONT);
 
-memset(pixels, 0xff, rect->h*pitch);
-    data->glReadPixels(rect->x, rect->y+rect->h-1, rect->w, rect->h,
+    data->glReadPixels(rect->x, (window->h-rect->y)-rect->h, rect->w, rect->h,
                        format, type, pixels);
 
-#if 0
     /* Flip the rows to be top-down */
     length = rect->w * bytes_per_pixel(pixel_format);
     src = (Uint8*)pixels + (rect->h-1)*pitch;
@@ -1293,9 +1291,10 @@
         SDL_memcpy(tmp, dst, length);
         SDL_memcpy(dst, src, length);
         SDL_memcpy(src, tmp, length);
+        dst += pitch;
+        src -= pitch;
     }
     SDL_stack_free(tmp);
-#endif
 
     return 0;
 }