Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

ExManagerSpecialEffect.cpp

Aller à la documentation de ce fichier.
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: ExManagerSpecialEffect.cpp,v 1.2 2002/11/24 11:58:58 data Exp $
00021  *
00022  */
00023 #include "ExManagerSpecialEffect.h"
00024 
00025 bool ExManagerSpecialEffect::m_flag = false; 
00026 ExManagerSpecialEffect* ExManagerSpecialEffect::m_instance = NULL; 
00027 
00028 ExManagerSpecialEffect* ExManagerSpecialEffect::CreateSingleton(void){
00029 Guard(ExManagerSpecialEffect* ExManagerSpecialEffect::CreateSingleton(void))
00030         if(!m_flag)
00031         {
00032                 m_flag = true; // We are creating the error log now, so set flag to true
00033                 m_instance = new ExManagerSpecialEffect; // Create the error log
00034         }else
00035         {
00036                 std::cout<<"Error singleton already created"<<std::endl;
00037         }
00038         return m_instance; 
00039 UnGuard
00040 }
00041 
00042 ExManagerSpecialEffect::ExManagerSpecialEffect(void)
00043 {
00044 }
00045 
00046 ExManagerSpecialEffect::~ExManagerSpecialEffect(void)
00047 {
00048 }
00049 
00050 void ExManagerSpecialEffect::Reset(void)
00051 {
00052 }
00053 
00054 void ExManagerSpecialEffect::Init(void)
00055 {
00056 }
00057 
00058 void ExManagerSpecialEffect::Draw(void)
00059 {
00060         Specialeffect();
00061 }
00062 
00063 void ExManagerSpecialEffect::BeforeDraw(void)
00064 {
00065         switch(m_effect)
00066         {
00067         case MOTION_BLUR:
00068                 MotionBlur();
00069                 break;
00070         }       
00071 }
00072 
00073 void ExManagerSpecialEffect::SetAntialliasingState(bool state)
00074 {
00075 Guard(void ExManagerSpecialEffect::SetAntialliasingState(bool state))
00076         m_Antialliasing=state;
00077         if(m_Antialliasing)
00078         {
00079                 glEnable(GL_LINE_SMOOTH);
00080                 glEnable(GL_BLEND);
00081                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00082                 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
00083         }else
00084         {
00085                 glDisable(GL_LINE_SMOOTH);
00086                 glDisable(GL_BLEND);
00087         }
00088 UnGuard
00089 }
00090 
00091 
00092 void ExManagerSpecialEffect::MotionBlur(void)
00093 {
00094 Guard(void ExManagerSpecialEffect::MotionBlur(void))
00095         if(!m_MotionBlurTexture)
00096         {
00097                 // Create a pointer to store the blank image data
00098                 unsigned int *pTexture = NULL;                                                                                  
00099 
00100                 // Allocate and init memory for the image array and point to it from pTexture
00101                 pTexture = new unsigned int [512 * 512 * 3];
00102                 memset(pTexture, 0, 512 * 512 * 3 * sizeof(unsigned int));      
00103 
00104                 // Register the texture with OpenGL and bind it to the texture ID
00105                 glGenTextures(1, &TextureMotionBlur);                                                           
00106                 glBindTexture(GL_TEXTURE_2D, TextureMotionBlur);                                        
00107                 
00108                 // Create the texture and store it on the video card
00109                 glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_INT, pTexture);                                              
00110                 
00111                 // Set the texture quality
00112                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
00113                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
00114 
00115                 // Since we stored the texture space with OpenGL, we can delete the image data
00116                 delete [] pTexture;                                                     
00117                 m_MotionBlurTexture=true;
00118         }
00119 
00120         // Push on a new stack so that we do not interfere with the current matrix
00121         glPushMatrix();
00122 
00123                 // Turn off depth testing so that we can blend over the screen
00124                 glDisable(GL_DEPTH_TEST);                       
00125 
00126                 // Set our blend method and enable blending
00127                 //glBlendFunc(GL_SRC_ALPHA,GL_ONE);     
00128                 //glEnable(GL_BLEND);                                   
00129 
00130                 
00131                 // Decrease the alpha value of the blend by %10 so it will fade nicely
00132                 glColor4f(1, 1, 1, 0.9f);
00133 
00134                 // Switch to 2D mode (Ortho mode)
00135                 ExNihilo::EnterOrthoMode();
00136 
00137                 // Display a 2D quad with our blended texture
00138                 glEnable(GL_TEXTURE_2D);
00139                 glBindTexture(GL_TEXTURE_2D,TextureMotionBlur);
00140                 glBegin(GL_QUADS);
00141 
00142 
00143                         // Display the top left point of the 2D image
00144                         glTexCoord2f(0.0f, 1.0f);       glVertex2f(100, 100);
00145 
00146                         // Display the bottom left point of the 2D image
00147                         //glTexCoord2f(0.0f, 0.0f);     glVertex2f(0, ExNihilo::GetResolutionY());
00148                         glTexCoord2f(0.0f, 0.0f);       glVertex2f(100, 180);
00149 
00150                         // Display the bottom right point of the 2D image
00151                         //glTexCoord2f(1.0f, 0.0f);     glVertex2f(ExNihilo::GetResolutionX(), ExNihilo::GetResolutionY());
00152                         glTexCoord2f(1.0f, 0.0f);       glVertex2f(180, 180);
00153 
00154                         // Display the top right point of the 2D image
00155                         //glTexCoord2f(1.0f, 1.0f);     glVertex2f(ExNihilo::GetResolutionX(), 0);
00156                         glTexCoord2f(1.0f, 1.0f);       glVertex2f(180, 100);
00157 
00158                 // Stop drawing 
00159                 glEnd();
00160                 glDisable(GL_TEXTURE_2D);
00161                 // Let's set our mode back to perspective 3D mode.
00162                 ExNihilo::LeaveOrthoMode();
00163 
00164                 // Turn depth testing back on and texturing off.  If you do NOT do these 2 lines of 
00165                 // code it produces a cool flash effect that might come in handy somewhere down the road.
00166                 glEnable(GL_DEPTH_TEST);                                                
00167                 glDisable(GL_BLEND);                                                    
00168                 
00169         // Go back to our original matrix
00170         glPopMatrix();  
00171 UnGuard
00172 }
00173 
00174 void ExManagerSpecialEffect::CapturForMotionBlur(void)
00175 {
00176 Guard(void ExManagerSpecialEffect::CapturForMotionBlur(void))
00177 /*      glEnable(GL_TEXTURE_2D);
00178         glBindTexture(GL_TEXTURE_2D,TextureMotionBlur);
00179         glReadBuffer(GL_FRONT);
00180         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256,256, 0);
00181 */
00182         unsigned char * imageData;
00183         imageData= (unsigned char*) malloc(ExNihilo::GetResolutionX()*ExNihilo::GetResolutionY()*3);
00184         memset(imageData,255, ExNihilo::GetResolutionX()* ExNihilo::GetResolutionY()* 3);
00185 
00186         glReadBuffer(GL_FRONT);
00187         glReadPixels(0, 0, ExNihilo::GetResolutionX()- 1, ExNihilo::GetResolutionY()- 1, GL_RGB, GL_UNSIGNED_BYTE, imageData);
00188         
00189         // Create the texture and store it on the video card
00190         glTexImage2D(GL_TEXTURE_2D, 0, 3, ExNihilo::GetResolutionX(), ExNihilo::GetResolutionY(), 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);                                              
00191 
00192         // Set the texture quality
00193         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
00194         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
00195 
00196 
00197 UnGuard
00198 }
00199 
00200 void ExManagerSpecialEffect::Specialeffect(void)
00201 {
00202         switch(m_effect)
00203         {
00204         case FADE_TO_WHITE:             
00205                 glColor4ub(255,255,255, (uchar)m_CouterEffect);
00206                 ExNihilo::EnterOrthoMode();
00207                 
00208                 glEnable(GL_BLEND);     
00209                 glDisable(GL_DEPTH_TEST);
00210                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00211                 
00212                 glBegin(GL_QUADS);
00213                         glVertex2f(0, 0);
00214                         glVertex2f(0, ExNihilo::GetResolutionY());
00215                         glVertex2f(ExNihilo::GetResolutionX(), ExNihilo::GetResolutionY());
00216                         glVertex2f(ExNihilo::GetResolutionX(), 0);
00217                 glEnd();
00218                         
00219                 glDisable(GL_BLEND);            
00220                 glEnable(GL_DEPTH_TEST);
00221 
00222                 ExNihilo::LeaveOrthoMode();
00223                 m_CouterEffect++;
00224                                 
00225                 if(m_CouterEffect>255)
00226                 {
00227                         m_CouterEffect=0;
00228                         m_effect=0;
00229                 }
00230                 break;
00231         case WITHE_TO_FADE:
00232                 glColor4ub(255,255,255, m_CouterEffect);
00233                 ExNihilo::EnterOrthoMode();
00234                 
00235                 glEnable(GL_BLEND);     
00236                 glDisable(GL_DEPTH_TEST);
00237                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00238                 
00239                 glBegin(GL_QUADS);
00240                         glVertex2f(0, 0);
00241                         glVertex2f(0, ExNihilo::GetResolutionY());
00242                         glVertex2f(ExNihilo::GetResolutionX(), ExNihilo::GetResolutionY());
00243                         glVertex2f(ExNihilo::GetResolutionX(), 0);
00244                 glEnd();
00245                         
00246                 glDisable(GL_BLEND);            
00247                 glEnable(GL_DEPTH_TEST);
00248 
00249                 ExNihilo::LeaveOrthoMode();
00250                 m_CouterEffect--;
00251                                 
00252                 if(m_CouterEffect<1)
00253                 {
00254                         m_CouterEffect=255;
00255                         m_effect=0;
00256                 }
00257                 break;
00258         case FADE_TO_BLACK:
00259                 glColor4ub(0,0,0, m_CouterEffect);
00260                 ExNihilo::EnterOrthoMode();
00261                 
00262                 glEnable(GL_BLEND);     
00263                 glDisable(GL_DEPTH_TEST);
00264                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00265                 
00266                 glBegin(GL_QUADS);
00267                         glVertex2f(0, 0);
00268                         glVertex2f(0, ExNihilo::GetResolutionY());
00269                         glVertex2f(ExNihilo::GetResolutionX(), ExNihilo::GetResolutionY());
00270                         glVertex2f(ExNihilo::GetResolutionX(), 0);
00271                 glEnd();
00272                         
00273                 glDisable(GL_BLEND);            
00274                 glEnable(GL_DEPTH_TEST);
00275 
00276                 ExNihilo::LeaveOrthoMode();
00277                 m_CouterEffect++;
00278                                 
00279                 if(m_CouterEffect>255)
00280                 {
00281                         m_CouterEffect=0;
00282                         m_effect=0;
00283                 }
00284 
00285                 if(m_CouterEffect==230)
00286                 {
00287                         //return end action
00288                         ExCAction Action(LOAD_EXEC_CONFIG_FILE);
00289                         Action.m_Param=" lotr1.exec";
00290                         FluxAction->Push(Action);
00291                 }
00292                 break;
00293         case BLACK_TO_FADE:
00294                 glColor4ub(0,0,0, m_CouterEffect);
00295                 ExNihilo::EnterOrthoMode();
00296                 
00297                 glEnable(GL_BLEND);     
00298                 glDisable(GL_DEPTH_TEST);
00299                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00300                 
00301                 glBegin(GL_QUADS);
00302                         glVertex2f(0, 0);
00303                         glVertex2f(0, ExNihilo::GetResolutionY());
00304                         glVertex2f(ExNihilo::GetResolutionX(), ExNihilo::GetResolutionY());
00305                         glVertex2f(ExNihilo::GetResolutionX(), 0);
00306                 glEnd();
00307                         
00308                 glDisable(GL_BLEND);            
00309                 glEnable(GL_DEPTH_TEST);
00310 
00311                 ExNihilo::LeaveOrthoMode();
00312                 m_CouterEffect--;
00313                                 
00314                 if(m_CouterEffect<1)
00315                 {
00316                         m_CouterEffect=255;
00317                         m_effect=0;
00318                 }
00319                 break;
00320         case MOTION_BLUR:
00321                 CapturForMotionBlur();
00322                 break;
00323         }
00324 }
00325 void ExManagerSpecialEffect::SetSpecialEffect(int effect)
00326 {
00327         //std::cout<<"changeefftect"<<std::endl;
00328         m_effect=effect;
00329         switch(m_effect)
00330         {
00331         case FADE_TO_WHITE:
00332                 m_CouterEffect=0;
00333                 break;
00334         case WITHE_TO_FADE:
00335                 m_CouterEffect=256;
00336                 break;
00337         case FADE_TO_BLACK:
00338                 m_CouterEffect=0;
00339                 break;
00340         case BLACK_TO_FADE:
00341                 m_CouterEffect=256;
00342                 break;
00343         }
00344 }
00345 
00346 ExCAction ExManagerSpecialEffect::InputAction(ExCAction Action)
00347 {
00348 Guard(ExCAction ExManagerSpecialEffect::InputAction(ExCAction Action))
00349         switch(Action.m_Action)
00350         {
00351         case START_FADE_TO_WHITE:SetSpecialEffect(FADE_TO_WHITE);return NOTHING;
00352         case STOP_FADE_TO_WHITE:SetSpecialEffect(NO_EFFECT);return NOTHING;
00353         case START_WITHE_TO_FADE:SetSpecialEffect(WITHE_TO_FADE);return NOTHING;
00354         case STOP_WITHE_TO_FADE:SetSpecialEffect(NO_EFFECT);return NOTHING;
00355         case START_FADE_TO_BLACK:SetSpecialEffect(FADE_TO_BLACK);return NOTHING;
00356         case STOP_FADE_TO_BLACK:SetSpecialEffect(NO_EFFECT);return NOTHING;
00357         case START_BLACK_TO_FADE:SetSpecialEffect(BLACK_TO_FADE);return NOTHING;
00358         case STOP_BLACK_TO_FADE:SetSpecialEffect(NO_EFFECT);return NOTHING;
00359         case START_MOTION_BLUR:SetSpecialEffect(MOTION_BLUR);return NOTHING;
00360         case STOP_MOTION_BLUR:SetSpecialEffect(NO_EFFECT);return NOTHING;
00361         }
00362         if(Action.m_NextAction){return *Action.m_NextAction;}
00363         else{return NOTHING;}
00364 UnGuard
00365 }
00366 
00367 ExCAction ExManagerSpecialEffect::InputCommand(ExCCommand Command)
00368 {
00369 Guard(ExCAction ExManagerSpecialEffect::InputCommand(ExCCommand Command))
00370 /*      switch(Command.m_Command)
00371         {
00372         }*/
00373         return NOTHING;
00374 UnGuard
00375 }

Généré le Tue Oct 28 12:43:38 2003 pour ExNihilo par doxygen 1.3.4