1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <ClanLib/core.h>
#include <ClanLib/application.h>
#include <ClanLib/display.h>
#include <ClanLib/gl.h>
class ExampleTime : public CL_ClanApplication
{
public:
virtual int main(int argc, char **argv)
{
// Create a console window for text-output if not available
CL_ConsoleWindow console("Console");
console.redirect_stdio();
try
{
// Initialize ClanLib base components
CL_SetupCore setup_core;
// Initialize the ClanLib display component
CL_SetupDisplay setup_display;
// Initilize the OpenGL drivers
CL_SetupGL setup_gl;
// Set a videomode
CL_DisplayWindow window("ClanLib Time Example", 640, 480);
CL_ResourceManager resources("resources.xml", false);
CL_Font font("font_gray", &resources);
// Class to give us the framerate
CL_FramerateCounter framerate;
// A timer that emits a signal every 2 seconds
CL_Timer timer(2000);
CL_Slot slot_timer = timer.sig_timer().connect(this, &ExampleTime::on_timer);
timer.enable();
// Call callback once to initialize variable
on_timer();
// Run until someone presses escape
while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
{
// Clear the display in a dark blue nuance
// The four arguments are red, green, blue and alpha
// All color nuances in ClanLib are measured in the interval 0->255
CL_Display::clear(CL_Color(0,0,56));
font.draw(10,10, "FPS: " + CL_String::from_int(framerate.get_fps()));
font.draw(10,30, CL_String::from_int(time_since_system_boot) + " ms since system boot (updating every 2 secs)");
// Flip the display, showing on the screen what we have drawed
// since last call to flip_display()
CL_Display::flip();
// This call updates input and performs other "housekeeping"
// call this each frame
CL_System::keep_alive();
}
}
catch(CL_Error error)
{
std::cout << "Exception caught : " << error.message.c_str() << std::endl;
// Display console close message and wait for a key
console.display_close_message();
return -1;
}
return 0;
}
void on_timer()
{
time_since_system_boot = CL_System::get_time();
}
int time_since_system_boot;
} my_app;
|