*
**************************************************************************/
+#include <sstream>
#include <stdexcept>
#include "dispatcher.hh"
mode(attributes_.mode);
if (!current_) make_current();
+
+ show_fps(false);
}
void video::recreate_context()
void video::caption(const std::string& caption)
{
+ caption_ = caption;
SDL_WM_SetCaption(caption.c_str(), 0);
}
-std::string video::caption() const
+const std::string& video::caption() const
{
- char* caption;
- SDL_WM_GetCaption(&caption, 0);
- return std::string(caption);
+ return caption_;
+ //char* caption;
+ //SDL_WM_GetCaption(&caption, 0);
+ //return std::string(caption);
}
}
-void video::swap()
+void video::swap(scalar t)
{
+ if (show_fps_)
+ {
+ scalar dt = t - last_swap_;
+ last_swap_ = t;
+
+ fps_accumulator_ += dt;
+ if (SCALAR(1.0) <= fps_accumulator_)
+ {
+ std::ostringstream stream;
+ stream << caption_ << " - " << fps_counter_ << " fps";
+ SDL_WM_SetCaption(stream.str().c_str(), 0);
+
+ fps_accumulator_ -= SCALAR(1.0);
+ fps_counter_ = 0;
+ }
+
+ ++fps_counter_;
+ }
+
SDL_GL_SwapBuffers();
}
settings.get("fullscreen", is_fullscreen);
settings.get("resizable", is_resizable);
settings.get("showcursor", is_cursor_visible);
- settings.get("grab", is_cursor_captured);
+ settings.get("capturecursor", is_cursor_captured);
std::vector<int> dimensions;
settings.get("videomode", dimensions);
if (modes == (SDL_Rect**)0)
{
- log_error("no native video mode");
+ throw std::runtime_error("can't find appropriate video mode");
}
else if (modes == (SDL_Rect**)-1)
{
- log_warning("any resolution allowed; "
- "choosing default 800x600");
+ log_warning("any resolution allowed; choosing default 800x600");
mode[0] = 800;
mode[1] = 600;
}
{
mode[0] = (*modes)->w;
mode[1] = (*modes)->h;
- log_info << "choosing native resolution "
- << mode[0] << "x" << mode[1] << std::endl;
+ log_info << "choosing native resolution: "
+ << mode[0] << "x" << mode[1] << std::endl;
}
}
if (dimensions.size() > 2) mode[2] = dimensions[2];