Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed GL_RenderReadPixels() - thanks Ryan!
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 18, 2009
1 parent 3bbf955 commit 9de246c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/video/SDL_renderer_gl.c
Expand Up @@ -1257,6 +1257,7 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
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;
Expand All @@ -1276,13 +1277,10 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
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;
Expand All @@ -1293,9 +1291,10 @@ memset(pixels, 0xff, rect->h*pitch);
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;
}
Expand Down

0 comments on commit 9de246c

Please sign in to comment.