Archived

This topic is now archived and is closed to further replies.

Mulligan

Creating screenshots and movies

Recommended Posts

I have two questions. 1 - How can I generate screenshots in an opengl windowed application? 2 - How can I use these screenshots and combine them into a movie file?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
1 - Use glReadPixels().

2 - Save the files with a number after their name, i.e. ScreenShot00001.bmp, then open the files in numeric order in Adobe Premiere and convert all the image-files to an AVI.

Share this post


Link to post
Share on other sites
Ok, that set me in the right direction, but in the function:
glBitmap
the final parameter is a pointer to a bitmap image. How is a bitmap pointer obtained?

Share this post


Link to post
Share on other sites
quote:
Original post by Mulligan
I''m quite new to this (creating bitmaps), do you have any source code that does that?


IMHO, targa files are easier to write. A quick google will get you the exact file format. Basically, you just write a header and write the pixels (in BGR format). You should be able to fit the entire tga writting function on one screen (a couple dozen lines or so).

Share this post


Link to post
Share on other sites
Ok, I figures out how to make TARGA files (it was fairly easy), but I''m unclear of how to copy buffer data into the file itself.
I''ve tested dozens of combinations for what I have below as "???" but my targa images all appear completely black. What should these values be if I want to copy RGB data to the file?
OR are there more steps involved?
tga = fopen( str, "wb" );

WriteTargaHeader( header, tga );
/*
glReadPixels(
0,
0,
IMAGESIZE,// w
IMAGESIZE,// h
???,
???,
???);
*/
fclose( tga );

Share this post


Link to post
Share on other sites
Well, I believe I''m nearing the answer. The end result of this is generating TARGA files that aren''t right. It generates a highly distorted image which could be just garbage because I''m doing something wrong, or its the right image, just severly skewed. Here''s what I got:

bool CApplication::GenerateScreenShot()
{
Log( "CApplication::GenerateScreenShot()\n" );

const int IMAGESIZE = 500;
char str[256];

sprintf( str, "ScreenShot%d.tga", m_iCurrentScreenShot );
m_iCurrentScreenShot++;

FILE *tga;
unsigned char *Buffer = new unsigned char[IMAGESIZE * IMAGESIZE * 3];

TARGAHEADER header;

/* First, set all the fields in the header to appropriate values */
header.id_len = 0; /* no ID field */
header.map_type = 0; /* no colormap */
header.img_type = 2; /* trust me */
header.map_first = 0; /* not used */
header.map_len = 0; /* not used */
header.map_entry_size = 0; /* not used */
header.x = 0; /* image starts at (0,0) */
header.y = 0;
header.width = IMAGESIZE; /* image is 200 x 100 */
header.height = IMAGESIZE;
header.bpp = 16; /* 24 bits per pixel */
header.misc = 0x20; /* scan from upper left corner */

tga = fopen( str, "wb" );
// Writes the header for the file
WriteTargaHeader( header, tga );

glReadPixels(
0,
0,
IMAGESIZE,// w
IMAGESIZE,// h
GL_RGB,
GL_UNSIGNED_BYTE,
Buffer );

fwrite( Buffer, sizeof( unsigned char ), IMAGESIZE * IMAGESIZE * 3, tga );

fclose( tga );

delete Buffer;
return true;
}

I''m all out of rational ideas....

Share this post


Link to post
Share on other sites
Ok, here is a little pseud-code. I have this divided into two functions: one for reading the pixels from OpenGL and the other to write the file to disk.



SAVE SCREEN SHOT FUNCTION

CREATE BUFFER TO STORE PIXEL DATA
(width * height * pixel depth)


glReadPixels (x, y, width, height,
GL_RGB, GL_UNSIGNED_BYTE, buffer);

SAVE TGA FILE FUNCTION (width, height, buffer)

DELETE BUFFER

END SAVE SCREEN SHOT FUNCTION




SAVE TGA FILE FUNCTION (width, height, buffer)

OPEN FILE FOR "wb" (like you already have)

WRITE HEADER DATA (like the image type,
color mode, etc. See the targa specs
for details on what needs to be written;
I think you'll have about 12 fwrites here)

FOR EACH PIXEL IN THE BUFFER
SWAP THE PIXEL FROM RGB TO BGR FORMAT
END FOR LOOP

WRITE BUFFER TO FILE (this is just a
single fwrite call such as:
fwrite (buffer, 1, num_bytes, fileptr);

CLOSE FILE (fclose)

END SAVE TGA FILE FUNCTION


[edited by - spiffgq on September 3, 2002 7:22:23 PM]

Share this post


Link to post
Share on other sites
Some issues I''ve noticed in the code:

1) header.bpp is set to 16. RGB data corresponds to 24 bits per pixel. RGBA data corresponds to 32 bits per pixel.

2) Be sure to reorder your written data from RGB to BGR before writing to the file.

Share this post


Link to post
Share on other sites