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

fx.cpp

Go to the documentation of this file.
00001 /*
00002  * $Id: fx.cpp,v 1.3 2002/08/07 13:39:10 virtualcasino Exp $
00003  */
00004 #include<SDL.h>
00005 #include<fx.h>
00006 #include<math.h>
00007 #include<Resource.h>
00008 #include<SDL_gfxPrimitives.h>
00009 extern SDL_Surface *Screen;
00010 
00011 void fade_out(SDL_Surface *surf, double inc){
00012         double gamma = 0;
00013         double g;
00014         SDL_Rect src, dest;
00015         src.x = 0;
00016         src.y = 0;
00017         src.w = surf->w;
00018         src.h = surf->h;
00019         dest.x = 0;
00020         dest.y = 0;
00021         dest.w = Screen->w;
00022         dest.h = Screen->h;
00023         SDL_SetGamma(gamma, gamma, gamma);
00024         SDL_BlitSurface(surf, &src, Screen, &dest);
00025         for(gamma = 0; gamma <= 1; gamma += inc){
00026                 g = gamma * gamma;
00027                 SDL_SetGamma(g, g, g);
00028                 SDL_Flip(Screen);
00029         }
00030         SDL_SetGamma(1, 1, 1);
00031         SDL_FillRect(Screen, 0, 0);
00032 }
00033 
00034 void fade_in(SDL_Surface *surf, double inc){
00035         double gamma = 1;
00036         SDL_Rect src, dest;
00037         src.x = 0;
00038         src.y = 0;
00039         src.w = surf->w;
00040         src.h = surf->h;
00041         dest.x = 0;
00042         dest.y = 0;
00043         dest.w = Screen->w;
00044         dest.h = Screen->h;
00045         SDL_SetGamma(gamma, gamma, gamma);
00046         SDL_BlitSurface(surf, &src, Screen, &dest);
00047         for(gamma = 1; gamma >= 0; gamma -= inc){
00048                 SDL_SetGamma(gamma, gamma, gamma);
00049                 SDL_Flip(Screen);
00050         }
00051         SDL_FillRect(Screen, 0, 0);
00052         SDL_Flip(Screen);
00053         SDL_SetGamma(1, 1, 1);
00054 }
00055 
00056 void drawGrid(){
00057         int x, y;
00058         char buf[64];
00059         for(x = 0; x <= Screen->w; x+=10){
00060                 for(y = 0; y <= Screen->h; y+=10){
00061                         if(x % 100 == 0 && y % 50 == 0){
00062                                 sprintf(buf, "(%03d,%03d)", x, y);
00063                                 stringRGBA(Screen, x - 35, y, buf, 255, 255, 70, 70);
00064                         }
00065                         pixelRGBA(Screen, x, y, 255, 255, 255, 255);
00066                 }
00067         }
00068 }
00069 
00070 void cb_playsound(void *udata, Uint8 *stream, int len);
00071 Uint8 *audio_chunk;
00072 Uint32 audio_len;
00073 Uint8 *audio_pos;
00074 
00075 void playSound(const char *wav){
00076         SDL_AudioSpec wanted;
00077         wanted.freq = 22050;
00078         wanted.format = AUDIO_S16;
00079         wanted.channels = 2;
00080         wanted.samples = 1024;
00081         wanted.callback = cb_playsound;
00082         wanted.userdata = NULL;
00083         if ( SDL_OpenAudio(&wanted, NULL) < 0 ) {
00084                 fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
00085                 return;
00086         }
00087         if( SDL_LoadWAV(wav, &wanted, &audio_chunk, &audio_len) == NULL ){
00088                 fprintf(stderr, "Could not open test.wav: %s\n", SDL_GetError());
00089                 return;
00090         }
00091         audio_pos = audio_chunk;
00092         SDL_PauseAudio(0);
00093 }
00094 
00095 bool playFinished(){
00096         if(audio_len > 0)
00097                 return false;
00098         SDL_CloseAudio();
00099         return true;
00100 }
00101 
00102 void cb_playsound(void *udata, Uint8 *stream, int len){
00103         if ( audio_len == 0 )
00104                 return;
00105         len = ( (Uint32)len > audio_len ? audio_len : len );
00106         SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
00107         audio_pos += len;
00108         audio_len -= len;
00109 }

Powered by:

SourceForge Logo