Save Screenshot Library for Irrlicht with Directx9

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
ilbuzzo
Posts: 71
Joined: Sat Mar 05, 2005 4:00 pm
Location: Italy

Save Screenshot Library for Irrlicht with Directx9

Post by ilbuzzo »

Hi Guys,
As explained in .Net Poser by Il Buzzo topic I'm releasing a library written by me to save screenshots from irrlicht with Directx9 device.
You just need to pass SExposedData with dimension of control to my function and the game is done, a file dialog request to save will pop up to let you save where you want.
You can find this library at the following address:
http://www.ilbuzzo.net/downloads/SaveIrrDx9Lib.zip
it contains static version (you need Microsoft SDK, Directx9 SDK and libc.lib to link) and dynamic version (DLL) (nothing needed apart Irrlicht) plus include file.
These libraries are written in c++ and compiled with Visual C++ Toolkit 2003, but DLL will be suitable for all windows compilers (not tested yet ;)).
I'm going to implement OpenGL too as soon as possible..
Bye All.
Other
Posts: 85
Joined: Fri Dec 03, 2004 5:41 pm
Contact:

Re: Save Screenshot Library for Irrlicht with Directx9

Post by Other »

ilbuzzo wrote: I'm going to implement OpenGL too as soon as possible..
Bye All.
cool!!! :D
My Irrlicht&ODE-Project: http://www.lofing.de/myworld/
Mancuso Raffaele
Posts: 70
Joined: Sat Dec 17, 2005 4:43 pm
Location: licata (AG) italy
Contact:

Post by Mancuso Raffaele »

I prefer to use this function written by me that works on all windows device (directx8,directx9,opengl,irrlicht software and apfelbaum software)(but this function just works on windows).
To compile it, get DIBAPI from here

You can compile DIBAPI as a static library or as a dynamic library

NOTE: this function automatic add the ".bmp" extension at the file name. This function is stable,it doesn't crash and ,if the file exist, this function save the screen with the name file1.bmp. if file1.bmp exist, it saves the screen with the name file2.bmp, etc...

however, your library is excellent.

the code of my function is below.

example of use of my function :

Code: Select all

//this exsample capture the portion of the screen comprised between 0,0 //and 800,600
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = 800;
rect.bottom = 600;
CaptureTheCurrentScreen(device,"image",rect);
//save the current screen with the name image.bmp, or image1.bmp if image.bmp exist, or image2.bmp if image1.bmp exist, etc.....
do you want capure all the screen (and not a portion of it)? use CaptureTheCurrentScreen(device,"image");

This is the source of the function:

Code: Select all

#include <windows.h>
#include "dibapi.h"
#include <irrlicht.h>
using namespace irr;
#include <string>
#inlcude <sstream>
using namespace std;

RECT GetScreenResolution() {

  RECT screenrect;
   HDC hDC = CreateDC("DISPLAY", NULL, NULL, NULL);

  screenrect.left = screenrect.top = 0;
  screenrect.right = GetDeviceCaps(hDC, HORZRES);
  screenrect.bottom = GetDeviceCaps(hDC, VERTRES);

  /* Delete our DC */
  DeleteDC(hDC);
  return screenrect
}

template<class Num>string NumericString(Num num) {
       ostringstream stringa;
        stringa<<num;
        return stringa.str();
}

void CaptureTheCurrentScreen(IrrlichtDevice* device,string name_of_file,RECT screenrect)
{
	
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	/* get the bitmap */
	HDIB dib = CopyScreenToDIB(&screenrect);
	/* save the bitmap in a file */
	int number = 0;
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	for(;; number++)
	{
	       string file = name_of_file + NumericString(number) ".bmp";

	if(device->getFileSystem()->existFile(file.c_str()) == false)
	{
	 /* if the file does not exist save it */
	if(SaveDIB(dib, (char *) file.c_str()) != 0)
	{
	MessageBox(NULL, "errore!", "errore", MB_OK |MB _SYSTEMMODAL);
	}
             break;
}
}
/* destroy the DIB */
DestroyDIB(dib);
}
void CaptureTheCurrentScreen(IrrlichtDevice* device,string name_of_file) {
   CaptureTheCurrentScreen(device,name_of_file,GetScreenResolution());
}
What do you think? :D
Guest

Post by Guest »

Mancuso Raffaele wrote: What do you think? :D
I think it's very handy if it means I can avoiding linking in DXhelper files and works across the board.

I just have one question - does it capture the front buffer , and therfore will capture antialiased screenshots if antialiasing is enabled? (if so, great - if not I will stick to the other code I have working)

cheers
Mancuso Raffaele
Posts: 70
Joined: Sat Dec 17, 2005 4:43 pm
Location: licata (AG) italy
Contact:

Post by Mancuso Raffaele »

this function capture all that you can see in the portion of the screen or in all screen (use GetScreenResolution()) that you capture. so if antialiasing is set and it works (not all videocard support antialiasing), the code capture the screen with antialiasing. if videocard not support antialiasing, it doesn't work in your game, and the code capture the screen without antialiasing.
the function capture all that there is into the screen (or a portion of it,if your game is windowed) in the moment that the function start.
Post Reply