src/logo.cpp

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU Library General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00015  */
00016  
00017 #include "logo.h"
00018 
00019 LOGO::LOGO()
00020 {
00021         num_logos = 0;
00022         ltime = 0;
00023 }
00024 
00025 void LOGO::AddLogo(string filename)
00026 {
00027         logo_fn[num_logos] = filename;
00028         logo_tex[num_logos].Load(filename, false);
00029         
00030         num_logos++;
00031 }
00032 
00033 bool LOGO::IncrementTime(float fps)
00034 {
00035         ltime += 1.0f/fps;
00036         
00037         //cout << ltime << endl;
00038         
00039         if (ltime > SECS_PER_LOGO * num_logos)
00040         {
00041                 //gamestate.SetGameState(GAMESTATE_MENU);
00042                 Cleanup();
00043                 //cout << "Cleanup" << endl;
00044                 return false;
00045         }
00046         
00047         return true;
00048 }
00049 
00050 void LOGO::Cleanup()
00051 {
00052         int i;
00053         
00054         for (i = 0; i < num_logos; i++)
00055                 //glDeleteTextures(1, &(logo_tex[i]));
00056                 //textures.Delete(logo_fn[i]);
00057                 logo_tex[i].Unload();
00058 
00059 }
00060 
00061 void LOGO::Draw()
00062 {
00063         glPushAttrib(GL_ALL_ATTRIB_BITS);
00064         
00065         glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);            // Clear Screen And Depth Buffer
00066         
00067         int curlogo = (int)(ltime / SECS_PER_LOGO);
00068         
00069         glEnable(GL_TEXTURE_2D);
00070         
00071         /*int w = configsys.GetScreenW();
00072         int h = configsys.GetScreenH();*/
00073         int w, h;
00074         //w = (int) (LOGO_DIM*1.333333f);
00075         w = LOGO_DIM;
00076         h = LOGO_DIM;
00077         
00078         // Select our texture
00079     //glBindTexture( GL_TEXTURE_2D, logo_tex[curlogo] );
00080         logo_tex[curlogo].Activate();
00081 
00082     // Disable depth testing 
00083     glDisable( GL_DEPTH_TEST );
00084         //and lighting...
00085         glDisable( GL_LIGHTING);
00086         glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00087         glEnable( GL_BLEND );
00088 
00089     // Select The Projection Matrix
00090     glMatrixMode( GL_PROJECTION );
00091     // Store The Projection Matrix
00092     glPushMatrix( );
00093 
00094     // Reset The Projection Matrix 
00095     glLoadIdentity( );
00096     // Set Up An Ortho Screen 
00097     glOrtho( 0, w, 0, h, -1, 1 );
00098 
00099     // Select The Modelview Matrix
00100     glMatrixMode( GL_MODELVIEW );
00101     // Stor the Modelview Matrix
00102     glPushMatrix( );
00103     // Reset The Modelview Matrix
00104     glLoadIdentity( );
00105 
00106     // Position The Text (0,0 - Bottom Left)
00107     glTranslated( (w-LOGO_DIM)/2, (h-LOGO_DIM)/2, 0 );
00108         
00109         float trans = (ltime - (curlogo*SECS_PER_LOGO))/LOGO_FADE_SECS;
00110         if (trans > 1.0f)
00111                 trans = 1.0f;
00112         
00113         //cout << trans << endl;
00114         
00115         if (FADE_OUT && SECS_PER_LOGO - (ltime - (curlogo*SECS_PER_LOGO)) < LOGO_FADE_SECS)
00116         {
00117                 trans = (SECS_PER_LOGO - (ltime - (curlogo*SECS_PER_LOGO)))/LOGO_FADE_SECS;
00118         }
00119         
00120         glColor4f(1.0f, 1.0f, 1.0f, trans);
00121         
00122         //draw logo
00123         glBegin( GL_QUADS );
00124 
00125                 /* Texture Coord (Top Right) */
00126                 glTexCoord2f( 1, 1 );
00127                 /* Vertex Coord (Top Right) */
00128                 glVertex2i( LOGO_DIM, 0 );
00129                 
00130                 /* Texture Coord (Top Left) */
00131                 glTexCoord2f( 0, 1);
00132                 /* Vertex Coord (Top Left) */
00133                 glVertex2i( 0, 0 );
00134 
00135                 /* Texture Coord (Bottom Left) */
00136                 glTexCoord2f( 0, 0 );
00137                 /* Vertex Coord (Bottom Left) */
00138                 glVertex2i( 0, LOGO_DIM );      
00139 
00140                 /* Texture Coord (Bottom Right) */
00141                 glTexCoord2f( 1, 0);
00142                 /* Vertex Coord (Bottom Right) */
00143                 glVertex2i( LOGO_DIM, LOGO_DIM );               
00144         
00145         glEnd( );
00146         
00147         // Select The Projection Matrix
00148     glMatrixMode( GL_PROJECTION );
00149     // Restore The Old Projection Matrix
00150     glPopMatrix( );
00151         
00152         // Select the Modelview Matrix
00153     glMatrixMode( GL_MODELVIEW );
00154     // Restore the Old modelview Matrix
00155         glPopMatrix();
00156         
00157         glPopAttrib();
00158 }
00159 
00160 void LOGO::run()
00161 {
00162         string tex_size;
00163         settings.Get( "display.texture_size", tex_size );
00164         //string settings.GetDataDir() = DATA_DIR;
00165         string skin_path = settings.GetSkinPath();
00166         AddLogo( skin_path + "/textures/libsplash.png");
00167         //AddLogo(settings.GetDataDir() + "/tex/splash.jpg");
00168         AddLogo( skin_path + "/textures/splash.png");
00169         //AddLogo(settings.GetDataDir() + "/tex/logo_openal.png");
00170         
00171         Uint32 t = SDL_GetTicks();
00172         float fps = 100.0;
00173         Uint32 T0 = SDL_GetTicks();
00174         
00175         bool lp = true;
00176         bool kd = false;
00177         bool md = false;
00178         bool jd = false;
00179         
00180         while (lp)
00181         {
00182                 //glClearColor(1,1,1,0);
00183                 //glClearColor(0,0,0,0);
00184                 Draw();
00185                 SDL_GL_SwapBuffers( );
00186                 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00187                 
00188                 //t = SDL_GetTicks();
00189                 //fps = 1000000.0/(t - ot);
00190                 //cout << fps << endl;
00191 
00192                 t = SDL_GetTicks();
00193                 GLfloat seconds = (t - T0) / 1000.0;
00194                 fps = 1.0 / seconds;
00195                 T0 = t;
00196                 
00197                 t = T0;
00198                 lp = IncrementTime(fps);
00199                 //cout << lp << endl;
00200                 
00201                 SDL_Event event;
00202                 while ( SDL_PollEvent( &event ) )
00203                 {
00204                     switch( event.type )
00205                         {
00206                                 case SDL_KEYDOWN:
00207                                         kd = true;
00208                                         break;
00209                                 case SDL_JOYBUTTONDOWN:
00210                                         jd = true;
00211                                         break;
00212                                 case SDL_MOUSEBUTTONDOWN:
00213                                         md = true;
00214                                         break;
00215                                 case SDL_KEYUP:
00216                                         if (kd)
00217                                                 lp = false;
00218                                         break;
00219                                 case SDL_JOYBUTTONUP:
00220                                         if (jd)
00221                                                 lp = false;
00222                                         break;
00223                                 case SDL_MOUSEBUTTONUP:
00224                                         if (md)
00225                                                 lp = false;
00226                                         break;
00227                         }
00228                 }
00229         }
00230 }

Generated on Thu Oct 19 04:05:53 2006 by  doxygen 1.4.6