Recommended Posts

Hi Guys,
Recently I incorporated a Screenshot function into my tech demo.
The problem I am having is that when I take a screenshot everything is copied into the created .png image apart from any HUD images/textures I have set on the screen (these are also .png).
It seems like it is only drawing the 3d scene into the screenshot and leaving out 2d stuff. I am taking a screenshot of the backbuffer, is this my problem? If so how can I solve it?
Heres my code:

AH DAMN!! THanks Steve, just realised when I was going to actually copy the code here that I am calling it before I draw the HUD in my render function.I will change it to appear just before Present!

Another question I wanted to ask was about the FPS, I am calling my FPS function straight after:

d3ddev->Present(NULL, NULL, NULL, NULL); // This will get the frames per second GetFPS();

I will show my FPS function below, but what my problem is that I am getting around the region of 33 fps everytime? All I am doing in my program is calling a few .x meshes and rotating them. Is their a reason why my FPS is low? Because I have seen similar tutorial demos, and in them I get FPS of about 220 or even one demo at 700fps.

I know this question is probably very awkward to answer as it depends on a lot of things but do you have any sujjesstions?

Here is my code:

// Gets and displays the Frames Per Secondvoid GetFPS(){// Hold the number of frames per second in between secondsstaticfloat FPS = 0.0f;

// Check if a second has passedfloat nextSecond = 0.0f;

// Last second that occuredstaticfloat prevSecond = 0.0f;

// Add to the frames per second every time this function is called FPS++;

// Get the second in millisecond then convert to seconds (by multiplying 0.001) nextSecond = GetTickCount() * 0.001f;

// If the time we have now substracted from the previous second is greater than// or equal to 1 (i.e. if a second has passed) then we display the FPS numberif(nextSecond - prevSecond > 1.0f) {// Make the second we just got the previous second for next time the function is called prevSecond = nextSecond;

Why? Since you're not using it after you take the screenshot, you may as well release it as soon as you're done with it. This will also help prevent any mistakes; for example if you forget to call CleanD3D() every time you take a screenshot.

It's a bit complicated, but it uses QPC for quick frames (Since it's more accurate), and timeGetTime for slower ones. If QPC returns rubbish (Which it can do on dual-core CPUs with no CPU driver, and laptops), it falls back to timeGetTime(). And it also averages the FPS over 16 frames to stop it jumping around wildly.

Why? Since you're not using it after you take the screenshot, you may as well release it as soon as you're done with it. This will also help prevent any mistakes; for example if you forget to call CleanD3D() every time you take a screenshot.

Share this post

Link to post

Share on other sites

Original post by Evil SteveGetTickCount() is extremely inaccurate, it's only got a granularity of about 25ms. So if a frame takes under 25ms, it'll report a time of 0ms.

You should use QueryPerformanceCounter instead, or timeGetTime (QPC has it's own issues).

Here's my timer class (Which may have bugs of its own [smile]):

Header:*** Source Snippet Removed ***

Source code:*** Source Snippet Removed ***

It's a bit complicated, but it uses QPC for quick frames (Since it's more accurate), and timeGetTime for slower ones. If QPC returns rubbish (Which it can do on dual-core CPUs with no CPU driver, and laptops), it falls back to timeGetTime(). And it also averages the FPS over 16 frames to stop it jumping around wildly.

Thanks Steve.

I did try using timeGetTime aswell last night, but it gave me the same result!

Your timer class looks highly complicated, but when I get home tonight (currently at work) I will try it out and see if I can understand and incorporate it into my demo.

Are you actually calling your begin and end functions in the render function, like how I called mine after ->Present()?

Do you use this timer class just for the FPS, or is it used for other things too?

Where Loop() does all the game logic and rendering. I only use the timer for keeping track of FPS currently, but there's no reason it couldn't be used for anything else - although you'd probably want to remove the frame time averaging code.

Quote:

Original post by NadsAlso in your header file you have:

PTimer();~PTimer();

its probably a very beginner question but whats the ~ stand for?

The first function is the constructor, which is called when the object is created (And used to initialise any member variables and state). The second one (~PTimer) is the destructor, which is called when the object is destroyed (When it goes out of scope or it's deleted), and is used to clean up after the object.For example, a rendering class might call IDirect3DDevice9::Release() from the destructor to make sure that the device was always cleaned up.

0

Share this post

Link to post

Share on other sites

Did you call timeBeginPeriod(1); ? That increases the accuracy of timeGetTime() (Called from the constructor in my class).

No I didnt try that but will do tonight. But even then how much can it increase it by?? As I mentioned earlier I was getting about 33FPS, where I am expecting atleast over 100FPS. To me it just feels like I was doing the function wrong although i did take tips from many tutorials. Hence I dont think timeBeginPeriod(1) could fix it by that much (although I could be wrong and therefore will try it!)

Thanks for explaining about the deconstructor, it isnt something I had come across before but will also read up on it now that i know what it is.

0

Share this post

Link to post

Share on other sites

Original post by NadsNo I didnt try that but will do tonight. But even then how much can it increase it by?? As I mentioned earlier I was getting about 33FPS, where I am expecting atleast over 100FPS. To me it just feels like I was doing the function wrong although i did take tips from many tutorials. Hence I dont think timeBeginPeriod(1) could fix it by that much (although I could be wrong and therefore will try it!)

From the timeGetTime docs: "Windows NT/2000: The default precision of the timeGetTime function can be five milliseconds or more, depending on the machine." 5ms would give you a max FPS of 200FPS though, so I would have thought the default should be fine.