Sign in to follow this  
Ganoosh_

Screenshots? FBO?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites

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;
}



Share this post


Link to post
Share on other sites
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!)

Share this post


Link to post
Share on other sites
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...:)

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
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?


I got around those types of problems by limiting my loader and saver to 24-bit bitmaps. Good point though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this