Screenshots

Why when I try and grab a screenshot of an SDL window (under Linux) do
I get the following when I press the “grab” button in ‘xv’?—
X Error: BadAccess (attempt to access private resource denied)
Major Opcode: 28

And if I try The Gimp, it tells me “can’t open file as XWD file”.

I’m running Xfree 4.2.1, and have an NVIDIA card that’s using the
binary NVIDIA drivers.


Garlic gum is not funny

PGP Fingerprint [6AD6 865A BF6E 76BB 1FC2 E4C4 DEEA 7D08 D511 E149]
PGP Public key [www.piku.org.uk/public-key.asc] - Home [www.piku.org.uk]

Is this window OpenGL, by chance?On Sat, Jun 22, 2002 at 01:15:17PM +0100, James wrote:

Why when I try and grab a screenshot of an SDL window (under Linux) do
I get the following when I press the “grab” button in ‘xv’?


Joseph Carter The guy with a rocket launcher

  • Knghtbrd crosses his toes
    (if I crossed my fingers it would be hard to type)

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020622/cfafd831/attachment.pgp

| On Sat, Jun 22, 2002 at 01:15:17PM +0100, James wrote:
| > Why when I try and grab a screenshot of an SDL window (under Linux) do
| > I get the following when I press the “grab” button in ‘xv’?
|
| Is this window OpenGL, by chance?

No… I created it with:

screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_DOUBLEBUF);

I did have it as “SDL_HWSURFACE” and that didn’t work either. Is it the
double-buffering? And if so, why?On Sat, Jun 22, 2002 at 05:57:11AM -0700, Joseph Carter wrote:


I will stop talking about the twelve inch pianist

PGP Fingerprint [6AD6 865A BF6E 76BB 1FC2 E4C4 DEEA 7D08 D511 E149]
PGP Public key [www.piku.org.uk/public-key.asc] - Home [www.piku.org.uk]

James wrote:>On Sat, Jun 22, 2002 at 05:57:11AM -0700, Joseph Carter wrote:

| On Sat, Jun 22, 2002 at 01:15:17PM +0100, James wrote:
| > Why when I try and grab a screenshot of an SDL window (under Linux) do
| > I get the following when I press the “grab” button in ‘xv’?
|
| Is this window OpenGL, by chance?

No… I created it with:

screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_DOUBLEBUF);

I did have it as “SDL_HWSURFACE” and that didn’t work either. Is it the
double-buffering? And if so, why?

Just give your program some shortcut that will save the screen using
SDL_SabeBMP(…)
More info here: http://sdldoc.csn.ul.ie/sdlsavebmp.php

Marius

James wrote:

| On Sat, Jun 22, 2002 at 01:15:17PM +0100, James wrote:
| > Why when I try and grab a screenshot of an SDL window (under Linux) do
| > I get the following when I press the “grab” button in ‘xv’?
|
| Is this window OpenGL, by chance?

And how to take a screen shot with SDL OpenGL Surface?On Sunday 23 June 2002 01:23, you wrote:

On Sat, Jun 22, 2002 at 05:57:11AM -0700, Joseph Carter wrote:


The only thing worse than X Windows: (X Windows) - X

| Is this window OpenGL, by chance?

And how to take a screen shot with SDL OpenGL Surface?

http://www.libsdl.org/pipermail/sdl/2000-September/030013.html

This has code for copying data from OpenGL to an SDL surface, from which
SDL_SaveBMP can be used to save the code.From: danny.linux@gmx.net (Danny Angelo Carminati Grein)
Subject: Re: [SDL] Screenshots

How’s this? (Quick and dirty…)

SDL_bool
Screenshot (char *name)
{
SDL_Surface *scr;
Uint8 *buf;
size_t imgsize, writesize;
FILE *f;

scr = SDL_GetVideoSurface ();

imgsize = scr->w * scr->h * 3 + 18 + 26;
buf = calloc (1, imgsize);
if (!buf)
    return SDL_FALSE;

/* Fill in the necessary bits of the header - RTF Targa spec! */
buf[2] = 0x02;		/* F3, uncompressed truecolor */
buf[12] = (scr->w & 255);	/* F5.3, width, little endian */
buf[13] = (scr->w >> 8);
buf[14] = (scr->h & 255);	/* F5.4, height, little endian */
buf[15] = (scr->h >> 8);
buf[16] = 24;		/* F5.5, bpp */

// Fill in the pixel data
glReadPixels (0, 0, scr->w, scr->h, GL_BGR, GL_UNSIGNED_BYTE,
        &buf[18]);

/* Fill in the image footer and file ID */
strcpy (&buf[imgsize - 18], "TRUEVISION-XFILE.");

/* Spit out the file */
f = fopen (name, "wb");
if (!f)
{
    free (buf);
    return SDL_FALSE;
}

writesize = fwrite (buf, imgsize, 1, f);

free (buf);
fclose (f);

if (writesize == imgsize)
    return SDL_TRUE;

return SDL_FALSE;

}

