• Advertisement


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

Screen capture

This topic is 5536 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi everyone, I am thinking of doing a screen capture program, where the captured data can be saved as file or saved in memory. (using OpenGL or VC++) Could anyone enlighten me on how or what to start with? Thank you. Merry Christmas to all!

Share this post

Link to post
Share on other sites
This thread has working (windows) code to save the entire screen as a .bmp.
You have to fix a couple typos, and I guess it''s no good if you aren''t using windows/aren''t in fullscreen and only want the OpenGL window, but it works well for me.

MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It''s all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."

Share this post

Link to post
Share on other sites
I have added screen capture function into my program.
Bitmap is rather big file to save as screenshots files...
Anyway, thought all who are interested and have had given me help would like to see the codes that I use to add screen capture
into my program.

int WriteBMP(char *file, int width, int height, unsigned char *image)
// 3 parts of bmp, the info header, the file header, and the image.
// Write each one.

FILE *pFile; // file pointer.
BITMAPINFOHEADER infoHeader; // info header.
BITMAPFILEHEADER fileHeader; // file header.
int index; // index for the for loop.
unsigned char tempColors; // Use to change image from RGB to BGR.

pFile = fopen(file, "wb"); // Open the file for write.

if(!pFile) { return 0; }

// Define whats going in the infoHeader.
infoHeader.biSize = sizeof(BITMAPINFOHEADER);
infoHeader.biPlanes = 1;
infoHeader.biBitCount = 24;
infoHeader.biCompression = BI_RGB;
infoHeader.biSizeImage = width * abs(height) * 3;
infoHeader.biXPelsPerMeter = 0;
infoHeader.biYPelsPerMeter = 0;
infoHeader.biClrUsed = 0;
infoHeader.biClrImportant = 0;
infoHeader.biWidth = width;
infoHeader.biHeight = height;

// Define whats going in the file header.
fileHeader.bfSize = sizeof(BITMAPFILEHEADER);
fileHeader.bfType = 0x4D42;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

// Change image from RGB to BGR. Thats how .bmp is saved.
for(index = 0; index < infoHeader.biSizeImage; index += 3)
tempColors = image[index];
image[index] = image[index + 2];
image[index + 2] = tempColors;

// Write to the file.
// Write file header.
fwrite(&fileHeader, 1, sizeof(BITMAPFILEHEADER), pFile);

// Write info header.
fwrite(&infoHeader, 1, sizeof(BITMAPINFOHEADER), pFile);

// Write image.
fwrite(image, 1, infoHeader.biSizeImage, pFile);

// Close the file.

void SaveBMP()
{ char tring[32];
GLubyte *outputImage ;
// Allocate the neccessary memory.
outputImage = (unsigned char*)malloc(width * height * 3);

// Clear the variable.
memset(outputImage, 0, width * height * 3);

// glReadPixels() to read every pixel on the screen
// that you specify. You must use one less than each size.
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, outputImage);


// Call WriteBMP() function to write the bmp.
WriteBMP(tring, width, height, (unsigned char*)outputImage);

// Clear the allocated memory.
count +=1;

Share this post

Link to post
Share on other sites

  • Advertisement