make framerate display work in *nix
This commit is contained in:
parent
3230b9283f
commit
9ff8b1dc98
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "config_audio.h"
|
||||
#include "audio_sound.h"
|
||||
#include "audio_gui_functor.h"
|
||||
#include <dconfig.h>
|
||||
#include <filename.h>
|
||||
#include <load_dso.h>
|
||||
|
|
@ -32,6 +33,7 @@ int audio_thread_priority;
|
|||
|
||||
ConfigureFn(config_audio) {
|
||||
AudioSound::init_type();
|
||||
AudioGuiFunctor::init_type();
|
||||
|
||||
Config::ConfigTable::Symbol mode;
|
||||
config_audio.GetAll("audio-mode-flag", mode);
|
||||
|
|
|
|||
|
|
@ -22,3 +22,6 @@ ConfigureFn(config_glxdisplay) {
|
|||
glxGraphicsWindow::make_GlxGraphicsWindow);
|
||||
glxDisplay::init_type();
|
||||
}
|
||||
|
||||
bool gl_show_fps_meter = config_glxdisplay.GetBool("show-fps-meter", false);
|
||||
float gl_fps_meter_update_interval = max((float)0.5,config_glxdisplay.GetFloat("fps-meter-update-interval", 1.7));
|
||||
|
|
|
|||
|
|
@ -11,5 +11,7 @@
|
|||
|
||||
NotifyCategoryDecl(glxdisplay, EXPCL_PANDAGL, EXPTP_PANDAGL);
|
||||
|
||||
extern bool gl_show_fps_meter;
|
||||
extern float gl_fps_meter_update_interval;
|
||||
|
||||
#endif /* __CONFIG_GLXDISPLAY_H__ */
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ const char* glxGraphicsWindow::_glx_extensions = NULL;
|
|||
#define MOUSE_ENTERED 0
|
||||
#define MOUSE_EXITED 1
|
||||
|
||||
#define FONT_BITMAP_OGLDISPLAYLISTNUM 1000 // some arbitrary #
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Constructor
|
||||
// Access:
|
||||
|
|
@ -65,6 +67,9 @@ glxGraphicsWindow::~glxGraphicsWindow(void)
|
|||
// unmake_current();
|
||||
// glXDestroyContext(_display, _context);
|
||||
|
||||
if (gl_show_fps_meter)
|
||||
glDeleteLists(FONT_BITMAP_OGLDISPLAYLISTNUM, 128);
|
||||
|
||||
XDestroyWindow(_display, _xwindow);
|
||||
if (_colormap)
|
||||
XFreeColormap(_display, _colormap);
|
||||
|
|
@ -472,6 +477,22 @@ void glxGraphicsWindow::config( void )
|
|||
// to configure itself in the gsg
|
||||
make_current();
|
||||
make_gsg();
|
||||
|
||||
if (gl_show_fps_meter) {
|
||||
// 128 handles all the ascii chars
|
||||
// this creates a display list for each char. displist numbering starts
|
||||
// at FONT_BITMAP_OGLDISPLAYLISTNUM. Might want to optimize just to save
|
||||
// mem by just allocating bitmaps for chars we need (0-9,f,p,s,SPC)
|
||||
XFontStruct* foo;
|
||||
// I /know/ there has to be a way to get a useful handle to the default
|
||||
// font, but I have to date been unable to find one
|
||||
foo = XLoadQueryFont(_display, "-*-*-*-*-*--12-*-*-*-*-*-*-*");
|
||||
glXUseXFont(foo->fid, 0, 128, FONT_BITMAP_OGLDISPLAYLISTNUM);
|
||||
_start_time = ClockObject::get_global_clock()->get_real_time();
|
||||
_start_frame_count = 0;
|
||||
_cur_frame_count = 0;
|
||||
_current_fps = 0.;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -593,6 +614,52 @@ void glxGraphicsWindow::setup_properties(void)
|
|||
////////////////////////////////////////////////////////////////////
|
||||
void glxGraphicsWindow::end_frame( void )
|
||||
{
|
||||
if (gl_show_fps_meter) {
|
||||
ClockObject* co = ClockObject::get_global_clock();
|
||||
double now = co->get_real_time();
|
||||
double time_delta = now - _start_time;
|
||||
if (time_delta > gl_fps_meter_update_interval) {
|
||||
double num_frames = _cur_frame_count - _start_frame_count;
|
||||
_current_fps = num_frames / time_delta;
|
||||
_start_time = now;
|
||||
_start_frame_count = _cur_frame_count;
|
||||
}
|
||||
char fps_msg[20];
|
||||
sprintf(fps_msg, "%7.02f fps", _current_fps);
|
||||
glColor3f(0., 1., 1.);
|
||||
GLboolean tex_was_on = glIsEnabled(GL_TEXTURE_2D);
|
||||
if (tex_was_on)
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadMatrixf(LMatrix4f::ident_mat().get_data());
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadMatrixf(LMatrix4f::ident_mat().get_data());
|
||||
|
||||
glOrtho(_props._xorg,_props._xorg+_props._xsize,
|
||||
_props._yorg,_props._yorg+_props._ysize,-1.0,1.0);
|
||||
|
||||
// these seem to be good for default font
|
||||
glRasterPos2f(_props._xsize-75,_props._ysize-20);
|
||||
|
||||
// set up for a string-drawing display list call
|
||||
glListBase(FONT_BITMAP_OGLDISPLAYLISTNUM);
|
||||
|
||||
// draw a string using font display lists. chars index their
|
||||
// corresponding displist name
|
||||
glCallLists(strlen(fps_msg), GL_UNSIGNED_BYTE, fps_msg);
|
||||
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
if(tex_was_on)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
_cur_frame_count++; // only used by fps meter right now
|
||||
}
|
||||
|
||||
{
|
||||
PStatTimer timer(_swap_pcollector);
|
||||
glXSwapBuffers(_display, _xwindow);
|
||||
|
|
|
|||
|
|
@ -100,6 +100,12 @@ private:
|
|||
int _entry_state;
|
||||
bool _ignore_key_repeat;
|
||||
|
||||
// fps meter stuff
|
||||
double _start_time;
|
||||
long _start_frame_count;
|
||||
long _cur_frame_count;
|
||||
float _current_fps;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type(void);
|
||||
static void init_type(void);
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ public:
|
|||
GuiBehavior::init_type();
|
||||
register_type(_type_handle, "GuiChooser",
|
||||
GuiBehavior::get_class_type());
|
||||
ChooseFunctor::init_type();
|
||||
}
|
||||
virtual TypeHandle get_type(void) const {
|
||||
return get_class_type();
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ public:
|
|||
GuiBehavior::init_type();
|
||||
register_type(_type_handle, "GuiListBox",
|
||||
GuiBehavior::get_class_type());
|
||||
ListFunctor::init_type();
|
||||
}
|
||||
virtual TypeHandle get_type(void) const {
|
||||
return get_class_type();
|
||||
|
|
|
|||
Loading…
Reference in New Issue