Creating screenshots and movies

Started by
12 comments, last by Mulligan 21 years, 7 months ago
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 BUFFEREND 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]
SpiffGQ
Advertisement
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.
________________________________________________"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
I got it working! Thanks a million!
Use delete [] when deleting arrays, not plain delete.

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

This topic is closed to new replies.

Advertisement