Advertisement

Screen Dump

Started by April 02, 2001 04:40 PM
14 comments, last by CRRouse 23 years, 10 months ago
Probably really simple, but how how do I capture my OpenGL screen to a file?
glReadPixels would work (read the screen into a buffer, and write that to a file)
Celeron ][ 566 @ 850256MB PC-100 CAS2 RAMDFI PA-61 Mainboard (250MB memory bandwidth sucks, it should be 500MB)ATI Radeon 32MB DDR LEWindows 98SE
Advertisement
Screenshot.h :
/*********************************/
/* THE 3DGL ENGINE - DLL VERSION */
/* (C) 2000 ----- DANNY LOUSBERG */
/*********************************/

// TAKING SCREENSHOTS -- ANSI C COMPATIBLE -> PORTABILITY 100%


#ifndef SCREENSHOT_H
#define SCREENSHOT_H

// INCLUDES
#include "Types.h"


// TYPES
typedef struct
{
unsigned char TGAheader[12];
unsigned char header[6];
} tga_header;


// EXPORTS
void ScreenShot(char*);

#endif


screenshot.c :
/*********************************/
/* THE 3DGL ENGINE - DLL VERSION */
/* (C) 2000 ----- DANNY LOUSBERG */
/*********************************/

// TAKING SCREENSHOTS -- ANSI C COMPATIBLE -> PORTABILITY 100%


// INCLUDES
#include "ScreenShot.h"


// FUNCTIONS
void ScreenShot(char* FileName) // Export the frame buffer to a .tga file
{
byte* Buffer;
FILE* TGAFile;
tga_header TGA;
byte HeightH,HeightL,WidthH,WidthL;

Buffer = calloc(Width*Height*3,sizeof(unsigned char));
glReadPixels(0,0,Width,Height,GL_BGR_EXT,GL_UNSIGNED_BYTE,Buffer);

TGAFile = fopen(FileName, "wb");


HeightH = (byte)(Height / 256);
HeightL = (byte)(Height % 256);
WidthH = (byte)(Width / 256);
WidthL = (byte)(Width % 256);
// Write TGA Header
TGA.TGAheader[0] = 0;
TGA.TGAheader[1] = 0;
TGA.TGAheader[2] = 2;
TGA.TGAheader[3] = 0;
TGA.TGAheader[4] = 0;
TGA.TGAheader[5] = 0;
TGA.TGAheader[6] = 0;
TGA.TGAheader[7] = 0;
TGA.TGAheader[8] = 0;
TGA.TGAheader[9] = 0;
TGA.TGAheader[10] = 0;
TGA.TGAheader[11] = 0;
TGA.header[0] = (byte) WidthL;
TGA.header[1] = (byte) WidthH;
TGA.header[2] = (byte) HeightL;
TGA.header[3] = (byte) HeightH;
TGA.header[4] = (byte) 24;
TGA.header[5] = 0;
fwrite(&TGA,sizeof(tga_header),1,TGAFile);
fwrite(Buffer,Width*Height*3*sizeof(unsigned char),1,TGAFile);


fclose(TGAFile);
free(Buffer);
}

straight cut & paste from my engine, dunno if it works on all hardware, so please, if you use this, tell me about how it works on different systems...
- ANSI C COMPATIBLE -> PORTABILITY 100%
byte Heig

that aint ansi
#include "Types.h"

http://members.xoom.com/myBollux
hehe, yes it is, Types.h is my own header file, containing my Vector and poly defenitions, and the likes. It has nothing to do with the msvc types.h file
I know, awkward naming, but hey; It works huh :p


Hmmm, I guess it isn't ansi, since I use // for comments...




Edited by - Flous on April 6, 2001 8:06:34 AM
Sorry it took me so long to respond, but I finally tried out your code - it worked great with only trivial modifications!

Thanks a lot

For your platform comparison - I am running an AMD Athlon 700 with a Voodoo 3 3000 with Windows 2000 Professional (Service Pack 1)and MS Visual Studio 6 - Enterprise Edition as a compiler
Advertisement
Sorry it took me so long to respond, but I finally tried out your code - it worked great with only trivial modifications!

Thanks a lot

For your platform comparison - I am running an AMD Athlon 700 with a Voodoo 3 3000 with Windows 2000 Professional (Service Pack 1)and MS Visual Studio 6 - Enterprise Edition as a compiler
Just tried it also, and with one minor typecast change it worked great. Runnig a PIII 450, with a Voodoo 3 2000
Hey, I can''t seem to get it to work. What is in your Types.h file that I need to be able to get it to work?
L.I.G. == Life Is Good
Actually, // comments are ANSI-C in the latest ANSI-C spec... ;-)
--- axelP

This topic is closed to new replies.

Advertisement