00001
00002
00003
00004 #ifndef COURNIA_VIDEO_BASE_H
00005 #define COURNIA_VIDEO_BASE_H 1
00006
00007 #include "gl.h"
00008 #include "ttf.h"
00009 #include "clocker.h"
00010
00012
00015 class video_base
00016 {
00017 protected:
00018 unsigned int m_width;
00019 unsigned int m_height;
00020 bool m_fullscreen;
00021 unsigned int m_bpp;
00022 bool m_error;
00023 std::string m_error_msg;
00024 clocker m_clock;
00025 int m_2d_enabled;
00026
00027 double m_fps;
00028 double m_avg_fps;
00029 double m_fps_sum;
00030 unsigned int m_frame_count;
00031
00033 inline void clear_error( void ) {
00034 m_error = false;
00035 m_error_msg = "none";
00036 }
00037
00039 inline void set_error( const std::string& msg ) {
00040 m_error = true;
00041 m_error_msg = msg;
00042 }
00043
00044 public:
00046 video_base( void ):
00047 m_error( false ), m_error_msg( "none" ),
00048 m_2d_enabled( 0 ),
00049 m_fps( 0.0 ), m_avg_fps( 0.0 ), m_fps_sum( 0.0 ), m_frame_count( 0 )
00050 { }
00051
00053 virtual ~video_base( void ) { };
00054
00056
00066 virtual bool init( unsigned int w, unsigned int h, unsigned int bpp,
00067 bool fs ) = 0;
00068
00070 virtual void set_title( const std::string& title ) = 0;
00071
00073 virtual void resize( unsigned int width, unsigned int height ) = 0;
00074
00076
00079 virtual void start_frame( void ) = 0;
00080
00082
00085 virtual void end_frame( void ) = 0;
00086
00088 virtual void toggle_fullscreen( void ) = 0;
00089
00091
00095 virtual void shutdown( void ) = 0;
00096
00098 inline unsigned int get_width( void ) const {
00099 return m_width;
00100 }
00101
00103 inline unsigned int get_height( void ) const {
00104 return m_height;
00105 }
00106
00108 inline bool error( void ) const {
00109 return m_error;
00110 }
00111
00113 inline std::string get_error( void ) {
00114 std::string msg( m_error_msg );
00115 clear_error( );
00116 return msg;
00117 }
00118
00120
00123 inline double get_fps( void ) const {
00124 return m_fps;
00125 }
00126
00128
00131 inline double get_average_fps( void ) const {
00132 return m_avg_fps;
00133 }
00134
00136 inline double get_elapsed( void ) const {
00137 return m_clock.elapsed( );
00138 }
00139
00141 inline bool get_2d( void ) const {
00142 return (m_2d_enabled > 0 );
00143 }
00144
00146 inline void enable_2d( void ) {
00147 ++m_2d_enabled;
00148 gl::enable_2d( m_width, m_height );
00149 }
00150
00152 inline void disable_2d( void ) {
00153 --m_2d_enabled;
00154 gl::disable_2d( );
00155 }
00156
00158
00174 void render_string( real_t &x, real_t &y, const gl::ttf *font, real_t size,
00175 const std::string& text );
00176
00178
00195 void render_shadowed_string( real_t &x, real_t &y, const gl::ttf *font,
00196 real_t size, real_t shadow_offset,
00197 const std::string& text );
00198
00200
00208 void render_image( const rectf& rect, const gl::texture& texture );
00209 };
00210
00211 #endif