#include <sdl.h>
#include <math.h>
const int s_w = 1024;
const int s_h = 640;
static unsigned int myLut[s_w*s_h];
static unsigned int myTex[256*256];
void initLut( void )
{
for( int j=0; j<s_h; j++ )
for( int i=0; i<s_w; i++ )
{
const float x = -1.0f + (float)i*(2.0f/(float)s_w);
const float y = 1.0f - (float)j*(2.0f/(float)s_h);
const float r
= sqrt( x
*x
+y
*y
); const float a
= atan2( y
, x
);
const float u = 1.0f/r;
const float v = a*(3.0f/3.14159f);
float w = r*r;
if( w>1.0f ) w=1.0f;
const int iu = (int)(u*255.0f);
const int iv = (int)(v*255.0f);
const int iw = (int)(w*255.0f);
myLut[s_w*j+i] = ((iw&255)<<16) | ((iv&255)<<8) | (iu&255);
}
}
void initTexture( void )
{
for( int j=0; j<256; j++ )
for( int i=0; i<256; i++ )
{
int r = (i ^ j);
int g = (((i>>6)&1)^((j>>6)&1))*255;
g = (g*5 + 3*r)>>3;
myTex[256*j+i] = 0xff000000 | (g<<16) | (g<<8) | g;
}
}
void intro_init( void )
{
initTexture();
initLut();
}
unsigned int colScale( unsigned int col, int sca )
{
return ((((col&0x00ff00ff)*sca)>>8)&0x00ff00ff) + ((((col&0x0000ff00)*sca)>>8)&0x0000ff00);
}
void do_intro( unsigned int *buffer, long itime )
{
for( int i=0; i<s_w*s_h; i++ )
{
const unsigned int val = myLut[i];
const unsigned int col = myTex[ ((val&0x0000ffff)+(itime>>2))&0x0000ffff ];
buffer[i] = colScale( col, (val>>16) );
}
}
int main ( int argc, char** argv )
{
unsigned int tickf,tickl = 0,fps,count = 0;
float dif;
char buf[32];
SDL_Event event;
SDL_Init( SDL_INIT_VIDEO );
SDL_Surface* screen = SDL_SetVideoMode(s_w, s_h, 32, SDL_SWSURFACE );
intro_init();
bool done = false;
tickf = SDL_GetTicks();
while (!done)
{
dif = (tickl-tickf) / 1000;
if (dif >= 1.0f ){
tickf = tickl;
fps = count;
count = 0;
SDL_WM_SetCaption(buf,NULL);
} else {
count++;
};
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
done = true;
break;
case SDL_KEYDOWN:
if ( event.key.keysym.sym == SDLK_ESCAPE ){
done = true;
}
break;
}
}
do_intro((unsigned int *)screen->pixels, SDL_GetTicks());
SDL_Flip(screen);
tickl = SDL_GetTicks();
}
SDL_FreeSurface(screen);
return 0;
}