I have been working on this one algorithm for days to try and make it work at
a reasonable speed but to no avail…was hoping meyb u guys could help!
:)…firstly my coputer specs: athlon 2100xp 1gig ram r9800pro gfx
card…
At the moment i am writing a top down shooter, and i am
trying to write an algorithm that darkens the whole screen apart from a
circular area around the player using the folliwng algorithm that i made:
void darkenLandscape(SDL_Surface source,int radius,int x,int y){
// Draw to screen
int yofs = 0,j=0,ofs=0;
for (int i = 0; i < HEIGHT; i++)
{
for (j = 0, ofs = yofs; j < WIDTH; j++, ofs++)
{
int dx= x-j;
int dy= y-i;
float length=sqrt((float)((dxdx)+(dy*dy)));
Uint32 pixel = getPixel(source,j,i);
Uint8 sourcer = pixel;
Uint8 sourceg = pixel>>8;
Uint8 sourceb = pixel>>16;
if(length>radius){
sourcer/=4;
sourceg/=4;
sourceb/=4;
}
else{
//Avoid divide by zero error
double mod = 1+3*(1-((radius-length)/radius));
sourcer=(Uint8)(sourcer/(mod+0.1));
sourceg=(Uint8)(sourceg/(mod+0.1));
sourceb=(Uint8)(sourceb/(mod+0.1));
}
Uint32 *pixels = source->pixels;
pixel = (sourcer << 0)|(sourceg << 8)|(sourceb << 16);
pixels[ofs] = pixels[ofs]/2;}
}
yofs += PITCH;
}
}
Now i know that it definately works (see attached screenshot) however the
most i can get out of it is 16 or so fps which seems rediculous!!..i have
tried running it in fullscreen mode windowed mode using sdl_flip and
sdl_updaterec but to no avail…also before this algorithm is called the
source surface is locked. Can any1 help me out here its driving me crazy!!!
Thanks so much in advance
-James Grafton–
View this message in context: http://www.nabble.com/Bad-performence-problems-tf2088149.html#a5755364
Sent from the SDL forum at Nabble.com.