Jump to content
  • Advertisement
Sign in to follow this  
Trigger9k

Printing the FPS.........without it being erased

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

Hello guys. I'm having some trouble. I know how to calculate the amonut of frames per second and printint it out but since I flip the buffer after rendering and clear the screen before rendering I'm having a hard time keeping the font on screen. Here is the code :
GLvoid CTimer::PrintFPS( GLfloat const & p_X, GLfloat const & p_Y )
{

     std::ostringstream ss;

     static GLdouble Framerate = 0.0;
     static GLdouble Start = 0.0;
     GLdouble Now = 0.0;
     
     ++Framerate;
     Now = glfwGetTime( );     
     
     if( Now - Start > 1.0 )
     {
     
        Start = Now;
        
        ss << "FPS : " << (GLuint)Framerate;
        m_Font.Print( ss.str().c_str(), p_X, p_Y );
        
        Framerate = 0.0;
     }
}

Since I call this function every frame it gets erased and prints back onto the screen. I just want to be able to keep it on the screen. Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
Save the result of the computation to a global (or member) variable and move the actual printing to within your frame rendering function, where it will not be erased.

Share this post


Link to post
Share on other sites
Thanx it works.

I have another question that may be a little off topic.

Local variables get pushed into heap memory right?

And what is the name of the type of memory beside heap?(I think its called stack memory where global variables go to?)

Share this post


Link to post
Share on other sites
Quote:
Original post by Trigger9k
Local variables get pushed into heap memory right?


No, they're on the stack.

Quote:
And what is the name of the type of memory beside heap?(I think its called stack memory where global variables go to?)


A program has a few different memory areas - one for static/global variables (I can't remember it having any particular name), one for local variables (the stack, where each function's stack frame is pushed when the function is called and popped when the function returns) and the free store (for dynamically allocated memory - new and delete) - known to some as "the heap".

Share this post


Link to post
Share on other sites
Sign in to follow this  

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