Creating screenshots and movies

Started by
12 comments, last by Mulligan 21 years, 7 months ago
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?
Advertisement
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.
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?
glBitmap? You mean glReadPixels. You have to allocate a buffer yourself using new or malloc, read the pixels, write the file, then free the buffer.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
I''m quite new to this (creating bitmaps), do you have any source code that does that?
No.

You can look at www.wotsit.org to check out some file formats, or you can look into an image library like DevIL.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
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).
SpiffGQ
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 );
Have you used new to create an array to hold your frame in?

Do that, use glReadPixels (see MSDN), then write those pixels to the file, free the array, and close the file.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
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....

This topic is closed to new replies.

Advertisement