proj home

Files   Classes   Functions   Hierarchy  

framerate< period > Class Template Reference

Display a Glut applications framerate. More...

#include <graphmisc.h>

Collaboration diagram for framerate< period >:

List of all members.

Public Member Functions

 framerate (float xpos_=0.1, float ypos_=0.05)
 xpos and ypos position the framebuffer text.
void update ()
 Call in idle function.
void display ()
 Call inside general display routine.

Public Attributes

float xpos
 Position x: [0,1.0].
float ypos
 Position y: [0,1.0].


Detailed Description

template<int period = 500>
class framerate< period >

Display a Glut applications framerate.

Usage
Call framerate::display() from within the display function. Call framerate::update() from the idle function.

Definition at line 277 of file graphmisc.h.


Constructor & Destructor Documentation

template<int period = 500>
framerate< period >::framerate ( float  xpos_ = 0.1,
float  ypos_ = 0.05 
) [inline]

xpos and ypos position the framebuffer text.

Without scaling a 2.0 by 2.0 square with origin at center.

Definition at line 293 of file graphmisc.h.

00293                                                :
00294     frame(0), time(0), timebase(0), fps(0.0), xpos(xpos_), ypos(ypos_) {}


Member Function Documentation

template<int period = 500>
void framerate< period >::display (  )  [inline]

Call inside general display routine.

Keeps count off and displays the frame rate.

Definition at line 319 of file graphmisc.h.

References framerate< period >::xpos, and framerate< period >::ypos.

Referenced by helixtestscope::helixtest::display01(), and integration< D, F >::draw().

00320   {
00321     //assuming GL_MODELVIEW
00322     glPushMatrix(); //save
00323     glLoadIdentity(); //clear
00324 
00325     myLightingTurnOff temp2;
00326 
00327     glMatrixMode(GL_PROJECTION);
00328     glPushMatrix(); //save
00329     glLoadIdentity(); //clear
00330     //gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
00331     gluOrtho2D(0.0, 1.0, 0.0, 1.0);
00332     glMatrixMode(GL_MODELVIEW);
00333 
00334     ++frame;
00335 
00336     glColor3f(0.0,1.0,0.0);
00337 
00338 //cout << SHOW(xpos) << " " << SHOW(ypos) << endl;
00339 
00340     glRasterPos2f(xpos,ypos);
00341     //glRasterPos2f(0.8,0.2);
00342 
00343 //cout << SHOW(sr) << endl;
00344     int len = sr.length();
00345     for (int i = 0; i < len; ++i)
00346       glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, sr[i]);
00347 
00348     glMatrixMode(GL_PROJECTION);
00349     glPopMatrix(); //restore
00350     glMatrixMode(GL_MODELVIEW);
00351     glPopMatrix(); //restore
00352   }

template<int period = 500>
void framerate< period >::update (  )  [inline]

Call in idle function.

Definition at line 297 of file graphmisc.h.

Referenced by animate(), and helixtestscope::helixtest::idle03().

00298   {
00299     // glutGet(GLUT_ELAPSED_TIME) returns the time in millisecond units. 
00300     //   1unit=1ms
00301     time = glutGet(GLUT_ELAPSED_TIME);
00302 
00303     // Has a period passed? 
00304     if (time - timebase > period ) 
00305     {
00306       fps = frame*((GLfloat)period)/(time-timebase);
00307       timebase = time;    
00308       frame = 0;
00309 
00310       stringstream ss;
00311       ss << fps;
00312       sr = ss.str();
00313       sr += "fps";
00314     }
00315   }


Member Data Documentation

template<int period = 500>
float framerate< period >::xpos

Position x: [0,1.0].

Definition at line 287 of file graphmisc.h.

Referenced by framerate< period >::display().

template<int period = 500>
float framerate< period >::ypos

Position y: [0,1.0].

Definition at line 289 of file graphmisc.h.

Referenced by framerate< period >::display().


The documentation for this class was generated from the following file:

Generated on Fri Mar 4 00:49:57 2011 for Chelton Evans Source by  doxygen 1.5.8