Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

video_base.cpp

00001 //FILE:         video_base.cpp
00002 //AUTHOR:       Nathan Cournia <nathan@cournia.com>
00003 
00004 #include <iostream>
00005 #include "video_base.h"
00006 
00008 void 
00009 video_base::render_string( real_t &x, real_t &y, const gl::ttf *font, 
00010         real_t size, const std::string& text )
00011 {
00012         //sanity check on font
00013         assert( font );
00014         
00015         //map the virtual resolution to the real resolution
00016         real_t scale = m_width / 1024.0;
00017         x *= scale;
00018         y *= scale;
00019         size *= scale;
00020 
00021         //do we need to enable 2d mode
00022         if( m_2d_enabled > 0 ) {
00023                 //render the string
00024                 font->render_string( x, y, size, text );
00025         } else {
00026                 //enable 2d mode
00027                 enable_2d( );
00028 
00029                 //render the string
00030                 font->render_string( x, y, size, text );
00031 
00032                 //back to 3d mode
00033                 disable_2d( );
00034         }
00035 
00036         //map x and y coords back to virtual coords
00037         scale = 1 / scale;
00038         x *= scale;
00039         y *= scale;
00040 }
00041 
00043 void 
00044 video_base::render_shadowed_string( real_t &x, real_t &y, const gl::ttf *font, 
00045         real_t size, real_t shadow, const std::string& text )
00046 {
00047         //sanity check on font
00048         assert( font );
00049         
00050         //map the virtual resolution to the real resolution
00051         real_t scale = m_width / 1024.0;
00052         x *= scale;
00053         y *= scale;
00054         size *= scale;
00055         shadow *= scale;
00056 
00057         //save the x and y values
00058         real_t x_save = x;
00059         real_t y_save = y;
00060 
00061         //save the current color
00062         float color[ 4 ];
00063         glGetFloatv( GL_CURRENT_COLOR, color );
00064 
00065         //do we need to enable 2d mode
00066         if( m_2d_enabled > 0 ) {
00067                 //render the shadow
00068                 x += shadow; y -= shadow;
00069                 glColor4f( 0.0, 0.0, 0.0, 0.9 );
00070                 font->render_string( x, y, size, text );
00071                 
00072                 //render the string
00073                 x = x_save; y = y_save;
00074                 glColor4fv( color );
00075                 font->render_string( x, y, size, text );
00076         } else {
00077                 //enable 2d mode
00078                 enable_2d( );
00079 
00080                 //render the shadow
00081                 x += shadow; y -= shadow;
00082                 glColor4f( 0.0, 0.0, 0.0, 0.9 );
00083                 font->render_string( x, y, size, text );
00084                 
00085                 //render the string
00086                 x = x_save; y = y_save;
00087                 glColor4fv( color );
00088                 font->render_string( x, y, size, text );
00089 
00090                 //back to 3d mode
00091                 disable_2d( );
00092         }
00093 
00094         //map x and y coords back to virtual coords
00095         scale = 1 / scale;
00096         x *= scale;
00097         y *= scale;
00098 }
00099 
00101 void 
00102 video_base::render_image( const rectf& rect, const gl::texture& texture )
00103 {
00104         //sanity check on texture
00105         assert( texture );
00106         
00107         //map the virtual resolution to the real resolution
00108         real_t scale = m_width / 1024.0;
00109         rectf r = rect;
00110         r.scale( scale );
00111 
00112         //do we need to enable 2d mode
00113         if( m_2d_enabled > 0 ) {
00114                 //render the image
00115                 gl::render_image( r, texture );
00116         } else {
00117                 //enable 2d mode
00118                 enable_2d( );
00119 
00120                 //render the image
00121                 gl::render_image( r, texture );
00122 
00123                 //back to 3d mode
00124                 disable_2d( );
00125         }
00126 }

Generated on Tue Feb 11 18:49:42 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002