comparison src/video/SDL_renderer_gl.c @ 3607:8b4c0320638e

Fixed GL_RenderWritePixels() - thanks Ryan!
author Sam Lantinga <slouken@libsdl.org>
date Wed, 06 Jan 2010 06:12:01 +0000
parents 0f958e527e5e
children 64ce267332c6
comparison
equal deleted inserted replaced
3606:1a4456a01995 3607:8b4c0320638e
1452 static int 1452 static int
1453 GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, 1453 GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1454 Uint32 pixel_format, const void * pixels, int pitch) 1454 Uint32 pixel_format, const void * pixels, int pitch)
1455 { 1455 {
1456 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; 1456 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
1457 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1457 GLint internalFormat; 1458 GLint internalFormat;
1458 GLenum format, type; 1459 GLenum format, type;
1460 Uint8 *src, *dst, *tmp;
1461 int length, rows;
1459 1462
1460 if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) { 1463 if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
1461 /* FIXME: Do a temp copy to a format that is supported */ 1464 /* FIXME: Do a temp copy to a format that is supported */
1462 SDL_SetError("Unsupported pixel format"); 1465 SDL_SetError("Unsupported pixel format");
1463 return -1; 1466 return -1;
1464 } 1467 }
1465 1468
1466 /* FIXME: We need to copy the data and flip it */
1467
1468 if (pixel_format == SDL_PIXELFORMAT_INDEX1LSB) { 1469 if (pixel_format == SDL_PIXELFORMAT_INDEX1LSB) {
1469 data->glPixelStorei(GL_UNPACK_LSB_FIRST, 1); 1470 data->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
1470 } else if (pixel_format == SDL_PIXELFORMAT_INDEX1MSB) { 1471 } else if (pixel_format == SDL_PIXELFORMAT_INDEX1MSB) {
1471 data->glPixelStorei(GL_UNPACK_LSB_FIRST, 0); 1472 data->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
1472 } 1473 }
1473 data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 1474 data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1474 data->glPixelStorei(GL_UNPACK_ROW_LENGTH, 1475 data->glPixelStorei(GL_UNPACK_ROW_LENGTH,
1475 (pitch / bytes_per_pixel(pixel_format))); 1476 (pitch / bytes_per_pixel(pixel_format)));
1476 1477
1477 data->glRasterPos2i(rect->x, rect->y); 1478 /* Flip the rows to be bottom-up */
1478 data->glDrawPixels(rect->w, rect->h, format, type, pixels); 1479 length = rect->h * rect->w * pitch;
1480 tmp = SDL_stack_alloc(Uint8, length);
1481 src = (Uint8*)pixels + (rect->h-1)*pitch;
1482 dst = (Uint8*)tmp;
1483 rows = rect->h;
1484 while (rows--) {
1485 SDL_memcpy(dst, src, pitch);
1486 dst += pitch;
1487 src -= pitch;
1488 }
1489
1490 data->glRasterPos2i(rect->x, (window->h-rect->y));
1491 data->glDrawPixels(rect->w, rect->h, format, type, tmp);
1492 SDL_stack_free(tmp);
1479 1493
1480 return 0; 1494 return 0;
1481 } 1495 }
1482 1496
1483 static void 1497 static void