Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BiGF00T

how can i make screenshots from my fullscreen game?

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

normally i can make screenshots just by pressing the print key and then copy them into photoshop or paint... today i wanted to send a pic of my work to a friend but all i get after the printkeypress+pastetophotoshop is the normal windows desktop that is _behind_ my dxwindow why? and how can i make screenshots of my game? at the current state it doesnt matter because there is not much to see but that doesnt matter... sooner or later i''ll need screenshots! thx BiGF00T

Share this post


Link to post
Share on other sites
Advertisement
Thats tight, but now i hafta ask (because frankly i was wanting to do the same thing) what you think the best way of storing the last number screenshot, in an ini? somehow searching the folder and finding the highest number? (another thing im curious about, how do u know whats in a folder without knowing the file names of everything? )
-Dan

Share this post


Link to post
Share on other sites
maybe u could make a screenshot folder and simply count the files in there.. or the ini file thing.. or something else but these 2 seem to be not too hard to make

Share this post


Link to post
Share on other sites
I wrote an article and had a complete screen shot system setup with watermarking, video, low res screen shots, hi-res screen shots, and it supported DirectX and OpenGL (It didn''t use glGetPixels() or GetFrontBuffer()), but they never posted it!?!

Anyway, I created a "Screen Shot Manager" that handled all of that. It''s something simple, but can be tricky.

Here''s the code of how I did it:

Function to see if a certain screen shot exsists:


//------------------------------------------------------------------------------------------------

//--

//--ScreenShotExists(*)

//--Version: 1.0

//--

//------------------------------------------------------------------------------------------------

bool SCREENSHOTSYSTEM::ScreenShotExists(const char* Filename)
{
WIN32_FIND_DATA FindData;
//

//--Make sure a valid filename is passed in

if(Filename == NULL)
{
//--Not valid, return false

return false;
}
//

//--Try to find the file

HANDLE FileHandle = FindFirstFile(Filename, &FindData);
//

//--If the file handle turned out to be INVALID_HANDLE_VALUE,

//--then the screen shot does not exist

bool Exists = (FileHandle != INVALID_HANDLE_VALUE ? true : false);
//

//--Close the file

FindClose(FileHandle);
//

//--Return the result

return Exists;
}


Function to strip the directory off:


//------------------------------------------------------------------------------------------------

//--

//--StripDirectoryFromFilename(*)

//--Version: 1.0

//--

//------------------------------------------------------------------------------------------------

void SCREENSHOTSYSTEM::StripDirectoryFromFilename(char* Filename)
{
char Buffer[256];
//

//--Make sure a valid filename is passed in

if(Filename == NULL)
{
return;
}
else
{
//--Copy the filename to the buffer

sprintf(Buffer, "%s", Filename);
}
//

//--See if the filename contains a directory separator

char* InString = strrchr(Buffer, ''\\'');
//

//--It does

if(InString)
{
//--Copy the file title to the filename

strcpy(Filename, (InString + 1));
return;
}
//

//--See if the filename contains this kind of directory seperator

InString = strrchr(Buffer, ''/'');
//

//--It does

if(InString)
{
//--Copy the file title to the filename

strcpy(Filename, (InString + 1));
}
}


Functions to strip the extension off:


//------------------------------------------------------------------------------------------------

//--

//--StripExtensionFromFilename(*)

//--Version: 1.0

//--

//------------------------------------------------------------------------------------------------

void SCREENSHOTSYSTEM::StripExtensionFromFilename(char* Filename)
{
int Position = 0;
char Extension[5];
char Buffer[256];
//

//--If the filename is valid and it length is >= 4

if(Filename && strlen(Filename) >= 4)
{
//--Copy the last 4 characters the the extension

strcpy(Extension, &Filename[strlen(Filename) - 4]);
//

//--Add the null terminator

Extension[strlen(Extension)] = ''\0'';
}
else
{
//--Not valid, return

return;
}
//

//--If it has a valid extension on it

if(Extension[0] == ''.'')
{
//--Loop through every character except the extension

for(unsigned int ID = 0; ID < strlen(Filename) - 4; ID++)
{
//--Copy the current character to the buffer

Buffer[Position] = Filename[ID];
//

//--Accumulate the buffer position

Position++;
}
//

//--Add the null terminator

Buffer[Position] = ''\0'';
//

//--Copy the modified character array to the filename

strcpy(Filename, Buffer);
}
}