Caveats: I didn’t even TRY to explain the Targa header fields. If you
want to know what they are, go to wotsit and download the Targa 2.0 spec.
Note that the two high bits of Field 5.6 have been assigned a use, but
AFAIK not by Truevision, and I’ve never seen a reference implementation
which used them… Targa supports a lot of optional fields which I don’t
set in this function.

Why not read the pixels into another SDL_Surface? Three reasons: SDL with
or without SDL_image can only write Windows BMP, glReadPixels’ output is
bottom-to-top as all OpenGL image data is (as anyone who has tried to
upload SDL_Surfaces as textures has already discovered for themselves),
and it’s positively confusing to go back and forth between the pixel
format namings used by SDL which uses Uint32s for pixel data (and
therefore cares about endianness) and OpenGL which doesn’t. If you want
to make it work with a SDL_Surface, you’ll have to flip the image line by
line and keep in mind that on little-endian machines, what OpenGL calls
BGR is RGB when you’re talking to SDL…

One more note about using GL_BGR - it requires OpenGL 1.2. It exists as
an extension in, as far as I can tell, all Win32 OpenGL drivers. BGR and
BGRA are the native formats used by Win32 and in fact DirectX only
supports BGRA (which IMO just as foolishly as SDL, is called “ARGB”…)

Still, it’s the only format that Targa understands, and certain drivers
(such as 3dfx in Linux until the most recent versions) will return BGR
data from glReadPixels even if you specified GL_RGB. You can either check
for the extension or 1.2 and cope gracefully when it’s not present or you
can just assume it works and expect anyone for whom it doesn’t to complain
to their card’s chipset maker about crappy drivers which are more than 4
years out of date. I never see complaints when games demand DirectX 7 or
nowadays 8, but I always get someone whining when I expect OpenGL 1.2,
especially on Win32. Go figure.On Sun, Jun 23, 2002 at 01:13:24AM -0300, Danny Angelo Carminati Grein wrote:

| > Why when I try and grab a screenshot of an SDL window (under Linux) do
| > I get the following when I press the “grab” button in ‘xv’?
|
| Is this window OpenGL, by chance?

And how to take a screen shot with SDL OpenGL Surface?


Joseph Carter If this sig were funny…

$you = new YOU;
honk() if $you->love(perl)
– Seen on Slashdot

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020623/734b52d0/attachment.pgp

Mine’s faster. And definitely not any more evil. ;)On Sun, Jun 23, 2002 at 04:46:47PM +1200, Andrew Murie wrote:

| Is this window OpenGL, by chance?

And how to take a screen shot with SDL OpenGL Surface?

http://www.libsdl.org/pipermail/sdl/2000-September/030013.html

This has code for copying data from OpenGL to an SDL surface, from which
SDL_SaveBMP can be used to save the code.


Joseph Carter Have chainsaw will travel

wow, I think I just used libtool to solve a problem – somebody
help me! :>
xtifr, STEP AWAY FROM THE KEYBOARD

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020623/cf9b01a4/attachment.pgp

And how to take a screen shot with SDL OpenGL Surface?

How’s this? (Quick and dirty…)

[code]

Why not read the pixels into another SDL_Surface?

Ouch… Im trying to capture to another SDL_Surface… that a have an class
to manipulate images… load to SDL_Surfaces and save from SDL_Surfaces.

Three reasons: SDL with
or without SDL_image can only write Windows BMP, glReadPixels’ output is
bottom-to-top as all OpenGL image data is (as anyone who has tried to
upload SDL_Surfaces as textures has already discovered for themselves),

  Hmm.. interesting.. 

and it’s positively confusing to go back and forth between the pixel
format namings used by SDL which uses Uint32s for pixel data (and
therefore cares about endianness) and OpenGL which doesn’t. If you want
to make it work with a SDL_Surface, you’ll have to flip the image line by
line and keep in mind that on little-endian machines, what OpenGL calls
BGR is RGB when you’re talking to SDL…

One more note about using GL_BGR - it requires OpenGL 1.2. It exists as
an extension in, as far as I can tell, all Win32 OpenGL drivers. BGR and
BGRA are the native formats used by Win32 and in fact DirectX only
supports BGRA (which IMO just as foolishly as SDL, is called “ARGB”…)

Thank you, this is very usefull for me. 

[]'sOn Sunday 23 June 2002 07:32, you wrote:

Danny Angelo Carminati Grein wrote:>On Sunday 23 June 2002 01:23, you wrote:

James wrote:

On Sat, Jun 22, 2002 at 05:57:11AM -0700, Joseph Carter wrote:
| On Sat, Jun 22, 2002 at 01:15:17PM +0100, James wrote:
| > Why when I try and grab a screenshot of an SDL window (under Linux) do
| > I get the following when I press the “grab” button in ‘xv’?
|
| Is this window OpenGL, by chance?

And how to take a screen shot with SDL OpenGL Surface?

http://cone3d.gamedev.net/cgi-bin/index.pl?page=code/shotta