We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1218 - SDL_RenderReadPixels appears to be broken (OpenGL)
Summary: SDL_RenderReadPixels appears to be broken (OpenGL)
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-07 13:39 UTC by Jonas Thiem
Modified: 2013-05-21 02:42 UTC (History)
0 users

See Also:


Attachments
Screenshot function output (1.91 KB, image/png)
2011-06-07 13:39 UTC, Jonas Thiem
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonas Thiem 2011-06-07 13:39:41 UTC
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.
Comment 1 Sam Lantinga 2012-01-07 23:45:17 UTC
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()