K3dFontBmp.h

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #pragma once
00034 
00035 #include "../System/Builder/K3dTextureBuild.h"
00036 #include "../MathCore/K3dVector3.h"
00037 #include "../MathCore/K3dVector4.h"
00038 #include "../MathCore/K3dMatrix.h"
00039 #include "../Geometry/K3dCameraObj.h"
00040 #include "../System/GameData/K3dGameData.h"
00041 #include "K3dBmpFontObj.h"
00042 #include "../Script/K3dLua.h"
00043 #include "../System/K3dTimer.h"
00044 
00045 class K3dFontBmp
00046 {
00047                 K3dGameData *m_pGameData;       
00048 
00049                 struct TDraw
00050                 {
00051                         char str[256];
00052                         K3dVector3 kColor;
00053                 };
00054                 int m_iNumDraw;
00055                 TDraw m_atDraw[64];
00056 
00057                 //char m_strFilename[256];      ///< Bmp font filename
00058                 GLuint m_uiTextureId;   
00059                 GLuint m_uiBase;        
00060                 bool m_bNewFrame;       
00061                 int m_iNumLines;        
00062                 int m_iLine;    
00063                 float m_fFirstLine;     
00064                 float m_afLine[64];     
00065                 float m_fSpace; 
00066                 float m_fRow;   
00067                 bool m_bDraw;   
00068                 bool m_bDrawFps;        
00069                 K3dVector3 m_kCamera;   
00070                 bool m_bDrawCamPos;     
00071                 bool m_bDrawNumFaces;   
00072                 int m_iFps;
00073                 int m_iFpsTmp;
00074                 int m_iFrame;
00075 
00077                 void Print ( const char *_strIn, K3dVector3 _kColor );
00079                 void DrawFps();
00081                 void DrawCameraPosition();
00083                 void DrawNumFaces();
00084 
00085 
00086         public:
00087                 K3dFontBmp ( K3dGameData *_pGameData );
00088                 ~K3dFontBmp ( void );
00089                 void LoadBmpFonts();
00090 
00093                 void SetFrame ( const bool _bFrame )
00094                 {
00095                         m_bNewFrame = _bFrame;
00096                 }
00099                 bool GetFrame()
00100                 {
00101                         return m_bNewFrame;
00102                 }
00103 
00106                 void SetNumLines ( const int _iNumLines )
00107                 {
00108                         m_iNumLines = _iNumLines;
00109                 }
00112                 int GetNumLines()
00113                 {
00114                         return m_iNumLines;
00115                 }
00116 
00119                 void SetFirstLine ( const float _fFirstLine )
00120                 {
00121                         m_fFirstLine = _fFirstLine;
00122                 }
00125                 float GetFirstLine()
00126                 {
00127                         return m_fFirstLine;
00128                 }
00129 
00132                 void SetSpace ( const float _fSpace )
00133                 {
00134                         m_fSpace = _fSpace;
00135                 }
00138                 float GetSpace()
00139                 {
00140                         return m_fSpace;
00141                 }
00142 
00145                 void SetRow ( const float _fRow )
00146                 {
00147                         m_fRow = _fRow;
00148                 }
00151                 float GetRow()
00152                 {
00153                         return m_fRow;
00154                 }
00155 
00158                 void SetDrawFps ( const bool _bDrawFps )
00159                 {
00160                         cout << "void K3dFontBmp::SetDrawFps()" << endl;
00161                         m_bDrawFps = _bDrawFps;
00162                 }
00165                 bool GetDrawFps()
00166                 {
00167                         return m_bDrawFps;
00168                 }
00169 
00173                 void SetCamera ( K3dVector3 _kCamera )
00174                 {
00175                         m_kCamera = _kCamera;
00176                 }
00177 
00180                 void SetDrawCamPos ( const bool _bDrawCamPos )
00181                 {
00182                         cout << "void K3dFontBmp::SetDrawCamPos(const bool _bDrawCamPos)" << endl;
00183                         m_bDrawCamPos = _bDrawCamPos;
00184                 }
00187                 bool GetDrawCamPos()
00188                 {
00189                         return m_bDrawCamPos;
00190                 }
00191 
00194                 void SetDrawNumFaces ( const bool _bDrawNumFaces )
00195                 {
00196                         cout << "void K3dFontBmp::SetDrawNumFaces(const bool _bDrawNumFaces)" << endl;
00197                         m_bDrawNumFaces = _bDrawNumFaces;
00198                 }
00200                 bool GetDrawNumFaces()
00201                 {
00202                         return m_bDrawNumFaces;
00203                 }
00204 
00205 
00206 
00207                 void InitFontBmp();
00208                 void Reset();
00209                 void Destroy();
00210                 void DeleteFontBmp();
00211                 void DrawFontBmp();
00212 
00213 
00215                 void DrawValue ( const char *_strComment );
00217                 void DrawValue ( const char *_strComment, const K3dVector3 _kVec );
00219                 void DrawValue ( const char *_strComment, const K3dVector4 _kVec );
00221                 void DrawValue ( const char *_strComment, const float _fVal );
00223                 void DrawValue ( const char *_strComment, const int _iVal );
00225                 void DrawValue ( const K3dMatrix _kMat );
00227                 void ResetLines()
00228                 {
00229                         m_iLine = m_iNumLines;
00230                 }
00231 
00233                 //void SetFilename(const char *_strFilename);
00235                 void LoadTexture ( const K3dString &_strFileName );
00237                 void CreateDisplayLists ( bool _bItalic );
00239                 void ResetValues()
00240                 {
00241                         ResetLines();
00242                         m_bNewFrame = true;
00243                 }
00244 
00245 };
00246 /*
00249         inline void K3dFontBmp::SetFilename(const char *_strFilename)
00250         {
00251                 cout << "void K3dFontBmp::SetFilename()" << endl;
00252                 cout << "_strFilename = " << _strFilename << endl;
00253                 strcpy(m_strFilename, _strFilename);
00254         }*/
00255 
00257 inline void K3dFontBmp::LoadTexture ( const K3dString &_strFileName )
00258 {
00259         cout << "void K3dFontBmp::LoadTexture()" << endl;
00260         // Set texture id
00261         //m_uiTextureId = CreateTexture(_strFileName.GetString().c_str());
00262         cout << "void K3dFontBmp::LoadTexture() -- CreateTexture -- OK" << endl;
00263 }
00264 
00265 
00267 inline void K3dFontBmp::DrawCameraPosition()
00268 {
00269         K3dVector3 kColor;
00270         char acString[20];
00271 
00272         TTextureOption *ptOption = m_pGameData->GetTextureOption();
00273 
00274         if ( ptOption->bMultitexture )
00275         {
00276                 /*
00277                 // Active first texture of multitexture
00278                 glActiveTextureARB(GL_TEXTURE1_ARB);
00279                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00280                 // Active second texture of multitexture
00281                 glActiveTextureARB(GL_TEXTURE0_ARB);
00282                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00283                 */
00284         }
00285         else                                                                                                    // Jinak
00286         {
00287                 //if(glIsEnabled(GL_TEXTURE_2D))                // Jestlie je zapnuto texturov��                            glDisable(GL_TEXTURE_2D);                                                       // Vypni texturov��         }
00288         }
00289 
00290         // Get active camera index
00291         int iCamId = m_pGameData->GetActiveCamId();
00292         if ( iCamId>=0 )
00293         {
00294                 // Get active camera
00295                 K3dCameraObj *pCamera = m_pGameData->GetCameraObjSP().Get ( iCamId );
00296                 if ( !pCamera )
00297                 {
00298                         cerr << "void K3dFontBmp::DrawCameraPosition() -- Error - Pointer to camera object is NULL!!" << endl;
00299                         return;
00300                 }
00301                 kColor.Set ( 0,1,0 );
00302                 snprintf ( acString, 20, "%s%f", "Cam X: ", pCamera->GetCameraPos() [0] );
00303                 Print ( acString, kColor );
00304                 snprintf ( acString, 20, "%s%f", "Cam Y: ", pCamera->GetCameraPos() [1] );
00305                 Print ( acString, kColor );
00306                 snprintf ( acString, 20, "%s%f", "Cam Z: ", pCamera->GetCameraPos() [2] );
00307                 Print ( acString, kColor );
00308         }
00309 }
00310 
00312 inline void K3dFontBmp::DrawNumFaces()
00313 {
00314         int iNum = 0;
00315         K3dVector3 kColor;
00316         char acString[20];
00317 
00318         TTextureOption *ptOption = m_pGameData->GetTextureOption();
00319 
00320         if ( ptOption->bMultitexture )                                  // Jestlie je zapnut mutlitexturing
00321         {
00322                 /*
00323                 // Active first texture of multitexture
00324                 glActiveTextureARB(GL_TEXTURE1_ARB);
00325                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00326                 // Active second texture of multitexture
00327                 glActiveTextureARB(GL_TEXTURE0_ARB);
00328                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00329                 */
00330         }
00331         else                                                                                                    // Jinak
00332         {
00333                 iNum = m_pGameData->NumDrawTriangles();
00334                 kColor.Set ( 0,1,0 );
00335                 snprintf ( acString, 20, "%s%i", "Triangles: ", iNum );
00336                 Print ( acString, kColor );
00337         }
00338 }
00339 
00343 inline void K3dFontBmp::DrawValue ( const char *_strComment, const K3dVector3 _kVec )
00344 {
00345         K3dVector3 kColor;
00346         char acString[200];
00347         TTextureOption *ptOption = m_pGameData->GetTextureOption();
00348         if ( ptOption->bMultitexture )                                  // Jestlie je zapnut mutlitexturing
00349         {
00350                 /*
00351                 // Active first texture of multitexture
00352                 glActiveTextureARB(GL_TEXTURE1_ARB);
00353                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00354                 // Active second texture of multitexture
00355                 glActiveTextureARB(GL_TEXTURE0_ARB);
00356                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00357                 */
00358         }
00359         else                                                                                                    // Jinak
00360         {
00361                 //if(glIsEnabled(GL_TEXTURE_2D))                // Jestlie je zapnuto texturov��                            glDisable(GL_TEXTURE_2D);                                                       // Vypni texturov��         }
00362         }
00363         kColor.Set ( 0,1,1 );
00364         snprintf ( acString, 200, "%s %f %f %f", _strComment, _kVec.GetX(), _kVec.GetY(), _kVec.GetZ() );
00365         Print ( acString, kColor );
00366 }
00367 
00371 inline void K3dFontBmp::DrawValue ( const char *_strComment, K3dVector4 _kVec )
00372 {
00373         K3dVector3 kColor;
00374         char acString[200];
00375         float *pV;
00376         K3dVector4 kV;
00377 
00378         kV = _kVec;
00379 
00380         pV = kV.GetVector();
00381 
00382         TTextureOption *ptOption = m_pGameData->GetTextureOption();
00383 
00384         if ( ptOption->bMultitexture )                          // Jestlie je zapnut mutlitexturing
00385         {
00386                 /*
00387                 // Active first texture of multitexture
00388                 glActiveTextureARB(GL_TEXTURE1_ARB);
00389                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00390                 // Active second texture of multitexture
00391                 glActiveTextureARB(GL_TEXTURE0_ARB);
00392                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00393                 */
00394         }
00395         else                                                                                                    // Jinak
00396         {
00397                 //if(glIsEnabled(GL_TEXTURE_2D))                // Jestlie je zapnuto texturov��                            glDisable(GL_TEXTURE_2D);                                                       // Vypni texturov��         }
00398         }
00399         kColor.Set ( 0,1,1 );
00400         snprintf ( acString, 200, "%s %f %f %f %f", _strComment, pV[0], pV[1], pV[2], pV[3] );
00401         Print ( acString, kColor );
00402 }
00403 
00405 inline void K3dFontBmp::DrawValue ( const char *_strComment, const float _fVal )
00406 {
00407         K3dVector3 kColor;
00408         char acString[200];
00409 
00410         TTextureOption *ptOption = m_pGameData->GetTextureOption();
00411 
00412         if ( ptOption->bMultitexture )                                  // Jestlie je zapnut mutlitexturing
00413         {
00414                 /*
00415                 // Active first texture of multitexture
00416                 glActiveTextureARB(GL_TEXTURE1_ARB);
00417                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00418                 // Active second texture of multitexture
00419                 glActiveTextureARB(GL_TEXTURE0_ARB);
00420                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00421                 */
00422         }
00423         else                                                                                                    // Jinak
00424         {
00425                 //if(glIsEnabled(GL_TEXTURE_2D))                // Jestlie je zapnuto texturov��                            glDisable(GL_TEXTURE_2D);                                                       // Vypni texturov��         }
00426         }
00427         kColor.Set ( 0,1,1 );
00428         snprintf ( acString, 200, "%s %f", _strComment , _fVal );
00429         Print ( acString, kColor );
00430 }
00431 
00432 // Draw int value to next lines
00433 inline void K3dFontBmp::DrawValue ( const char *_strComment, const int _iVal )
00434 {
00435         K3dVector3 kColor;
00436         char acString[200];
00437 
00438         TTextureOption *ptOption = m_pGameData->GetTextureOption();
00439 
00440         if ( ptOption->bMultitexture )                                  // Jestlie je zapnut mutlitexturing
00441         {
00442                 /*
00443                 // Active first texture of multitexture
00444                 glActiveTextureARB(GL_TEXTURE1_ARB);
00445                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00446                 // Active second texture of multitexture
00447                 glActiveTextureARB(GL_TEXTURE0_ARB);
00448                 if(!glIsEnabled(GL_TEXTURE_2D))         // Jestlie je vypnuto texturov��                    glEnable(GL_TEXTURE_2D);                                                        // Zapni texturov��                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);             // Nastav b�ou texturu
00449                 */
00450         }
00451         else                                                                                                    // Jinak
00452         {
00453                 //if(glIsEnabled(GL_TEXTURE_2D))                // Jestlie je zapnuto texturov��                            glDisable(GL_TEXTURE_2D);                                                       // Vypni texturov��         }
00454         }
00455         kColor.Set ( 0,1,1 );
00456         snprintf ( acString, 200, "%s %i", _strComment , _iVal );
00457         Print ( acString, kColor );
00458 }
00459 
00460 // Draw matrix value to next lines
00461 inline void K3dFontBmp::DrawValue ( const K3dMatrix _kMat )
00462 {
00463         K3dVector3 kColor;
00464         char acString[200];
00465         float *pM;
00466         K3dMatrix kM;
00467 
00468         kM = _kMat;
00469         pM = kM.GetMatrix();
00470 
00471         TTextureOption *ptOption = m_pGameData->GetTextureOption();
00472 
00473         if ( ptOption->bMultitexture )
00474         {
00475                 /*
00476                 // Active first texture of multitexture
00477                 glActiveTextureARB(GL_TEXTURE1_ARB);
00478                 if(!glIsEnabled(GL_TEXTURE_2D))         glEnable(GL_TEXTURE_2D);
00479                 glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);
00480                 // Active second texture of multitexture
00481                 glActiveTextureARB(GL_TEXTURE0_ARB);
00482                 if(!glIsEnabled(GL_TEXTURE_2D))                                 glEnable(GL_TEXTURE_2D);                                                                        glBindTexture(GL_TEXTURE_2D, K3dTexture::m_uiWhiteTexture);
00483                 */
00484         }
00485         else                                                                                                    // Jinak
00486         {
00487                 //if(glIsEnabled(GL_TEXTURE_2D))                                                glDisable(GL_TEXTURE_2D);                                                               }
00488         }
00489 
00490         kColor.Set ( 0,1,1 );
00491         snprintf ( acString, 200, "%f %f %f %f", pM[0], pM[1], pM[2], pM[3] );
00492         Print ( acString, kColor );
00493         snprintf ( acString, 200, "%f %f %f %f", pM[4], pM[5], pM[6], pM[7] );
00494         Print ( acString, kColor );
00495         snprintf ( acString, 200, "%f %f %f %f", pM[8], pM[9], pM[10], pM[11] );
00496         Print ( acString, kColor );
00497         snprintf ( acString, 200, "%f %f %f %f", pM[12], pM[13], pM[14], pM[15] );
00498         Print ( acString, kColor );
00499 }
00500 

Generated on Thu Aug 16 23:53:26 2007 for K3dEngine by  doxygen 1.5.0