Hi Milan,
I,ve set the screen surface to 800600 32 bit .
A bitmap file, at 800600 is 1,37 mb (I know that is too big, but I’m not
yet used SDL_Image).
I’ve the same result with software surface.
I include some code…
it is beginner code…
#define FRAME_RATE 24
int main(int argc, char *argv[])
{
int time1;
/* the animation frame currently played */
int current = 0;
/* the time when the last frame was displayed */
int lastframe=0;
int secondi=0;
Uint8 *keys;//unsigned integer 8bit–>servir? per monitorare la tastiera
Uint32 pixelColor;//contiene il colore della WalkMap
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) //Init All…
{
printf(“Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);//chiudiamo tutto all’uscita
//inizializziamo lo schermo…
screen=SDL_SetVideoMode(800,600,32,SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBU
F);
if ( screen == NULL )
{
printf(“Unable to set 800x600 video: %s\n”, SDL_GetError());
exit(1);
}
SDL_PumpEvents();//pump event loop
//creo una superficie vuota in System Memory per accedere ai pixel
//della WalkMap
SDL_Surface *walkMap;
walkMap=SDL_CreateRGBSurface(SDL_SWSURFACE, 400, 300, 2, 0,0,0,0);
walkMap=SDL_LoadBMP(“provaLocation0WalkMapLoRes.bmp”);
BackGround= SDL_LoadBMP(“provaLocation0.bmp”);//carico l’immagine nella
nuova superficie
sprite=SDL_LoadBMP(“provaLocation0Sprite.bmp”);
//settiamo un colore alpha
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format, 255, 255,
255));
//definiamo un RECT per posizionare lo sprite
SDL_Rect rect={xpos, ypos, 0, 0};
SDL_Rect rect2={0, 168, 44, 168};//questo rect serve per i frame
dell’animazione
//w e h devono essere quanto la grandezza di un solo frame
//x e y indicano il punto di partenza del frame nella bitmap
mouseCursor=SDL_LoadBMP(“cursore.bmp”);
//settiamo un colore alpha
SDL_SetColorKey(mouseCursor, SDL_SRCCOLORKEY,SDL_MapRGB(mouseCursor->format,
255, 255, 255));
//definiamo un RECT per posizionare il cursore
SDL_Rect rectMouse={0, 0, 0, 0};
//definiamo una variabile di tipo event per gestire gli input
SDL_Event event;
SDL_ShowCursor(SDL_DISABLE);//per disabilitare il cursore del mouse
//game loop
int done=0;
while(done == 0)
{
SDL_GetMouseState(&xpos, &ypos); // Get the mouse coords per mouseCursor
rectMouse.x=xpos;//il cursore segue il movimento del mouse
rectMouse.y=ypos;
while ( SDL_PollEvent(&event) )//finch? c’? un evento nella coda degli
eventi…
//prendiamolo
{
if ( event.type == SDL_QUIT ) { done = 1; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
//controlli per il cambio frame
if ( event.key.keysym.sym == SDLK_UP ) { rect2.y=0; }
if ( event.key.keysym.sym == SDLK_DOWN ) { rect2.y=168; }
}
if (event.type == SDL_MOUSEBUTTONDOWN)
{
pixelColor = getpixel(walkMap, (xpos/2), (ypos/2));//divido per due perch?
la walkMap ? in bassa risoluzione
//facciamo il check per vedere se possiamo andare nella posizione desiderata
if(pixelColor==SDL_MapRGB(walkMap->format, 255, 255, 255))//se il pixel ?
bianco…
//SDL_MapRGB–>? importante!! non sappiamo come sono memorizzati i colori
dei pixel
{
rect.x=rectMouse.x-22;
rect.y=rectMouse.y-168;//per allineare con la base dello sprite
}
};
}//end pollEvent
/* what time is it? */
time1 = SDL_GetTicks();
/* check if it’s time to display the next frame */
if((time1 - lastframe) >= (1000.0 / FRAME_RATE))
{
/* print framerate */
if((time1-secondi) >= 1000.0)
{
printf("%d FPS\n", current);//scriviamo sul file stdout.txt
secondi=time1;
current = 1;
}
else current++;//advance frame
/* save the time */
lastframe = time1;
//per il pageFlipping
SDL_BlitSurface(BackGround,NULL,screen,NULL);//mettiamo BackGround su screen
SDL_BlitSurface(sprite,&rect2,screen,&rect);//mettiamo lo sprite su screen
nella posizione &rect
//rect2 indica quale porzione visualizzare della bitmap con i frame
SDL_BlitSurface(mouseCursor,NULL,screen,&rectMouse);//cursore…
SDL_Flip(screen);//
} //end check Framerate
}//end gameLoop
}//end main
Thanks> ----- Original Message -----
From: albis@eunet.yu (Milan Babuskov)
To:
Sent: Thursday, October 30, 2003 1:32 PM
Subject: Re: [SDL] Low Framerate
Alessandro Ardolino wrote:
as beginner I have a simple program that load a background image,
a sprite image and a mouse cursor image.
I move the sprite through the mouse.
All these image are in bmp format.
I’ve set the screen with SDL_DOUBLEBUF and SDL_FULLSCREEN.
Check whether you really got hw surfaces you asked for.
I’ve included a routine for print in sdtout.txt the fps I would.
Try printing on screen. Maybe your HDD is a bottleneck.
This code have a framerate of 30 fps on a P4 2,4 GHZ,
and only 20/22 fps on a AMD Athlon 1.7xp.
Why I’ve so low framerate?
You have to give us more data, like screen resolution and prehaps some
code of what you’re really doing.
–
Milan Babuskov
http://njam.sourceforge.net
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl