Archived

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

Help Showing FPS

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

Yes i checked it but i can''t understand because it updates many things else framerate, and it requires "dxutil.h" when i click Project on Menu then "Add to Project" and then files and then i include "dxutil.cpp & dxutil.h" but when i compile it says FatalError, cannot include file dxutil.h,
what''s this, i have the files even in same directory some times it didn''t find them aslo!

Share this post


Link to post
Share on other sites
Heres what I use, it''s common.


static float Frame = 0.0f;
static float LastTime = 0.0f;
float CurrentTime = GetTickCount() * 0.001f;

++Frame;
if(CurrentTime - LastTime > 1.0f)
{
FPS = Frame / (CurrentTime - LastTime);
LastTime = CurrentTime;
Frame = 0;
}


-UltimaX-

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

Share this post


Link to post
Share on other sites
All went fine but i how to display the FPS to the screen, when i want to write it using DirectFont object it says cannot conver parameter one from float to char, same is the case with writing it to log!

Is there any function to convert FPS float to a char??

THANKS!

Share this post


Link to post
Share on other sites
Yeah, here you go:


char strFPS[15];
static float Frame = 0.0f;
static float LastTime = 0.0f;
float CurrentTime = GetTickCount() * 0.001f;
//--

++Frame;
if(CurrentTime - LastTime > 1.0f)
{
FPS = Frame / (CurrentTime - LastTime);
LastTime = CurrentTime;
sprintf(strFPS, "FPS: %.02f", FPS);
Frame = 0;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just use sprintf() to convert from floating to char string. For example, sprintf( szFPS, "FPS: %f", fFPS ). Or make FPS an int and use itoa().

Share this post


Link to post
Share on other sites
You're welcome

-UltimaX-

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

[edited by - UltimaX on July 6, 2003 9:49:42 PM]

Share this post


Link to post
Share on other sites
@UltimaX

we are programming a RPS(Role Playing Strategy), and we need some programmers!, can you please join us, we have our own FTP server, there we keep our files!

Can you tell me your skills please:

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
why are you programming an rts if you don''t know how to convert strings to ints... shouldn''t you learn the basics first?

Share this post


Link to post
Share on other sites
ha, that''s why i am inviting good programmers!, i am not the programemr in the project, i am 3D Modeler, but i can do much programming, i am also the designer of the project!

Share this post


Link to post
Share on other sites
quote:
Original post by UltimaX
Yeah, here you go:


float CurrentTime = GetTickCount() * 0.001f;
//--

++Frame;
if(CurrentTime - LastTime > 1.0f)



one little detail that shouldnt matter if you do anything worthwhile in your frames:
floats have limited precision (well, ok, so does gettickcount, so its already quite "off"). for very small numbers you might kill the little precision thats left by making it even smaller (*0.001) and short timespans will end up 0. so in general i would rather do
float CurrentTime = GetTickCount();
if(CurrentTime - LastTime > 1000)

in this case i wouldnt expect any difference, but whenever you work with really small floats i guess its better to make numbers bigger rather than even smaller.

Share this post


Link to post
Share on other sites
I would but I have been working on my game engine for over a year now. I finally got to where I have different rendering engines in seperate .dll's. So now if you want OpenGL you just call Initialize(XRE_OPENGL, ...), if you want Direct3D just call Initialize(XRE_DIRECT3D, ...). The engine bases the texture system, material system, font system, etc off of what rendering engine was choosen automatically. Kinda cool.

Trienco:
Thanks for the tip. I don't do anything with the FPS besides show them anyway. I use a seperate timer for all the time based movements, task system, etc. By timer I mean using the performance counter not WM_TIMER. (I'm thinking about changing it to ASM so I can get the CPU ticks, not sure though...)

EDIT:
Greg, I'm pretty sure you were a begginer at one time. So why knock people that want help? At least they're wanting to learn and sticking to it. Would you rather they just quit programming and give up? Please try to keep your comments constructive.

DivineLight: I'm not saying your a begginer because I know nothing about your programming history. So don't take it the wrong way.

-UltimaX-

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

[edited by - UltimaX on July 7, 2003 10:35:42 AM]

Share this post


Link to post
Share on other sites