Jump to content
  • Advertisement
Sign in to follow this  
Ganoosh_

Screenshots? FBO?

This topic is 4601 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

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
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??

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
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!