Screenshots? FBO?

Started by
9 comments, last by kburkhart84 18 years, 6 months ago
I need to implement taking screenshots, I've tried using glReadPixels but it doesn't work very well and I've seen people saying FBO or pbuffer is the way to go. What are they, and how do I access the data? Thanks in advance
Advertisement
glReadPixels works fine for me. I've never used Pbuffers or anything else that is too complex, so that may be better. What is your problem with glReadPixels??


The image is all warped
Code and a screenshot would really help.
Make sure the buffer you read into is unsigned chars and you save it correctly. You might be messing up BGR with the correct file format RGB.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
The code I have is this
unsigned char* temp = 0;        temp = new unsigned char[(Console::settings->video->width*Console::settings->video->height)*3];        ZeroMemory(temp, sizeof(temp));        glPixelStorei(GL_PACK_ALIGNMENT, 1);        glReadPixels(0, 0, Console::settings->video->width, Console::settings->video->height,            GL_RGB, GL_UNSIGNED_BYTE, temp);        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);        BMPLoader::writeScreen(temp, Console::settings->video->width, Console::settings->video->height);        delete [] temp;        temp = 0;

BMPLoader is a class with functions to read a bmp and temporarily I have one to write a screenshot which writeScreen is.

Here's a screenshot:
void Window::takeSnapshot(){  ofstream screenShotFile;  ifstream existingFile;  char     filename[64];  int      screensCount = 0;  while(true)  {    sprintf(filename, "screenShot%03d.tga", screensCount);    existingFile.open(filename);    if(existingFile.is_open())    {      screensCount++;      existingFile.close();    }    else      break;  }  screenShotFile.open(filename, ios::binary);  if(!screenShotFile.is_open())    return;   GLubyte  TGAheader[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},           infoHeader[6],           *data = new GLubyte[4*width*height];  glReadPixels(0, 0, width, height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);  screenShotFile.write((char*)TGAheader, sizeof(TGAheader));  infoHeader[0] = (width  & 0x00FF);  infoHeader[1] = (width  & 0xFF00) >> 8;  infoHeader[2] = (height & 0x00FF);  infoHeader[3] = (height & 0xFF00) >> 8;  infoHeader[4] = 32;  infoHeader[5] = 0;  screenShotFile.write((char*)infoHeader, sizeof(infoHeader));  screenShotFile.write((char*)data, 4*width*height);  screenShotFile.close();  delete [] data;}
Quote:Original post by Ganoosh_
The code I have is this
*** Source Snippet Removed ***
BMPLoader is a class with functions to read a bmp and temporarily I have one to write a screenshot which writeScreen is.


That piece of code looks alright. Post the writeScreen function.

Or you could use JavaCoolDude's, (which, btw, is very clean and nicely coded!)
I don't think so, but the PACK and UN_PACK alignment thing I have never seen used before. It probably has nothing to do with it though. The glReadPixels looks right to me. Unles something is wrong with the bitmap saving itself. Also, I think JavaCoolDude's code saves TGA files, though there is nothing wrong with that, they are close to bitmaps. But if you don't have a program to read TGA files, then I wouldn't use that code. It is nice code though...:)


Does your BMPLoader::writeScreen() function (it's not just a loader if it saves BMPs as well [grin]) account for the 32-bit boundaries that bmp files are expected to have?

This topic is closed to new replies.

Advertisement