It is currently Tue Oct 24, 2017 2:28 am

All times are UTC - 5 hours




 Page 1 of 1 [ 7 posts ] 
Author Message
 Post subject: Taking a screenshot
PostPosted: Mon Dec 30, 2013 5:02 pm 

Joined: Mon Jun 11, 2012 11:43 am
Posts: 27
Hey everyone.
I'm trying to take a screenshot using a command in the console.
Only when I open up the saved screenshot, it turns out with odd colors.
Here is a screenshot taken with the code: https://dl.dropboxusercontent.com/u/37193337/test.bmp
Here is the code for the screenshot command:

//take a screenshot
   if (strcmp(szInputLower,"screenshot")==0) {
      _snprintf_s(m_consoleParam.szOutput,99,99,"Screenshot saved!");
      m_consoleParam.bError = false;

      //take screenshot code using the FreeImage library
      //Make the BYTE array, factor of 3 because it's RBG.
      int width = 1024;
      int height = 768;
      BYTE* pixels = new BYTE[ 3 * width * height];

      glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);

      //Convert to FreeImage format & save to file
      FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels, width, height, 3 * width, 24, 0x0000FF, 0xFF0000, 0x00FF00, false);
      FreeImage_Save(FIF_BMP, image, "test.bmp", 0);

      //Free resources
      FreeImage_Unload(image);
      delete [] pixels;

      return;
   }


This is using the FreeImage library.


Offline
 Profile  
 
 Post subject: Re: Taking a screenshot
PostPosted: Fri Jan 17, 2014 5:06 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
I saw this post last year and I was going to reply but I was doing something at the time so I wasn't able to. Then I forgot about it until today.

Anyway, if you look at the output of your screenshot you'll notice that the Red and Blue channels are reversed and that is why things look a little weird. If you swap those then your image will look correct.


Offline
 Profile  
 
 Post subject: Re: Taking a screenshot
PostPosted: Sat Jan 18, 2014 7:22 am 

Joined: Mon Jun 11, 2012 11:43 am
Posts: 27
I tried changing this line where it's converting it to the FreeImage format and then saving it, but with no luck.
Also tried changing the color codes in the header file of FreeImage, no change there.
(green seems to be fine, though)


Offline
 Profile  
 
 Post subject: Re: Taking a screenshot
PostPosted: Sat Jan 18, 2014 12:01 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
I opened your image in photoshop and I can see that if I swap the red with blue channels then everything looks okay. Now I've never used the Freeimage library so I'm not sure what it is doing under the hood, but I would guess that changing your glReadPixels call to use GL_BGR instead of GL_RGB should fix the problem.


Offline
 Profile  
 
 Post subject: Re: Taking a screenshot
PostPosted: Sat Jan 18, 2014 3:35 pm 

Joined: Mon Jun 11, 2012 11:43 am
Posts: 27
I tried that as well, but it gives me an error. (undeclared identifier)


Offline
 Profile  
 
 Post subject: Re: Taking a screenshot
PostPosted: Sat Jan 18, 2014 6:17 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
Have a look here for a solution to that problem: http://www.gamedev.net/topic/297183-inv ... el-values/


Offline
 Profile  
 
 Post subject: Re: Taking a screenshot
PostPosted: Sun Jan 19, 2014 5:27 am 

Joined: Mon Jun 11, 2012 11:43 am
Posts: 27
Changing the glReadPixels call from GL_BGR to GL_BGR_EXT worked.

The code is now:
//take a screenshot
   if (strcmp(szInputLower,"screenshot")==0) {
      _snprintf_s(m_consoleParam.szOutput,99,99,"Screenshot saved!");
      m_consoleParam.bError = false;

      //take screenshot code using the FreeImage library
      //Make the BYTE array, factor of 3 because it's RBG.
      int width = 1024;
      int height = 768;
      BYTE* pixels = new BYTE[ 3 * width * height];

      glReadPixels(0, 0, width, height, GL_BGR_EXT , GL_UNSIGNED_BYTE, pixels);

      //Convert to FreeImage format & save to file
      FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels, width, height, 3 * width, 24, 0, 0, 0, false);
      FreeImage_Save(FIF_BMP, image, "test.bmp", 0);

      //Free resources
      FreeImage_Unload(image);
      delete [] pixels;

      return;
   }

Thanks for your help! :)


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron