Sign in to follow this  
Trigger9k

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

Recommended Posts

Trigger9k    104
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
Fruny    1658
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
Trigger9k    104
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
Fruny    1658
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this