Problems

Hi… i’m have a problem with the next code :

SDL_Surface *saved = NULL;
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 16,
SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_Surface back = SDL_LoadBMP(“arena.bmp”); / 32x32 pixels */
SDL_Surface ship = SDL_LoadBMP(“ship.bmp”); / 40x40 pixels */
SDL_Rect r, currentPos;
r.x=r.y=0;
r.w=back->w;
r.h=back->h;

/* this paint the entire screen with a BMP */
for(x=0; x < 640; x+=32)
for(y=0; y < 480; y+=32)
{
r.x = x;
r.y = y;
SDL_BlitSurface(back, NULL, screen, &r);
}
SDL_Flip(screen);

currentPos.w = ship->w;
currentPos.h = ship->h;
CurrentPos.x = currentPos.y=0;
while(…)
{
if (saved)
SDL_BlitSurface(saved, NULL, screen, &currentPos);

 ...
 ... /* handle keyboard input and change the currentPos.x or/and

currentPos.y values */

if (!saved)
saved = SDL_CreateRGBSurface(SDL_HWSURFACE, ship.w, ship.h,
screen->format->BitsPerPixel,
screen->format->Rmask,
screen->format->Gmask,
screen->format->Bmask,
screen->format->Amask);
SDL_BlitSurface(screen, &currentPos, saved, NULL);
SDL_BlitSurface(ship, NULL, screen, &currentPos);
SDL_Flip(screen);
}

Well, this is basicaly the mail loop, but in “saved” always i have a
black surface… and before to do the “ship” blit, the screen backroung
is eraser. what am i doing wrong ??

   Thx again ......

PD : somebody know a SDL mailing list in spanish ??? …–
±----------------------------------------------------+
| Ricardo Markiewicz | El software es como |
±------------------------------+ el sexo… si es |
| Linux Inside! - S.u.S.E. 6.2 | gratis… Mejor!! |
| Kernel 2.2.14 | |
±----------------------------------------------------+

Hi… i’m have a problem with the next code :

SDL_Surface *saved = NULL;
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 16,
SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_Surface back = SDL_LoadBMP(“arena.bmp”); / 32x32 pixels */
SDL_Surface ship = SDL_LoadBMP(“ship.bmp”); / 40x40 pixels */
SDL_Rect r, currentPos;
r.x=r.y=0;
r.w=back->w;
r.h=back->h;

/* this paint the entire screen with a BMP */
for(x=0; x < 640; x+=32)
for(y=0; y < 480; y+=32)
{
r.x = x;
r.y = y;
SDL_BlitSurface(back, NULL, screen, &r);
}
SDL_Flip(screen);

currentPos.w = ship->w;
currentPos.h = ship->h;
CurrentPos.x = currentPos.y=0;
while(…)
{
if (saved)
SDL_BlitSurface(saved, NULL, screen, &currentPos);

 ...
 ... /* handle keyboard input and change the currentPos.x or/and

currentPos.y values */

if (!saved)
saved = SDL_CreateRGBSurface(SDL_HWSURFACE, ship.w, ship.h,
screen->format->BitsPerPixel,
screen->format->Rmask,
screen->format->Gmask,
screen->format->Bmask,
screen->format->Amask);
SDL_BlitSurface(screen, &currentPos, saved, NULL);
SDL_BlitSurface(ship, NULL, screen, &currentPos);
SDL_Flip(screen);
}

Well, this is basicaly the mail loop, but in “saved” always i have a
black surface… and before to do the “ship” blit, the screen backroung
is eraser. what am i doing wrong ??

When doing your screen update in the loop SDL_Flip(screen), you need to copy
your tile array into the screen every time, otherwise it becomes ‘lost’, due
to the double buffering.

With saved, I’m not sure, but don’t you have to fill it with something
before it contains anything? When I was doing what I think you are, I
didn’t get a black image, my image was filled with random garbage, but only
when I was in hardware mode, software mode did indeed become filled with
black.________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com