Original Post
Hey again, When you blit a SDL_Surface in SDL the content of the source SDL_Surface gets cleared. I tried to duplicate the SDL_Surface but it doesn't work (as shown in the code below). The purpose of this is that the program should only need to draw the room/level once, and not everytime it loops. The SDL wiki states that you shouldn't use memcpy (which I tried at first, but it segfaulted ofc) and recommended the method I used below as the proper way. Any suggestions?
Hero hero(200, 400);
SDL_Surface *levelm;
SDL_Surface *levels;
bool update_level;
void InitRender(SDL_Surface *screen)
{
levels = SDL_SetVideoMode(screen->clip_rect.w, screen->clip_rect.w, 16, SDL_SWSURFACE | SDL_PREALLOC);
levelm = SDL_SetVideoMode(screen->clip_rect.w, screen->clip_rect.w, 16, SDL_SWSURFACE | SDL_PREALLOC);
update_level = true;
}
void RenderScene(SDL_Surface *screen, SDL_Surface *newscreen, SDL_Surface *emptyscreen, Room *rooms, int croom)
{
/* Prepare scene */
SDL_SetColorKey(newscreen, SDL_SRCCOLORKEY, SDL_MapRGB(newscreen->format, 0x00, 0x00, 0x00));
SDL_FillRect(SDL_GetVideoSurface(), NULL, SDL_MapRGB(SDL_GetVideoSurface()->format, 0,0,0));
/* Draw into scene */
if (update_level == true)
{
rooms[croom].Draw(levelm);
}
else
{
levelm = levels;
}
levels = levelm;
levels->refcount++;
update_level = false;
SDL_BlitSurface(levelm, &levelm->clip_rect, newscreen, &newscreen->clip_rect);
hero.Draw(newscreen);
/* Render scene */
SDL_BlitSurface(newscreen, NULL, screen, NULL);
SDL_Flip(screen);
}