Please could you say me where is the problem ?
Thanks a lot
void bump(SDL_Surface *image, SDL_Surface *screen)
{
SDL_Event event;
int nx,ny,x,y,offset,done;
float lx,ly,count,nX,nY,nZ;
unsigned char *envmap;
SDL_Surface *bumpmap = SDL_AllocSurface(SDL_HWSURFACE,320,200,32,0xFF0000,0xFF00,0xFF,0);
int *imageptr = (int *)image->pixels;
int *bumpmapptr = (int *)bumpmap->pixels;
SDL_LockSurface(image);
SDL_LockSurface(bumpmap);
for (y=0;y<256;y++)
{
for (x=0;x<256;x++)
{
nX=(x-128)/128.0;
nY=(y-128)/128.0;
nZ=1-sqrt(nXnX+nYnY);
if (nZ<0) nZ=0;
envmap[x+(y<<8)] = ambient + diffuse * nZ;
}
}
for (done=0; !done; )
{
/* Look for a key or quit event */
while ( SDL_PollEvent(&event) )
{
if ( (event.type == SDL_KEYDOWN) || (event.type == SDL_QUIT) )
done = 1;
}
count++;
lx = cos(count/vitesse)*amplitude+288;
ly = sin(count/vitesse)*amplitude+228;
for (y=0;y<200;y++)
{
for (x=0;x<320;x++)
{
// attribue une valeur selon les normales de ses voisins
ny = nx = imageptr[offset+1] - imageptr[offset-1];
// Ajuste les pseudo-normales selon la source lumineuse
nx-=(x-lx);
ny-=(y-ly);
// On s'assure d'etre dans les limites
if (nx>255 || nx<0) nx=255;
if (ny>255 || ny<0) ny=255;
bumpmapptr[offset++] = envmap[nx+(ny<<8)];
}
}
SDL_BlitSurface(image, NULL, screen, NULL);
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
SDL_UnlockSurface(bumpmap);
SDL_UnlockSurface(image);
}