Main Page   Namespace List   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

ExManagerWindow.cpp

Go to the documentation of this file.
00001 /*
00002  * ExNihilo 3D Engine
00003  * 
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Please read AUTHORS file !!!
00019  * 
00020  * $Id: ExManagerWindow.cpp,v 1.16 2002/08/06 16:52:59 binny Exp $
00021  *
00022  */
00023 
00024 #include "ExManagerWindow.h"
00025 
00026 ExManagerWindow::ExManagerWindow(void){
00027 Guard(ExManagerWindow::ExManagerWindow(void))
00028         m_ShowGrille=false;
00029         m_ShowNetStat=false;
00030         m_Antialliasing=true;
00031         m_Menu=false;
00032         m_Console=false;
00033         m_Interface=false;
00034         
00035         options = new ExCOptions;
00036         
00037         m_ShowFps = options->getWindowShowfps ();
00038         
00039         m_WindowSizeX = options->getWindowResolutionX ();
00040         m_WindowSizeY = options->getWindowResolutionY ();
00041         m_WindowSizeXOld = m_WindowSizeX;
00042         m_WindowSizeYOld = m_WindowSizeY;
00043         m_WindowPosX=0;
00044         m_WindowPosY=0;
00045         m_Bits = options->getWindowDepth ();
00046         m_Rate = options->getWindowRate ();
00047         m_FullScreen = options->getWindowFullscreen () ;
00048         m_OldMode=m_FullScreen;
00049         m_Cursor=GLUT_CURSOR_CROSSHAIR;
00050         m_Title=new char[strlen("ExNihilo Engine Version ")+20];
00051         sprintf(m_Title,"ExNihilo Engine Version %s",VERSION);
00052         m_IconTitle=new char[strlen("ExNihilo Engine Version ")+20];
00053         sprintf(m_IconTitle,"ExNihilo %s",VERSION);
00054         SetAntialliasingState(true);
00055         m_MotionBlurTexture=false;
00056         m_CouterEffect=0.0f;
00057 UnGuard
00058 }
00059 
00060 ExManagerWindow::~ExManagerWindow(void)
00061 {
00062 Guard(ExManagerWindow::~ExManagerWindow(void))
00063 
00064 UnGuard
00065 }
00066 
00067 void ExManagerWindow::Create(int SizeX,int SizeY,int PosX,int PosY,char *argv){
00068 Guard(ExManagerWindow::Create(int SizeX,int SizeY,int PosX,int PosY,char *argv))
00069         m_WindowSizeX=SizeX;
00070         m_WindowSizeY=SizeY;
00071         m_WindowSizeXOld=SizeX;
00072         m_WindowSizeYOld=SizeY;
00073         m_WindowPosX=PosX;
00074         m_WindowPosY=PosY;
00075         glutInitWindowPosition(m_WindowPosX,m_WindowPosY);
00076         glutInitWindowSize(m_WindowSizeX,m_WindowSizeY);                
00077         m_WindowHandler=glutCreateWindow(m_Title);
00078         glutSetIconTitle(m_IconTitle);
00079         SetCursor(m_Cursor);
00080 UnGuard
00081 }
00082 
00083 void ExManagerWindow::Create(int SizeX,int SizeY,char *argv){
00084 Guard(ExManagerWindow::Create(int SizeX,int SizeY,char *argv))
00085         m_WindowSizeX=SizeX;
00086         m_WindowSizeY=SizeY;
00087         m_WindowSizeXOld=SizeX;
00088         m_WindowSizeYOld=SizeY;
00089         glutInitWindowPosition(m_WindowPosX,m_WindowPosY);
00090         glutInitWindowSize(m_WindowSizeX,m_WindowSizeY);                
00091         m_WindowHandler=glutCreateWindow(m_Title);
00092         glutSetIconTitle(m_IconTitle);
00093         SetCursor(m_Cursor);
00094 UnGuard
00095 }
00096 
00097 void ExManagerWindow::Move(int Posx,int Posy){
00098 Guard(ExManagerWindow::Move(int Posx,int Posy))
00099         m_WindowPosX=Posx;
00100         m_WindowPosY=Posy;
00101         glutPositionWindow(Posx,Posy);
00102 UnGuard
00103 }
00104 
00105 
00106 void ExManagerWindow::SetResolution(int SizeX,int SizeY){
00107 Guard(ExManagerWindow::SetResolution(int SizeX,int SizeY))
00108         m_WindowSizeXOld=m_WindowSizeX;
00109         m_WindowSizeYOld=m_WindowSizeY; 
00110         m_WindowSizeX=SizeX;
00111         m_WindowSizeY=SizeY;
00112 UnGuard
00113 }
00114 
00115 void ExManagerWindow::SetWindowTitle(char *Title){
00116 Guard(ExManagerWindow::SetWindowTitle(char *Title))
00117         m_Title = new char[strlen(Title)];
00118         sprintf(m_Title,"%s",Title);
00119         glutSetWindowTitle(m_Title);
00120 UnGuard
00121 }
00122 
00123 void ExManagerWindow::SetIconTitle(char *Title){
00124 Guard(ExManagerWindow::SetIconTitle(char *Title))
00125         m_IconTitle=new char[strlen(Title)];
00126         sprintf(m_IconTitle,"%s",Title);
00127         glutSetIconTitle(m_IconTitle);
00128 UnGuard
00129 }
00130 
00131 void ExManagerWindow::SetCursor(int Cursor){
00132 Guard(ExManagerWindow::SetCursor(int Cursor))
00133         glutSetCursor(Cursor);
00134 UnGuard
00135 }
00136 
00137 
00138 void ExManagerWindow::Apply(void){
00139 Guard(ExManagerWindow::Apply(void))
00140         if(options->getWindowFullscreen ())
00141         {
00142                 if(m_OldMode)
00143                 {
00144                         glutDestroyWindow(m_WindowHandler);
00145                 }
00146                 char *game;
00147                 game=new char[15];
00148                 sprintf(game,"%dx%d:%d@%d",m_WindowSizeX,m_WindowSizeY,m_Bits,m_Rate);
00149                 glutGameModeString(game);
00150 #ifndef UNIX_SRC
00151                 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
00152 #else
00153                 if (glutGameModeGet(GLUT_GAME_MODE_WIDTH)) {
00154 #endif
00155                         m_WindowHandler=glutEnterGameMode();
00156                         GlutCallBack();
00157                         glutSetWindow(m_WindowHandler);
00158 
00159                 } else {
00160                         std::cout << "can not switch to fullscreen" << std::endl;
00161                 }
00162         }else
00163         {
00164                 if(m_OldMode)
00165                 {
00166                         glutLeaveGameMode();
00167                         glutInitWindowPosition(m_WindowPosX,m_WindowPosY);
00168                         glutInitWindowSize(m_WindowSizeX,m_WindowSizeY);                
00169                         m_WindowHandler=glutCreateWindow(m_Title);
00170                 }else
00171                 {
00172                         glutReshapeWindow(m_WindowSizeX,m_WindowSizeY);
00173                 }
00174         }
00175         SetAntialliasingState(m_Antialliasing);
00176 UnGuard
00177 }
00178 
00179 void ExManagerWindow::SetAntialliasingState(bool state)
00180 {
00181 Guard(void ExManagerWindow::SetAntialliasingState(bool state))
00182         m_Antialliasing=state;
00183         if(m_Antialliasing)
00184         {
00185                 glEnable(GL_LINE_SMOOTH);
00186                 glEnable(GL_BLEND);
00187                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00188                 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
00189         }else
00190         {
00191                 glDisable(GL_LINE_SMOOTH);
00192                 glDisable(GL_BLEND);
00193         }
00194 UnGuard
00195 }
00196 
00197 void ExManagerWindow::ShowFps(void)
00198 {
00199 Guard(void ExManagerWindow::ShowFps(void))
00200         glMatrixMode(GL_PROJECTION);
00201         glPushMatrix();
00202                 glLoadIdentity();
00203                 gluOrtho2D(0, GetResolutionX(), 0, GetResolutionY());
00204                 glScalef(1, -1, 1);
00205                 glTranslatef(0, -GetResolutionY(),0);
00206                 glMatrixMode(GL_MODELVIEW);
00207                 glDisable(GL_LIGHTING);
00208                 glPushMatrix();
00209                         glLoadIdentity();
00210                         glColor3f(1.0,1.0,1.0);
00211 
00212                         frame++;
00213                         timeframe=glutGet(GLUT_ELAPSED_TIME);
00214                         if (timeframe - timebase > 1000) 
00215                         {
00216                                 sprintf(s,"FPS:%4.2f",frame*1000.0/(timeframe-timebase));
00217                                 timebase = timeframe;           
00218                                 frame = 0;
00219                         }
00220 
00221                         RenderBitmapString(30,15,(void *)GLUT_BITMAP_HELVETICA_12,"ExNihilo");
00222                         RenderBitmapString(30,35,(void *)GLUT_BITMAP_HELVETICA_12,s);
00223                         char TimeSinceStart[30];
00224                         sprintf(TimeSinceStart,"Time since start:%f"
00225                                 ,(double)((double)glutGet(GLUT_ELAPSED_TIME)/1000));
00226                         RenderBitmapString(30,55,(void *)GLUT_BITMAP_HELVETICA_12,TimeSinceStart);
00227 
00228                 glPopMatrix();
00229         glMatrixMode(GL_PROJECTION);
00230         glPopMatrix();
00231         glMatrixMode(GL_MODELVIEW);
00232 UnGuard
00233 }
00234 
00235 void ExManagerWindow::MotionBlur(void)
00236 {
00237 Guard(void ExManagerWindow::MotionBlur(void))
00238         if(!m_MotionBlurTexture)
00239         {
00240                 // Create a pointer to store the blank image data
00241                 unsigned int *pTexture = NULL;                                                                                  
00242 
00243                 // Allocate and init memory for the image array and point to it from pTexture
00244                 pTexture = new unsigned int [512 * 512 * 3];
00245                 memset(pTexture, 0, 512 * 512 * 3 * sizeof(unsigned int));      
00246 
00247                 // Register the texture with OpenGL and bind it to the texture ID
00248                 glGenTextures(1, &TextureMotionBlur);                                                           
00249                 glBindTexture(GL_TEXTURE_2D, TextureMotionBlur);                                        
00250                 
00251                 // Create the texture and store it on the video card
00252                 glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_INT, pTexture);                                              
00253                 
00254                 // Set the texture quality
00255                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
00256                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
00257 
00258                 // Since we stored the texture space with OpenGL, we can delete the image data
00259                 delete [] pTexture;                                                     
00260                 m_MotionBlurTexture=true;
00261         }
00262 
00263         // Push on a new stack so that we do not interfere with the current matrix
00264         glPushMatrix();
00265 
00266                 // Turn off depth testing so that we can blend over the screen
00267                 glDisable(GL_DEPTH_TEST);                       
00268 
00269                 // Set our blend method and enable blending
00270                 //glBlendFunc(GL_SRC_ALPHA,GL_ONE);     
00271                 //glEnable(GL_BLEND);                                   
00272 
00273                 
00274                 // Decrease the alpha value of the blend by %10 so it will fade nicely
00275                 glColor4f(1, 1, 1, 0.9f);
00276 
00277                 // Switch to 2D mode (Ortho mode)
00278                 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY);
00279 
00280                 // Display a 2D quad with our blended texture
00281                 glEnable(GL_TEXTURE_2D);
00282                 glBindTexture(GL_TEXTURE_2D,TextureMotionBlur);
00283                 glBegin(GL_QUADS);
00284 
00285 
00286                         // Display the top left point of the 2D image
00287                         glTexCoord2f(0.0f, 1.0f);       glVertex2f(0, 0);
00288 
00289                         // Display the bottom left point of the 2D image
00290                         //glTexCoord2f(0.0f, 0.0f);     glVertex2f(0, m_WindowSizeY);
00291                         glTexCoord2f(0.0f, 0.0f);       glVertex2f(0, 80);
00292 
00293                         // Display the bottom right point of the 2D image
00294                         //glTexCoord2f(1.0f, 0.0f);     glVertex2f(m_WindowSizeX, m_WindowSizeY);
00295                         glTexCoord2f(1.0f, 0.0f);       glVertex2f(80, 80);
00296 
00297                         // Display the top right point of the 2D image
00298                         //glTexCoord2f(1.0f, 1.0f);     glVertex2f(m_WindowSizeX, 0);
00299                         glTexCoord2f(1.0f, 1.0f);       glVertex2f(80, 0);
00300 
00301                 // Stop drawing 
00302                 glEnd();
00303                 glDisable(GL_TEXTURE_2D);
00304                 // Let's set our mode back to perspective 3D mode.
00305                 LeaveOrthoMode();
00306 
00307                 // Turn depth testing back on and texturing off.  If you do NOT do these 2 lines of 
00308                 // code it produces a cool flash effect that might come in handy somewhere down the road.
00309                 glEnable(GL_DEPTH_TEST);                                                
00310                 glDisable(GL_BLEND);                                                    
00311                 
00312         // Go back to our original matrix
00313         glPopMatrix();  
00314 UnGuard
00315 }
00316 
00317 void ExManagerWindow::CapturForMotionBlur(void)
00318 {
00319 Guard(void ExManagerWindow::CapturForMotionBlur(void))
00320         glBindTexture(GL_TEXTURE_2D,TextureMotionBlur);
00321         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512, 512, 0);
00322 UnGuard
00323 }
00324 
00325 
00326 void ExManagerWindow::ShowNetStat(void)
00327 {
00328 Guard(void ExManagerWindow::ShowNetStat(void))
00329 UnGuard
00330 }
00331 
00332 void ExManagerWindow::EnterOrthoMode(int left, int top, int right, int bottom)
00333 {
00334         glMatrixMode(GL_PROJECTION);                                            
00335         glPushMatrix();                                                                 
00336         glLoadIdentity();                                                               
00337         glOrtho( left, right, bottom, top, 0, 1 );      
00338         glMatrixMode(GL_MODELVIEW);                                                             
00339         glLoadIdentity();                                                                               
00340 }
00341 
00342 void ExManagerWindow::LeaveOrthoMode(void)      
00343 {
00344         glMatrixMode( GL_PROJECTION );                                                  
00345         glPopMatrix();                                                                                  
00346         glMatrixMode( GL_MODELVIEW );                                                   
00347 }
00348 
00349 void ExManagerWindow::Specialeffect(void)
00350 {
00351         switch(m_effect)
00352         {
00353         case FADE_TO_WHITE:             
00354                 glColor4ub(255,255,255, (uchar)m_CouterEffect);
00355                 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY);
00356                 
00357                 glEnable(GL_BLEND);     
00358                 glDisable(GL_DEPTH_TEST);
00359                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00360                 
00361                 glBegin(GL_QUADS);
00362                         glVertex2f(0, 0);
00363                         glVertex2f(0, m_WindowSizeY);
00364                         glVertex2f(m_WindowSizeX, m_WindowSizeY);
00365                         glVertex2f(m_WindowSizeX, 0);
00366                 glEnd();
00367                         
00368                 glDisable(GL_BLEND);            
00369                 glEnable(GL_DEPTH_TEST);
00370 
00371                 LeaveOrthoMode();
00372                 m_CouterEffect++;
00373                                 
00374                 if(m_CouterEffect>255)
00375                 {
00376                         m_CouterEffect=0;
00377                         m_effect=0;
00378                 }
00379                 break;
00380         case WITHE_TO_FADE:
00381                 glColor4ub(255,255,255, m_CouterEffect);
00382                 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY);
00383                 
00384                 glEnable(GL_BLEND);     
00385                 glDisable(GL_DEPTH_TEST);
00386                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00387                 
00388                 glBegin(GL_QUADS);
00389                         glVertex2f(0, 0);
00390                         glVertex2f(0, m_WindowSizeY);
00391                         glVertex2f(m_WindowSizeX, m_WindowSizeY);
00392                         glVertex2f(m_WindowSizeX, 0);
00393                 glEnd();
00394                         
00395                 glDisable(GL_BLEND);            
00396                 glEnable(GL_DEPTH_TEST);
00397 
00398                 LeaveOrthoMode();
00399                 m_CouterEffect--;
00400                                 
00401                 if(m_CouterEffect<1)
00402                 {
00403                         m_CouterEffect=255;
00404                         m_effect=0;
00405                 }
00406                 break;
00407         case FADE_TO_BLACK:
00408                 glColor4ub(0,0,0, m_CouterEffect);
00409                 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY);
00410                 
00411                 glEnable(GL_BLEND);     
00412                 glDisable(GL_DEPTH_TEST);
00413                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00414                 
00415                 glBegin(GL_QUADS);
00416                         glVertex2f(0, 0);
00417                         glVertex2f(0, m_WindowSizeY);
00418                         glVertex2f(m_WindowSizeX, m_WindowSizeY);
00419                         glVertex2f(m_WindowSizeX, 0);
00420                 glEnd();
00421                         
00422                 glDisable(GL_BLEND);            
00423                 glEnable(GL_DEPTH_TEST);
00424 
00425                 LeaveOrthoMode();
00426                 m_CouterEffect++;
00427                                 
00428                 if(m_CouterEffect>255)
00429                 {
00430                         m_CouterEffect=0;
00431                         m_effect=0;
00432                 }
00433                 break;
00434         case BLACK_TO_FADE:
00435                 glColor4ub(0,0,0, m_CouterEffect);
00436                 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY);
00437                 
00438                 glEnable(GL_BLEND);     
00439                 glDisable(GL_DEPTH_TEST);
00440                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00441                 
00442                 glBegin(GL_QUADS);
00443                         glVertex2f(0, 0);
00444                         glVertex2f(0, m_WindowSizeY);
00445                         glVertex2f(m_WindowSizeX, m_WindowSizeY);
00446                         glVertex2f(m_WindowSizeX, 0);
00447                 glEnd();
00448                         
00449                 glDisable(GL_BLEND);            
00450                 glEnable(GL_DEPTH_TEST);
00451 
00452                 LeaveOrthoMode();
00453                 m_CouterEffect--;
00454                                 
00455                 if(m_CouterEffect<1)
00456                 {
00457                         m_CouterEffect=255;
00458                         m_effect=0;
00459                 }
00460                 break;
00461         }
00462 }
00463 void ExManagerWindow::SetSpecialEffect(int effect)
00464 {
00465         m_effect=effect;
00466         switch(m_effect)
00467         {
00468         case FADE_TO_WHITE:
00469                 m_CouterEffect=0;
00470                 break;
00471         case WITHE_TO_FADE:
00472                 m_CouterEffect=256;
00473                 break;
00474         case FADE_TO_BLACK:
00475                 m_CouterEffect=0;
00476                 break;
00477         case BLACK_TO_FADE:
00478                 m_CouterEffect=256;
00479                 break;
00480         }
00481 }

Generated on Tue Aug 6 20:27:14 2002 for ExNihilo by doxygen1.2.17