| Summary: | SDL_RenderReadPixels appears to be broken (OpenGL) | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Jonas Thiem <contact> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 2.0 | ||
| Hardware: | x86 | ||
| OS: | Linux | ||
| Attachments: | Screenshot function output | ||
Can you try the latest snapshot? http://www.libsdl.org/tmp/SDL-1.3.zip Also, you probably need to pass r.w*3 in as the last parameter to SDL_RenderReadPixels() |
Created attachment 617 [details] Screenshot function output I tried to implement a screenshot function like this (using latest SDL 1.3, last hg pull today): void graphics_GetScreenRawRGB24(void** pointer) { //obtain the screen data for a screenshot or similar things #ifdef SDL13 //compose rectangle over whole screen SDL_Rect r; memset(&r,0,sizeof(r)); r.x = 0; r.y = 0; r.w = graphics_GetWindowWidth(); r.h = graphics_GetWindowHeight(); //allocate 32bit RGB raw data buffer *pointer = malloc(r.w*r.h*3); if (!*pointer) { //allocation failed :( return; } //obtain raw pixel data if (SDL_RenderReadPixels(mainrenderer, &r, SDL_PIXELFORMAT_RGB888, *pointer, 0) != 0) { //it didn't work for some reason free(*pointer); *pointer = NULL; return; } //ok print this out! at least a part of it int x,y; y = 0; while (y < r.h) { x = 0; while (x < r.h) { if (x < 30 && y < 150) { char s[5]; snprintf(s, 4, "%d", ((char*)*pointer)[(y*r.w)+x]); int amount = 3-strlen(s); while (amount > 0) { printf(" "); amount--; } printf("%s",s); } x++; } if (y < 150) { printf("[EOL]\n"); } y++; } #else //not implemented for SDL 1.2 *pointer = NULL; #endif } If I call this function (I tried at a random point, directly before calling SDL_RenderPresent() and directly after calling SDL_RenderPresent()), I end up with a seemingly black image with some weird pattern at the bottom (see attachment: the rows at the very bottom are actually not #000000 but some sort of three color pattern, increase contrast to see). (The graphical output is actually quite colourful and not fully black at any part of the screen for more than 1-2 pixels) The "ok print this out! at least a part of it" prints out some data right after screenshotting, to confirm it is actually as black coming directly of SDL as it also is in the final image generated by the image saving code. And indeed it is. Either SDL_RenderReadPixels() is broken, or I am using it wrongly.