And the heart of the whole thing:


//------------------------------------------------------------------------------------------------

//--

//--GetValidFilename(*)

//--Version: 1.0

//--

//------------------------------------------------------------------------------------------------

void SCREENSHOTSYSTEM::GetValidFilename(char* ValidFilename, char* Filename, bool InMovieMode)
{
int NewIndex = 1;
//

//--Make sure the filenames are valid

if(ValidFilename == NULL || Filename == NULL)
{
return;
}
//

if(InMovieMode == true)
{
//--Try this filename to see if it exists

sprintf(ValidFilename, "Screen Shots\\%s.avi", Filename);
}
else
{
//--Try this filename to see if it exists

sprintf(ValidFilename, "Screen Shots\\%s.bmp", Filename);
}
//

//--See if this screen shot already exists

if(ScreenShotExists(ValidFilename) == true)
{
//--Keep looping until we get a valid filename

while(ScreenShotExists(ValidFilename) == true)
{
if(InMovieMode == true)
{
//--Create the new filename as discussed in the article _[###]

sprintf(ValidFilename, "Screen Shots\\%s_%0003d.avi", Filename, NewIndex);
}
else
{
//--Create the new filename as discussed in the article _[###]

sprintf(ValidFilename, "Screen Shots\\%s_%0003d.bmp", Filename, NewIndex);
}
//

//--Accumulate the index

NewIndex++;
}
}
}


Then to use just call it like this:

void SCREENSHOTSYSTEM::SnapScreenShot(char* Filename, SCREENSHOTRESOLUTION& Resolution, int ResolutionID, bool UseTransparentColor, WATERMARKTRANSPARENTCOLOR& TransparentColor)
{
char* ValidFilename = new char[1024];
char* TempFilename = new char[1024];
//

//--Validate the filenames

if(Filename == NULL || ValidFilename == NULL || TempFilename == NULL)
{
return;
}
//

//--Copy the filename

strcpy(TempFilename, Filename);
//

//--Strip the directory off of the filename if one exists

StripDirectoryFromFilename(TempFilename);
//

//--Strip the file extension off of the filename if one is on there

StripExtensionFromFilename(TempFilename);
//

//--Get a valid filename to save the screen shot to

GetValidFilename(ValidFilename, TempFilename);
//

//--Snap the screen shot and save it using the

//--ValidFilename. This will rename the files like:

//--SShot001.bmp, SShot002.bmp, SShot003.bmp, etc. in

//--a directory called "Screen Shots"



-UltimaX-
Ariel Productions

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
BTW, heres a few examples of what it will do:
If you type:
SnapScreenShot("SomeFolder\\SomeFolder2\\SShot.bmp");

And you save 4 screen shots you will end up with:
Screen Shots\SShot.bmp
Screen Shots\SShot_001.bmp
Screen Shots\SShot_002.bmp
Screen Shots\SShot_003.bmp


:OR:
If you type:
SnapScreenShot("SShot.bmp"); and your in movie mode, you'll get:
Screen Shots\SShot.avi
Screen Shots\SShot_001.avi
Screen Shots\SShot_002.avi
Screen Shots\SShot_003.avi

It's not the best, but it works pretty good. When you actually publish the game the users wont choose the directory to save them so thats why I defaulted them to the "Screen Shots" directory.

EDIT
Forgot the '_' Ooops

Best of luck,
-UltimaX-
Ariel Productions

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on February 29, 2004 10:07:56 PM]

Share this post


Link to post
Share on other sites

  • 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!