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 /* 00055 void ExManagerSpecialEffect::SetAntialliasingState(bool state) 00056 { 00057 Guard(void ExManagerSpecialEffect::SetAntialliasingState(bool state)) 00058 m_Antialliasing=state; 00059 if(m_Antialliasing) 00060 { 00061 glEnable(GL_LINE_SMOOTH); 00062 glEnable(GL_BLEND); 00063 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 00064 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE); 00065 }else 00066 { 00067 glDisable(GL_LINE_SMOOTH); 00068 glDisable(GL_BLEND); 00069 } 00070 UnGuard 00071 } 00072 00073 00074 00075 void ExManagerSpecialEffect::MotionBlur(void) 00076 { 00077 Guard(void ExManagerSpecialEffect::MotionBlur(void)) 00078 if(!m_MotionBlurTexture) 00079 { 00080 // Create a pointer to store the blank image data 00081 unsigned int *pTexture = NULL; 00082 00083 // Allocate and init memory for the image array and point to it from pTexture 00084 pTexture = new unsigned int [512 * 512 * 3]; 00085 memset(pTexture, 0, 512 * 512 * 3 * sizeof(unsigned int)); 00086 00087 // Register the texture with OpenGL and bind it to the texture ID 00088 glGenTextures(1, &TextureMotionBlur); 00089 glBindTexture(GL_TEXTURE_2D, TextureMotionBlur); 00090 00091 // Create the texture and store it on the video card 00092 glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_INT, pTexture); 00093 00094 // Set the texture quality 00095 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 00096 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 00097 00098 // Since we stored the texture space with OpenGL, we can delete the image data 00099 delete [] pTexture; 00100 m_MotionBlurTexture=true; 00101 } 00102 00103 // Push on a new stack so that we do not interfere with the current matrix 00104 glPushMatrix(); 00105 00106 // Turn off depth testing so that we can blend over the screen 00107 glDisable(GL_DEPTH_TEST); 00108 00109 // Set our blend method and enable blending 00110 //glBlendFunc(GL_SRC_ALPHA,GL_ONE); 00111 //glEnable(GL_BLEND); 00112 00113 00114 // Decrease the alpha value of the blend by %10 so it will fade nicely 00115 glColor4f(1, 1, 1, 0.9f); 00116 00117 // Switch to 2D mode (Ortho mode) 00118 ExNihilo::EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY); 00119 00120 // Display a 2D quad with our blended texture 00121 glEnable(GL_TEXTURE_2D); 00122 glBindTexture(GL_TEXTURE_2D,TextureMotionBlur); 00123 glBegin(GL_QUADS); 00124 00125 00126 // Display the top left point of the 2D image 00127 glTexCoord2f(0.0f, 1.0f); glVertex2f(0, 0); 00128 00129 // Display the bottom left point of the 2D image 00130 //glTexCoord2f(0.0f, 0.0f); glVertex2f(0, m_WindowSizeY); 00131 glTexCoord2f(0.0f, 0.0f); glVertex2f(0, 80); 00132 00133 // Display the bottom right point of the 2D image 00134 //glTexCoord2f(1.0f, 0.0f); glVertex2f(m_WindowSizeX, m_WindowSizeY); 00135 glTexCoord2f(1.0f, 0.0f); glVertex2f(80, 80); 00136 00137 // Display the top right point of the 2D image 00138 //glTexCoord2f(1.0f, 1.0f); glVertex2f(m_WindowSizeX, 0); 00139 glTexCoord2f(1.0f, 1.0f); glVertex2f(80, 0); 00140 00141 // Stop drawing 00142 glEnd(); 00143 glDisable(GL_TEXTURE_2D); 00144 // Let's set our mode back to perspective 3D mode. 00145 ExNihilo::LeaveOrthoMode(); 00146 00147 // Turn depth testing back on and texturing off. If you do NOT do these 2 lines of 00148 // code it produces a cool flash effect that might come in handy somewhere down the road. 00149 glEnable(GL_DEPTH_TEST); 00150 glDisable(GL_BLEND); 00151 00152 // Go back to our original matrix 00153 glPopMatrix(); 00154 UnGuard 00155 } 00156 00157 void ExManagerSpecialEffect::CapturForMotionBlur(void) 00158 { 00159 Guard(void ExManagerSpecialEffect::CapturForMotionBlur(void)) 00160 glBindTexture(GL_TEXTURE_2D,TextureMotionBlur); 00161 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512, 512, 0); 00162 UnGuard 00163 } 00164 00165 void ExManagerSpecialEffect::Specialeffect(void) 00166 { 00167 switch(m_effect) 00168 { 00169 case FADE_TO_WHITE: 00170 glColor4ub(255,255,255, (uchar)m_CouterEffect); 00171 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY); 00172 00173 glEnable(GL_BLEND); 00174 glDisable(GL_DEPTH_TEST); 00175 glBlendFunc(GL_SRC_ALPHA,GL_ONE); 00176 00177 glBegin(GL_QUADS); 00178 glVertex2f(0, 0); 00179 glVertex2f(0, m_WindowSizeY); 00180 glVertex2f(m_WindowSizeX, m_WindowSizeY); 00181 glVertex2f(m_WindowSizeX, 0); 00182 glEnd(); 00183 00184 glDisable(GL_BLEND); 00185 glEnable(GL_DEPTH_TEST); 00186 00187 LeaveOrthoMode(); 00188 m_CouterEffect++; 00189 00190 if(m_CouterEffect>255) 00191 { 00192 m_CouterEffect=0; 00193 m_effect=0; 00194 } 00195 break; 00196 case WITHE_TO_FADE: 00197 glColor4ub(255,255,255, m_CouterEffect); 00198 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY); 00199 00200 glEnable(GL_BLEND); 00201 glDisable(GL_DEPTH_TEST); 00202 glBlendFunc(GL_SRC_ALPHA,GL_ONE); 00203 00204 glBegin(GL_QUADS); 00205 glVertex2f(0, 0); 00206 glVertex2f(0, m_WindowSizeY); 00207 glVertex2f(m_WindowSizeX, m_WindowSizeY); 00208 glVertex2f(m_WindowSizeX, 0); 00209 glEnd(); 00210 00211 glDisable(GL_BLEND); 00212 glEnable(GL_DEPTH_TEST); 00213 00214 LeaveOrthoMode(); 00215 m_CouterEffect--; 00216 00217 if(m_CouterEffect<1) 00218 { 00219 m_CouterEffect=255; 00220 m_effect=0; 00221 } 00222 break; 00223 case FADE_TO_BLACK: 00224 glColor4ub(0,0,0, m_CouterEffect); 00225 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY); 00226 00227 glEnable(GL_BLEND); 00228 glDisable(GL_DEPTH_TEST); 00229 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 00230 00231 glBegin(GL_QUADS); 00232 glVertex2f(0, 0); 00233 glVertex2f(0, m_WindowSizeY); 00234 glVertex2f(m_WindowSizeX, m_WindowSizeY); 00235 glVertex2f(m_WindowSizeX, 0); 00236 glEnd(); 00237 00238 glDisable(GL_BLEND); 00239 glEnable(GL_DEPTH_TEST); 00240 00241 LeaveOrthoMode(); 00242 m_CouterEffect++; 00243 00244 if(m_CouterEffect>255) 00245 { 00246 m_CouterEffect=0; 00247 m_effect=0; 00248 } 00249 break; 00250 case BLACK_TO_FADE: 00251 glColor4ub(0,0,0, m_CouterEffect); 00252 EnterOrthoMode(0, 0, m_WindowSizeX, m_WindowSizeY); 00253 00254 glEnable(GL_BLEND); 00255 glDisable(GL_DEPTH_TEST); 00256 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 00257 00258 glBegin(GL_QUADS); 00259 glVertex2f(0, 0); 00260 glVertex2f(0, m_WindowSizeY); 00261 glVertex2f(m_WindowSizeX, m_WindowSizeY); 00262 glVertex2f(m_WindowSizeX, 0); 00263 glEnd(); 00264 00265 glDisable(GL_BLEND); 00266 glEnable(GL_DEPTH_TEST); 00267 00268 LeaveOrthoMode(); 00269 m_CouterEffect--; 00270 00271 if(m_CouterEffect<1) 00272 { 00273 m_CouterEffect=255; 00274 m_effect=0; 00275 } 00276 break; 00277 } 00278 } 00279 void ExManagerSpecialEffect::SetSpecialEffect(int effect) 00280 { 00281 m_effect=effect; 00282 switch(m_effect) 00283 { 00284 case FADE_TO_WHITE: 00285 m_CouterEffect=0; 00286 break; 00287 case WITHE_TO_FADE: 00288 m_CouterEffect=256; 00289 break; 00290 case FADE_TO_BLACK: 00291 m_CouterEffect=0; 00292 break; 00293 case BLACK_TO_FADE: 00294 m_CouterEffect=256; 00295 break; 00296 } 00297 }*/