Fixed GL_RenderReadPixels() - thanks Ryan!
authorSam Lantinga <slouken@libsdl.org>
Wed, 18 Nov 2009 08:07:37 +0000
changeset 3447294b770c1989
parent 3446 0f969d273f65
child 3448 bc27e1fdd3a7
Fixed GL_RenderReadPixels() - thanks Ryan!
src/video/SDL_renderer_gl.c
     1.1 --- a/src/video/SDL_renderer_gl.c	Wed Nov 18 07:35:00 2009 +0000
     1.2 +++ b/src/video/SDL_renderer_gl.c	Wed Nov 18 08:07:37 2009 +0000
     1.3 @@ -1257,6 +1257,7 @@
     1.4                      Uint32 pixel_format, void * pixels, int pitch)
     1.5  {
     1.6      GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     1.7 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
     1.8      GLint internalFormat;
     1.9      GLenum format, type;
    1.10      Uint8 *src, *dst, *tmp;
    1.11 @@ -1276,13 +1277,10 @@
    1.12      data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
    1.13      data->glPixelStorei(GL_PACK_ROW_LENGTH,
    1.14                          (pitch / bytes_per_pixel(pixel_format)));
    1.15 -    data->glReadBuffer(GL_FRONT);
    1.16  
    1.17 -memset(pixels, 0xff, rect->h*pitch);
    1.18 -    data->glReadPixels(rect->x, rect->y+rect->h-1, rect->w, rect->h,
    1.19 +    data->glReadPixels(rect->x, (window->h-rect->y)-rect->h, rect->w, rect->h,
    1.20                         format, type, pixels);
    1.21  
    1.22 -#if 0
    1.23      /* Flip the rows to be top-down */
    1.24      length = rect->w * bytes_per_pixel(pixel_format);
    1.25      src = (Uint8*)pixels + (rect->h-1)*pitch;
    1.26 @@ -1293,9 +1291,10 @@
    1.27          SDL_memcpy(tmp, dst, length);
    1.28          SDL_memcpy(dst, src, length);
    1.29          SDL_memcpy(src, tmp, length);
    1.30 +        dst += pitch;
    1.31 +        src -= pitch;
    1.32      }
    1.33      SDL_stack_free(tmp);
    1.34 -#endif
    1.35  
    1.36      return 0;
    1.37  }