comparison 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
comparison
equal deleted inserted replaced
3446:0f969d273f65 3447:294b770c1989
1255 static int 1255 static int
1256 GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, 1256 GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1257 Uint32 pixel_format, void * pixels, int pitch) 1257 Uint32 pixel_format, void * pixels, int pitch)
1258 { 1258 {
1259 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; 1259 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
1260 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1260 GLint internalFormat; 1261 GLint internalFormat;
1261 GLenum format, type; 1262 GLenum format, type;
1262 Uint8 *src, *dst, *tmp; 1263 Uint8 *src, *dst, *tmp;
1263 int length, rows; 1264 int length, rows;
1264 1265
1274 data->glPixelStorei(GL_PACK_LSB_FIRST, 0); 1275 data->glPixelStorei(GL_PACK_LSB_FIRST, 0);
1275 } 1276 }
1276 data->glPixelStorei(GL_PACK_ALIGNMENT, 1); 1277 data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
1277 data->glPixelStorei(GL_PACK_ROW_LENGTH, 1278 data->glPixelStorei(GL_PACK_ROW_LENGTH,
1278 (pitch / bytes_per_pixel(pixel_format))); 1279 (pitch / bytes_per_pixel(pixel_format)));
1279 data->glReadBuffer(GL_FRONT); 1280
1280 1281 data->glReadPixels(rect->x, (window->h-rect->y)-rect->h, rect->w, rect->h,
1281 memset(pixels, 0xff, rect->h*pitch);
1282 data->glReadPixels(rect->x, rect->y+rect->h-1, rect->w, rect->h,
1283 format, type, pixels); 1282 format, type, pixels);
1284 1283
1285 #if 0
1286 /* Flip the rows to be top-down */ 1284 /* Flip the rows to be top-down */
1287 length = rect->w * bytes_per_pixel(pixel_format); 1285 length = rect->w * bytes_per_pixel(pixel_format);
1288 src = (Uint8*)pixels + (rect->h-1)*pitch; 1286 src = (Uint8*)pixels + (rect->h-1)*pitch;
1289 dst = (Uint8*)pixels; 1287 dst = (Uint8*)pixels;
1290 tmp = SDL_stack_alloc(Uint8, length); 1288 tmp = SDL_stack_alloc(Uint8, length);
1291 rows = rect->h / 2; 1289 rows = rect->h / 2;
1292 while (rows--) { 1290 while (rows--) {
1293 SDL_memcpy(tmp, dst, length); 1291 SDL_memcpy(tmp, dst, length);
1294 SDL_memcpy(dst, src, length); 1292 SDL_memcpy(dst, src, length);
1295 SDL_memcpy(src, tmp, length); 1293 SDL_memcpy(src, tmp, length);
1294 dst += pitch;
1295 src -= pitch;
1296 } 1296 }
1297 SDL_stack_free(tmp); 1297 SDL_stack_free(tmp);
1298 #endif
1299 1298
1300 return 0; 1299 return 0;
1301 } 1300 }
1302 1301
1303 static int 1302 static int