Hi,
I have one game with photo albun with games screenshots. Now i am
develop one screen to display shots captured by game.
It will display one screenshot by time, I think the best way is using
one surface for all of them, and free it after use. But its not
working on.
I am also using SDL_Resize lib for resize images before display it.
Look a little bit from my code:
void Ltr_DispararTelaLogScreenShots()
{
SDL_Surface* sfcResized = NULL; // Surface for all images
display. BUG for freesurface.
SDL_Rect recResized = {80,25,640,480}; // Store location of image at album.
SDL_Event evnt; // Event managerment.
long current = 0;
char screenShotFile[200+1];
// Get last valid file from path.
for (current=1;; current++)
{
FILE *fp = NULL;
memset(screenShotFile, 0, sizeof(screenShotFile));
sprintf(screenShotFile, "screenshots/shot%06d.png", current);
fp = fopen(screenShotFile, "r");
// If cant open, we found last file.
if (!fp)
break;
fclose(fp);
}
--current;
// If we have a valid last file, display it on screen.
if (current>0)
{
memset(screenShotFile, 0, sizeof(screenShotFile));
sprintf(screenShotFile, "screenshots/shot%06d.png", screenShotFile);
LoadImg(&sfcResized, screenShotFile);
SDL_ResizeXY(sfcResized, 640, 480, 2);
SDL_BlitSurface(sfcResized, NULL, sfcTela, &recResized);
SDL_UpdateRect(sfcTela, 0, 0, TELA_W, TELA_H);
}
while (current>0)
{
SDL_Delay(50);
// We only change the surface if has key press to change it.
if( !SDL_PollEvent(&evnt) || (evnt.type != SDL_KEYDOWN) )
continue;
switch (evnt.key.keysym.sym)
{
FILE *fp = NULL;
case SDLK_a:
if (current > 1)
current--;
break;
case SDLK_s:
memset(screenShotFile, 0, sizeof(screenShotFile));
sprintf(screenShotFile, "screenshots/shot%06d.png", current+1);
fp = fopen(screenShotFile, "r");
// If its a valid file, we can use it.
if (fp)
{
current++;
fclose(fp);
}
break;
case SDLK_ESCAPE:
current = -1;
break;
}
if (current < 1)
break;
SDL_FreeSurface(sfcResized);
memset(screenShotFile, 0, sizeof(screenShotFile));
sprintf(screenShotFile, "screenshots/shot%06d.png", current);
LoadImg(&sfcResized, screenShotFile);
SDL_ResizeXY(sfcResized, 640, 480, 2);
SDL_BlitSurface(sfcResized, NULL, sfcTela, &recResized);
SDL_UpdateRect(sfcTela, 0, 0, TELA_W, TELA_H);
}
}
When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont have
a valid surface?–
R?ben L?cio Reis
Game Developer
Linux user #433535