Low Framerate

Hi,
i suppose it is a newbie question but i’ve searched the whole internet and did not find anything that explains my low framerate. I programmed a pong game that blits 4 surfaces onto the screen surface. But when i blit an 800x600 surface ( game background) every frame, my game gets so slow that collision detection is useless.

Please Help me !!! And have mercy with me.

Thanks :slight_smile:

Can we see the code, or at least the initialization and blit in
question. There are definitely some very common mistakes that lead to
this kind of thing.On Sun, 2002-11-24 at 02:06, Marc Essinger wrote:

Hi,
i suppose it is a newbie question but i’ve searched the whole internet and did not find anything that explains my low framerate. I programmed a pong game that blits 4 surfaces onto the screen surface. But when i blit an 800x600 surface ( game background) every frame, my game gets so slow that collision detection is useless.

Please Help me !!! And have mercy with me.

Thanks :slight_smile:

I can understand the slow framerate, if you’re blitting an ENTIRE
800*600 surface -every frame-. That’s a lot of data, all the time.
Let’s do the math…

A 16bpp image, meaning (8006002) bytes, is 938K, nearly an entire
megabyte. To run at 85fps, SDL would need to copy data at a blazing 77
megabytes per second! And if your source image doesn’t match the pixel
depth of the screen, SDL would need to be able to CONVERT 77 megs of
data per second. Ouch!

Fortunately, there’s a way around this. You don’t need to update the
entire background every frame, just the parts that have changed; just
the background that was revealed when stuff moved(and directly below
aforementioned stuff if they’re transparent or alpha-channeled).

And for that matter, you don’t have to update the entire screen, either,
just the parts that’ve changed. :slight_smile: Instead of SDL_Flip(screen) or
SDL_UpdateRect(screen,0,0,0,0) you can use
SDL_UpdateRects(screen,number_of_rectangles, array_of_rectangles).

This method’s inarguably more complicated, but usually MUCH more
efficient unless nearly the entire screen changes every frame.

Marc Essinger wrote:> Hi,i suppose it is a newbie question but i’ve searched the whole

internet and did not find anything that explains my low framerate. I
programmed a pong game that blits 4 surfaces onto the screen surface.
But when i blit an 800x600 surface ( game background) every frame, my
game gets so slow that collision detection is useless. Please Help me
!!! And have mercy with me. Thanks :slight_smile:

Hello,

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.

I’ve included a routine for print in sdtout.txt the fps I would.

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?

Thanks

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

Hi Milan,

I,ve set the screen surface to 800600 32 bit .
A bitmap file, at 800
600 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

Alessandro Ardolino wrote:

I,ve set the screen surface to 800600 32 bit .
A bitmap file, at 800
600 is 1,37 mb (I know that is too big, but I’m not
yet used SDL_Image).

It’s not too big. Njam blits that amount every frame, and I get about
200 fps on machine like yours (about 80fps without hw surfaces)

SDL_PumpEvents();//pump event loop

Why do you need this?

pixelColor = getpixel(walkMap, (xpos/2), (ypos/2));//divido per due perch?

You should check whether the surface has to be locked. RTFM.

 rect.y=rectMouse.y-168;//per allineare con la base dello sprite

}
};

This looks like an extra semicolon.

time1 = SDL_GetTicks();
/* check if it’s time to display the next frame */
if((time1 - lastframe) >= (1000.0 / FRAME_RATE))

Prehaps you should initialize lastframe with SDL_GetTicks() as well
(instead of zero).

If you really want to measure fps, you shouldn’t try to “put it down”.
Remove those IFs, and just let it roll, so you can see what framerate is
really possible.

HTH–
Milan Babuskov
http://njam.sourceforge.net

I’ve made these changes…
but it’s still slow.

on P4 2.4GHZ I’ve a constant framerate of 60fps.

on AMD 1.7xp I’ve the same framerate of 20/22 fps.

I use DevC++ 4.9.8.0, must insert some compile strings?

PS. I’ve downloaded your Njam, it goes fast! congratulation, it’s very funny
expecially in 2 player mode…> ----- Original Message -----

From: albis@eunet.yu (Milan Babuskov)
To:
Sent: Thursday, October 30, 2003 3:24 PM
Subject: Re: [SDL] Low Framerate

Alessandro Ardolino wrote:

I,ve set the screen surface to 800600 32 bit .
A bitmap file, at 800
600 is 1,37 mb (I know that is too big, but I’m
not

yet used SDL_Image).

It’s not too big. Njam blits that amount every frame, and I get about
200 fps on machine like yours (about 80fps without hw surfaces)

SDL_PumpEvents();//pump event loop

Why do you need this?

pixelColor = getpixel(walkMap, (xpos/2), (ypos/2));//divido per due
perch?

You should check whether the surface has to be locked. RTFM.

 rect.y=rectMouse.y-168;//per allineare con la base dello sprite

}
};

This looks like an extra semicolon.

time1 = SDL_GetTicks();
/* check if it’s time to display the next frame */
if((time1 - lastframe) >= (1000.0 / FRAME_RATE))

Prehaps you should initialize lastframe with SDL_GetTicks() as well
(instead of zero).

If you really want to measure fps, you shouldn’t try to “put it down”.
Remove those IFs, and just let it roll, so you can see what framerate is
really possible.

HTH

–
Milan Babuskov
http://njam.sourceforge.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I’ve made these changes…
but it’s still slow.

on P4 2.4GHZ I’ve a constant framerate of 60fps.

on AMD 1.7xp I’ve the same framerate of 20/22 fps.

Do you convert your images to be the same depth and pixel format as the
display? If you don’t then SDL will convert them for you when you copy
them to the screen. But, it will convert them every time to copy them to
the screen. The conversion can be very time consuming. Also, do you copy
the background every frame? If so, you may be over whelming some part of
your hardware. Of course, that depends on many things both hardware and
software. So, you need to test that carefully. You might try not
updating the background and see if that affects the performance.

	Bob PendletonOn Thu, 2003-10-30 at 09:46, Alessandro Ardolino wrote:

I use DevC++ 4.9.8.0, must insert some compile strings?

PS. I’ve downloaded your Njam, it goes fast! congratulation, it’s very funny
expecially in 2 player mode…

----- Original Message -----
From: “Milan Babuskov”
To:
Sent: Thursday, October 30, 2003 3:24 PM
Subject: Re: [SDL] Low Framerate

Alessandro Ardolino wrote:

I,ve set the screen surface to 800600 32 bit .
A bitmap file, at 800
600 is 1,37 mb (I know that is too big, but I’m
not

yet used SDL_Image).

It’s not too big. Njam blits that amount every frame, and I get about
200 fps on machine like yours (about 80fps without hw surfaces)

SDL_PumpEvents();//pump event loop

Why do you need this?

pixelColor = getpixel(walkMap, (xpos/2), (ypos/2));//divido per due
perch?

You should check whether the surface has to be locked. RTFM.

 rect.y=rectMouse.y-168;//per allineare con la base dello sprite

}
};

This looks like an extra semicolon.

time1 = SDL_GetTicks();
/* check if it’s time to display the next frame */
if((time1 - lastframe) >= (1000.0 / FRAME_RATE))

Prehaps you should initialize lastframe with SDL_GetTicks() as well
(instead of zero).

If you really want to measure fps, you shouldn’t try to “put it down”.
Remove those IFs, and just let it roll, so you can see what framerate is
really possible.

HTH

–
Milan Babuskov
http://njam.sourceforge.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
–
±--------------------------------------+

Hello,

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.

I’ve included a routine for print in sdtout.txt the fps I would.

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?

Thanks

You may want to make sure that you aren’t compiling in debug mode. This can really slow things down.

Shred

----- Original Message -----
From: aleardo@libero.it (Alessandro Ardolino)
Reply-To: sdl at libsdl.org
Date: Thu, 30 Oct 2003 12:29:47 +0100

Hello, I have been seeing your code and I found two importants things:

  1. you don’t convert the load surfaces to screen format, currently there
    isn’t problem because I imagine you load BMP at 32bits color depth but if
    you change this… you’ll have problems… so, you need to use
    SDL_DisplayFormat(), you can see it in your source code (I had done a few
    changes on it).

  2. the most important and the main reason which you don’t get more frames
    per second… you have a frame limiter in your code… (I suppose that you
    are using a code from an example or another project because this code’s part
    is in english language). whatever I don’t understand is how in a Pentium 4
    machine the fps can exceed the 24fps limits that you have in your code.

With this modifications… I get +/- 170fps in software mode and more than
1000fps in hardware mode… but I have doubts about your method to calculate
the fps… but I don’t have more time… maybe is all right :slight_smile:

happy coding, see you!

Roberto Prieto
MegaStorm Systems © 2003
http://www.megastormsystems.com----------------------------------------------------------------------------

// Testing code…

// —Includes—
#include “SDL.h”
#define FRAME_RATE 24

// Prototype
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y);

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=0;//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);
// —>Roberto: to test in software mode
//screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE);

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,*BackGround,*sprite,*temp;
walkMap=SDL_LoadBMP(“provaLocation0WalkMapLoRes.bmp”);
// —>Roberto: here, we convert surface loaded to screen format
if(walkMap!=NULL)
{
temp=SDL_DisplayFormat(walkMap);
SDL_FreeSurface(walkMap);
walkMap=temp;
}
BackGround=SDL_LoadBMP(“provaLocation0.bmp”);//carico l’immagine nella
nuova superficie
// —>Roberto: The same…
if(BackGround!=NULL)
{
temp=SDL_DisplayFormat(BackGround);
SDL_FreeSurface(BackGround);
BackGround=temp;
}
// —>Roberto: The same…
sprite=SDL_LoadBMP(“provaLocation0Sprite.bmp”);
if(sprite!=NULL)
{
temp=SDL_DisplayFormat(sprite);
SDL_FreeSurface(sprite);
sprite=temp;
}

//settiamo un colore alpha
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format, 255,
255,255));
//definiamo un RECT per posizionare lo sprite
int xpos=0,ypos=0;
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

SDL_Surface *mouseCursor=SDL_LoadBMP(“cursore.bmp”);
// —>Roberto: The same…
if(mouseCursor!=NULL)
{
temp=SDL_DisplayFormat(mouseCursor);
SDL_FreeSurface(mouseCursor);
mouseCursor=temp;
}
//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
deglieventi…
//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)
{
// —>Roberto: I don’t know what function are you using here… I use
my function.
pixelColor = MyOwnGetPixel(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
coloridei 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
// —>Roberto: here, I switch off the limiter of FRAME_RATE per second
//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);//
// —>Roberto: and here
//} //end check Framerate

}//end gameLoop

}//end main

// MyOwnGetPixel, it works with 8,16,24 and 32 bits
// the log system is switch off because this function is from my library
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y)
{

 Uint32 ret;

 // Bloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
if(SDL_LockSurface(s)<0)
{
//ILogSystem.Msg(" ?CRM32Pro [IPrimitives::GetPixel()] Error:
%s\n",SDL_GetError());
return 0;
}
}

// Depende del modo grafico
switch(s->format->BytesPerPixel)
{
// Modo 8bit con paleta
case 1:
 {
  ret=*((Uint8*)s->pixels + y * s->pitch + x);
     break;
 }

// Modo 16bit
case 2:
 {
  ret=*((Uint16*)s->pixels + y * s->pitch/2 + x);
     break;
 }

// Modo 24bit (muy lento)
case 3:
 {
  Uint8 *pix;
  int shift;
  Uint32 color;

  pix=(Uint8*)s->pixels + y * s->pitch + x * 3;
  shift=s->format->Rshift;
  color=*(pix+shift/8)<<shift;
  shift=s->format->Gshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Bshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Ashift;
  color|=*(pix+shift/8)<<shift;
  ret=color;
  break;
 }

// Modo 32bit
case 4:
 {
  ret=*((Uint32*)s->pixels + y * s->pitch/4 + x);
  break;
 }
}

// Desbloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
SDL_UnlockSurface(s);
}
return ret;
}

----- Original Message -----
From: shred@shredsplace.com (shred )
To:
Sent: Thursday, October 30, 2003 6:45 PM
Subject: Re: [SDL] Low Framerate

---------- Original Message ----------------------------------
From: “Alessandro Ardolino”
Reply-To: sdl at libsdl.org
Date: Thu, 30 Oct 2003 12:29:47 +0100

Hello,

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.

I’ve included a routine for print in sdtout.txt the fps I would.

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?

Thanks

You may want to make sure that you aren’t compiling in debug mode. This
can really slow things down.

Shred


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

What’s wrong!!!
I’m very frustrated!

I’ve used SDL_DisplayFormat(),
cut off the frame limiter (I had this to get same fps on 2 PCs…),
almost sure not compile in debug mode,
trying to not updating the background every frame.

I’ve still only 60fps on P4…

I don’t want disturb you,
but it’s very stange!

Thanks to all> ----- Original Message -----

From: dm2@mi.madritel.es (Roberto Prieto)
To:
Sent: Thursday, October 30, 2003 8:32 PM
Subject: Re: [SDL] Low Framerate

Hello, I have been seeing your code and I found two importants things:

  1. you don’t convert the load surfaces to screen format, currently there
    isn’t problem because I imagine you load BMP at 32bits color depth but if
    you change this… you’ll have problems… so, you need to use
    SDL_DisplayFormat(), you can see it in your source code (I had done a few
    changes on it).

  2. the most important and the main reason which you don’t get more frames
    per second… you have a frame limiter in your code… (I suppose that you
    are using a code from an example or another project because this code’s
    part
    is in english language). whatever I don’t understand is how in a Pentium 4
    machine the fps can exceed the 24fps limits that you have in your code.

With this modifications… I get +/- 170fps in software mode and more than
1000fps in hardware mode… but I have doubts about your method to
calculate
the fps… but I don’t have more time… maybe is all right :slight_smile:

happy coding, see you!

Roberto Prieto
MegaStorm Systems © 2003
http://www.megastormsystems.com


–

// Testing code…

// —Includes—
#include “SDL.h”
#define FRAME_RATE 24

// Prototype
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y);

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=0;//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);
// —>Roberto: to test in software mode
//screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE);

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,*BackGround,*sprite,*temp;
walkMap=SDL_LoadBMP(“provaLocation0WalkMapLoRes.bmp”);
// —>Roberto: here, we convert surface loaded to screen format
if(walkMap!=NULL)
{
temp=SDL_DisplayFormat(walkMap);
SDL_FreeSurface(walkMap);
walkMap=temp;
}
BackGround=SDL_LoadBMP(“provaLocation0.bmp”);//carico l’immagine nella
nuova superficie
// —>Roberto: The same…
if(BackGround!=NULL)
{
temp=SDL_DisplayFormat(BackGround);
SDL_FreeSurface(BackGround);
BackGround=temp;
}
// —>Roberto: The same…
sprite=SDL_LoadBMP(“provaLocation0Sprite.bmp”);
if(sprite!=NULL)
{
temp=SDL_DisplayFormat(sprite);
SDL_FreeSurface(sprite);
sprite=temp;
}

//settiamo un colore alpha
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format, 255,
255,255));
//definiamo un RECT per posizionare lo sprite
int xpos=0,ypos=0;
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

SDL_Surface *mouseCursor=SDL_LoadBMP(“cursore.bmp”);
// —>Roberto: The same…
if(mouseCursor!=NULL)
{
temp=SDL_DisplayFormat(mouseCursor);
SDL_FreeSurface(mouseCursor);
mouseCursor=temp;
}
//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
deglieventi…
//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)
{
// —>Roberto: I don’t know what function are you using here… I use
my function.
pixelColor = MyOwnGetPixel(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
coloridei 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
// —>Roberto: here, I switch off the limiter of FRAME_RATE per
second
//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);//
// —>Roberto: and here
//} //end check Framerate

}//end gameLoop

}//end main

// MyOwnGetPixel, it works with 8,16,24 and 32 bits
// the log system is switch off because this function is from my library
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y)
{

 Uint32 ret;

 // Bloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
if(SDL_LockSurface(s)<0)
{
//ILogSystem.Msg(" ?CRM32Pro [IPrimitives::GetPixel()] Error:
%s\n",SDL_GetError());
return 0;
}
}

// Depende del modo grafico
switch(s->format->BytesPerPixel)
{
// Modo 8bit con paleta
case 1:
 {
  ret=*((Uint8*)s->pixels + y * s->pitch + x);
     break;
 }

// Modo 16bit
case 2:
 {
  ret=*((Uint16*)s->pixels + y * s->pitch/2 + x);
     break;
 }

// Modo 24bit (muy lento)
case 3:
 {
  Uint8 *pix;
  int shift;
  Uint32 color;

  pix=(Uint8*)s->pixels + y * s->pitch + x * 3;
  shift=s->format->Rshift;
  color=*(pix+shift/8)<<shift;
  shift=s->format->Gshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Bshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Ashift;
  color|=*(pix+shift/8)<<shift;
  ret=color;
  break;
 }

// Modo 32bit
case 4:
 {
  ret=*((Uint32*)s->pixels + y * s->pitch/4 + x);
  break;
 }
}

// Desbloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
SDL_UnlockSurface(s);
}
return ret;
}

–

----- Original Message -----
From: "shred "
To:
Sent: Thursday, October 30, 2003 6:45 PM
Subject: Re: [SDL] Low Framerate

---------- Original Message ----------------------------------
From: “Alessandro Ardolino”
Reply-To: sdl at libsdl.org
Date: Thu, 30 Oct 2003 12:29:47 +0100

Hello,

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.

I’ve included a routine for print in sdtout.txt the fps I would.

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?

Thanks

You may want to make sure that you aren’t compiling in debug mode. This
can really slow things down.

Shred


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I think this problem has to do with vsync but i dont rememebr enough
technical knowledge to help you out here.

vsync makes it so it only redraws the screen when the monitor is starting
its refresh period (meaning the screen is actualy being drawn).

Without vsync if you draw something half way and the monitor does a refresh
your object will be half done on the screen and then next frame it will be
completely drawn and will look flickery.

With vsync it decreases the flickery look, but its limited to drawing at the
refresh rate of your monitor…which commonly is 60 times a second!

this is why i think you are stuck at a maximum of 60 fps. I wouldnt worry
about it, but im not you (:> ----- Original Message -----

From: aleardo@libero.it (Alessandro Ardolino)
To:
Sent: Thursday, October 30, 2003 4:43 PM
Subject: Re: [SDL] Low Framerate

What’s wrong!!!
I’m very frustrated!

I’ve used SDL_DisplayFormat(),
cut off the frame limiter (I had this to get same fps on 2 PCs…),
almost sure not compile in debug mode,
trying to not updating the background every frame.

I’ve still only 60fps on P4…

I don’t want disturb you,
but it’s very stange!

Thanks to all

----- Original Message -----
From: “Roberto Prieto”
To:
Sent: Thursday, October 30, 2003 8:32 PM
Subject: Re: [SDL] Low Framerate

Hello, I have been seeing your code and I found two importants things:

  1. you don’t convert the load surfaces to screen format, currently there
    isn’t problem because I imagine you load BMP at 32bits color depth but
    if

you change this… you’ll have problems… so, you need to use
SDL_DisplayFormat(), you can see it in your source code (I had done a
few

changes on it).

  1. the most important and the main reason which you don’t get more
    frames

per second… you have a frame limiter in your code… (I suppose that
you

are using a code from an example or another project because this code’s
part
is in english language). whatever I don’t understand is how in a Pentium
4

machine the fps can exceed the 24fps limits that you have in your code.

With this modifications… I get +/- 170fps in software mode and more
than

1000fps in hardware mode… but I have doubts about your method to
calculate
the fps… but I don’t have more time… maybe is all right :slight_smile:

happy coding, see you!

Roberto Prieto
MegaStorm Systems © 2003
http://www.megastormsystems.com


–

// Testing code…

// —Includes—
#include “SDL.h”
#define FRAME_RATE 24

// Prototype
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y);

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=0;//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);
// —>Roberto: to test in software mode
//screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE);

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,*BackGround,*sprite,*temp;
walkMap=SDL_LoadBMP(“provaLocation0WalkMapLoRes.bmp”);
// —>Roberto: here, we convert surface loaded to screen format
if(walkMap!=NULL)
{
temp=SDL_DisplayFormat(walkMap);
SDL_FreeSurface(walkMap);
walkMap=temp;
}
BackGround=SDL_LoadBMP(“provaLocation0.bmp”);//carico l’immagine nella
nuova superficie
// —>Roberto: The same…
if(BackGround!=NULL)
{
temp=SDL_DisplayFormat(BackGround);
SDL_FreeSurface(BackGround);
BackGround=temp;
}
// —>Roberto: The same…
sprite=SDL_LoadBMP(“provaLocation0Sprite.bmp”);
if(sprite!=NULL)
{
temp=SDL_DisplayFormat(sprite);
SDL_FreeSurface(sprite);
sprite=temp;
}

//settiamo un colore alpha
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format, 255,
255,255));
//definiamo un RECT per posizionare lo sprite
int xpos=0,ypos=0;
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

SDL_Surface *mouseCursor=SDL_LoadBMP(“cursore.bmp”);
// —>Roberto: The same…
if(mouseCursor!=NULL)
{
temp=SDL_DisplayFormat(mouseCursor);
SDL_FreeSurface(mouseCursor);
mouseCursor=temp;
}
//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
deglieventi…
//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)
{
// —>Roberto: I don’t know what function are you using here… I
use

my function.
pixelColor = MyOwnGetPixel(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
coloridei 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
// —>Roberto: here, I switch off the limiter of FRAME_RATE per
second
//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);//
// —>Roberto: and here
//} //end check Framerate

}//end gameLoop

}//end main

// MyOwnGetPixel, it works with 8,16,24 and 32 bits
// the log system is switch off because this function is from my library
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y)
{

 Uint32 ret;

 // Bloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
if(SDL_LockSurface(s)<0)
{
//ILogSystem.Msg(" ?CRM32Pro [IPrimitives::GetPixel()] Error:
%s\n",SDL_GetError());
return 0;
}
}

// Depende del modo grafico
switch(s->format->BytesPerPixel)
{
// Modo 8bit con paleta
case 1:
 {
  ret=*((Uint8*)s->pixels + y * s->pitch + x);
     break;
 }

// Modo 16bit
case 2:
 {
  ret=*((Uint16*)s->pixels + y * s->pitch/2 + x);
     break;
 }

// Modo 24bit (muy lento)
case 3:
 {
  Uint8 *pix;
  int shift;
  Uint32 color;

  pix=(Uint8*)s->pixels + y * s->pitch + x * 3;
  shift=s->format->Rshift;
  color=*(pix+shift/8)<<shift;
  shift=s->format->Gshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Bshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Ashift;
  color|=*(pix+shift/8)<<shift;
  ret=color;
  break;
 }

// Modo 32bit
case 4:
 {
  ret=*((Uint32*)s->pixels + y * s->pitch/4 + x);
  break;
 }
}

// Desbloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
SDL_UnlockSurface(s);
}
return ret;
}


–

----- Original Message -----
From: "shred "
To:
Sent: Thursday, October 30, 2003 6:45 PM
Subject: Re: [SDL] Low Framerate

---------- Original Message ----------------------------------
From: “Alessandro Ardolino”
Reply-To: sdl at libsdl.org
Date: Thu, 30 Oct 2003 12:29:47 +0100

Hello,

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.

I’ve included a routine for print in sdtout.txt the fps I would.

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?

Thanks

You may want to make sure that you aren’t compiling in debug mode.
This

can really slow things down.

Shred


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Ok, 60fps sounds to vsync… but I’m not sure… you can test to switch off
SDL_DOUBLEBUF in SDL_SetVideoMode() and maybe… this increase the frame rate
(but you get a screen flickering…, it’s only to do more tests). You also
can test de hz of your monitor at 800x600, some of them has an option in its
OSD and you can see the frequency. Another possibility is your AGP bus (2x?
4x? 8x?) and your video card, I have an Athlon XP 2800+ and Radeon
9700Pro… but you can’t compare directly an Athlon against Pentium 4
without to consider the video card and AGP bus.
At last,you can send me your exe with your artwork (zipped) to
megastorm at megastormsystems.com and I can test directly your exe in my
machines.
good luck!

Roberto Prieto
MegaStorm Systems © 2003
http://www.megastormsystems.com> ----- Original Message -----

From: aleardo@libero.it (Alessandro Ardolino)
To:
Sent: Friday, October 31, 2003 1:43 AM
Subject: Re: [SDL] Low Framerate

What’s wrong!!!
I’m very frustrated!

I’ve used SDL_DisplayFormat(),
cut off the frame limiter (I had this to get same fps on 2 PCs…),
almost sure not compile in debug mode,
trying to not updating the background every frame.

I’ve still only 60fps on P4…

I don’t want disturb you,
but it’s very stange!

Thanks to all

----- Original Message -----
From: “Roberto Prieto”
To:
Sent: Thursday, October 30, 2003 8:32 PM
Subject: Re: [SDL] Low Framerate

Hello, I have been seeing your code and I found two importants things:

  1. you don’t convert the load surfaces to screen format, currently there
    isn’t problem because I imagine you load BMP at 32bits color depth but
    if

you change this… you’ll have problems… so, you need to use
SDL_DisplayFormat(), you can see it in your source code (I had done a
few

changes on it).

  1. the most important and the main reason which you don’t get more
    frames

per second… you have a frame limiter in your code… (I suppose that
you

are using a code from an example or another project because this code’s
part
is in english language). whatever I don’t understand is how in a Pentium
4

machine the fps can exceed the 24fps limits that you have in your code.

With this modifications… I get +/- 170fps in software mode and more
than

1000fps in hardware mode… but I have doubts about your method to
calculate
the fps… but I don’t have more time… maybe is all right :slight_smile:

happy coding, see you!

Roberto Prieto
MegaStorm Systems © 2003
http://www.megastormsystems.com


–

// Testing code…

// —Includes—
#include “SDL.h”
#define FRAME_RATE 24

// Prototype
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y);

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=0;//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);
// —>Roberto: to test in software mode
//screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE);

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,*BackGround,*sprite,*temp;
walkMap=SDL_LoadBMP(“provaLocation0WalkMapLoRes.bmp”);
// —>Roberto: here, we convert surface loaded to screen format
if(walkMap!=NULL)
{
temp=SDL_DisplayFormat(walkMap);
SDL_FreeSurface(walkMap);
walkMap=temp;
}
BackGround=SDL_LoadBMP(“provaLocation0.bmp”);//carico l’immagine nella
nuova superficie
// —>Roberto: The same…
if(BackGround!=NULL)
{
temp=SDL_DisplayFormat(BackGround);
SDL_FreeSurface(BackGround);
BackGround=temp;
}
// —>Roberto: The same…
sprite=SDL_LoadBMP(“provaLocation0Sprite.bmp”);
if(sprite!=NULL)
{
temp=SDL_DisplayFormat(sprite);
SDL_FreeSurface(sprite);
sprite=temp;
}

//settiamo un colore alpha
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format, 255,
255,255));
//definiamo un RECT per posizionare lo sprite
int xpos=0,ypos=0;
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

SDL_Surface *mouseCursor=SDL_LoadBMP(“cursore.bmp”);
// —>Roberto: The same…
if(mouseCursor!=NULL)
{
temp=SDL_DisplayFormat(mouseCursor);
SDL_FreeSurface(mouseCursor);
mouseCursor=temp;
}
//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
deglieventi…
//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)
{
// —>Roberto: I don’t know what function are you using here… I
use

my function.
pixelColor = MyOwnGetPixel(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
coloridei 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
// —>Roberto: here, I switch off the limiter of FRAME_RATE per
second
//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);//
// —>Roberto: and here
//} //end check Framerate

}//end gameLoop

}//end main

// MyOwnGetPixel, it works with 8,16,24 and 32 bits
// the log system is switch off because this function is from my library
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y)
{

 Uint32 ret;

 // Bloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
if(SDL_LockSurface(s)<0)
{
//ILogSystem.Msg(" ?CRM32Pro [IPrimitives::GetPixel()] Error:
%s\n",SDL_GetError());
return 0;
}
}

// Depende del modo grafico
switch(s->format->BytesPerPixel)
{
// Modo 8bit con paleta
case 1:
 {
  ret=*((Uint8*)s->pixels + y * s->pitch + x);
     break;
 }

// Modo 16bit
case 2:
 {
  ret=*((Uint16*)s->pixels + y * s->pitch/2 + x);
     break;
 }

// Modo 24bit (muy lento)
case 3:
 {
  Uint8 *pix;
  int shift;
  Uint32 color;

  pix=(Uint8*)s->pixels + y * s->pitch + x * 3;
  shift=s->format->Rshift;
  color=*(pix+shift/8)<<shift;
  shift=s->format->Gshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Bshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Ashift;
  color|=*(pix+shift/8)<<shift;
  ret=color;
  break;
 }

// Modo 32bit
case 4:
 {
  ret=*((Uint32*)s->pixels + y * s->pitch/4 + x);
  break;
 }
}

// Desbloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
SDL_UnlockSurface(s);
}
return ret;
}


–

----- Original Message -----
From: "shred "
To:
Sent: Thursday, October 30, 2003 6:45 PM
Subject: Re: [SDL] Low Framerate

---------- Original Message ----------------------------------
From: “Alessandro Ardolino”
Reply-To: sdl at libsdl.org
Date: Thu, 30 Oct 2003 12:29:47 +0100

Hello,

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.

I’ve included a routine for print in sdtout.txt the fps I would.

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?

Thanks

You may want to make sure that you aren’t compiling in debug mode.
This

can really slow things down.

Shred


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

If you use hardware surfaces and double buffer on windows then the flip just
exchanges two pointers and waits the screen refresh. Maybe you can measure
time excluding the flip. In this way you will measure the time used by your
game and be able to calculate the max frame rate you can expect.

Julien> ----- Original Message -----

From: dm2@mi.madritel.es (Roberto Prieto)
To:
Sent: Friday, October 31, 2003 11:59 AM
Subject: Re: [SDL] Low Framerate

Ok, 60fps sounds to vsync… but I’m not sure… you can test to switch off
SDL_DOUBLEBUF in SDL_SetVideoMode() and maybe… this increase the frame
rate
(but you get a screen flickering…, it’s only to do more tests). You also
can test de hz of your monitor at 800x600, some of them has an option in
its
OSD and you can see the frequency. Another possibility is your AGP bus
(2x?
4x? 8x?) and your video card, I have an Athlon XP 2800+ and Radeon
9700Pro… but you can’t compare directly an Athlon against Pentium 4
without to consider the video card and AGP bus.
At last,you can send me your exe with your artwork (zipped) to
megastorm at megastormsystems.com and I can test directly your exe in my
machines.
good luck!

Roberto Prieto
MegaStorm Systems © 2003
http://www.megastormsystems.com

----- Original Message -----
From: “Alessandro Ardolino”
To:
Sent: Friday, October 31, 2003 1:43 AM
Subject: Re: [SDL] Low Framerate

What’s wrong!!!
I’m very frustrated!

I’ve used SDL_DisplayFormat(),
cut off the frame limiter (I had this to get same fps on 2 PCs…),
almost sure not compile in debug mode,
trying to not updating the background every frame.

I’ve still only 60fps on P4…

I don’t want disturb you,
but it’s very stange!

Thanks to all

----- Original Message -----
From: “Roberto Prieto”
To:
Sent: Thursday, October 30, 2003 8:32 PM
Subject: Re: [SDL] Low Framerate

Hello, I have been seeing your code and I found two importants things:

  1. you don’t convert the load surfaces to screen format, currently
    there

isn’t problem because I imagine you load BMP at 32bits color depth but
if

you change this… you’ll have problems… so, you need to use
SDL_DisplayFormat(), you can see it in your source code (I had done a
few

changes on it).

  1. the most important and the main reason which you don’t get more
    frames

per second… you have a frame limiter in your code… (I suppose that
you

are using a code from an example or another project because this
code’s

part

is in english language). whatever I don’t understand is how in a
Pentium
4

machine the fps can exceed the 24fps limits that you have in your
code.

With this modifications… I get +/- 170fps in software mode and more
than

1000fps in hardware mode… but I have doubts about your method to
calculate
the fps… but I don’t have more time… maybe is all right :slight_smile:

happy coding, see you!

Roberto Prieto
MegaStorm Systems © 2003
http://www.megastormsystems.com


–

// Testing code…

// —Includes—
#include “SDL.h”
#define FRAME_RATE 24

// Prototype
Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y);

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=0;//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);
// —>Roberto: to test in software mode
//screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE);

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,*BackGround,*sprite,*temp;
walkMap=SDL_LoadBMP(“provaLocation0WalkMapLoRes.bmp”);
// —>Roberto: here, we convert surface loaded to screen format
if(walkMap!=NULL)
{
temp=SDL_DisplayFormat(walkMap);
SDL_FreeSurface(walkMap);
walkMap=temp;
}
BackGround=SDL_LoadBMP(“provaLocation0.bmp”);//carico l’immagine
nella

nuova superficie
// —>Roberto: The same…
if(BackGround!=NULL)
{
temp=SDL_DisplayFormat(BackGround);
SDL_FreeSurface(BackGround);
BackGround=temp;
}
// —>Roberto: The same…
sprite=SDL_LoadBMP(“provaLocation0Sprite.bmp”);
if(sprite!=NULL)
{
temp=SDL_DisplayFormat(sprite);
SDL_FreeSurface(sprite);
sprite=temp;
}

//settiamo un colore alpha
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format,
255,

255,255));
//definiamo un RECT per posizionare lo sprite
int xpos=0,ypos=0;
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

SDL_Surface *mouseCursor=SDL_LoadBMP(“cursore.bmp”);
// —>Roberto: The same…
if(mouseCursor!=NULL)
{
temp=SDL_DisplayFormat(mouseCursor);
SDL_FreeSurface(mouseCursor);
mouseCursor=temp;
}
//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
deglieventi…
//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)
{
// —>Roberto: I don’t know what function are you using here… I
use

my function.
pixelColor = MyOwnGetPixel(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
coloridei 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
// —>Roberto: here, I switch off the limiter of FRAME_RATE per
second
//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);//
// —>Roberto: and here
//} //end check Framerate

}//end gameLoop

}//end main

// MyOwnGetPixel, it works with 8,16,24 and 32 bits
// the log system is switch off because this function is from my
library

Uint32 MyOwnGetPixel(SDL_Surface *s, Sint16 x, Sint16 y)
{

 Uint32 ret;

 // Bloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
if(SDL_LockSurface(s)<0)
{
//ILogSystem.Msg(" ?CRM32Pro [IPrimitives::GetPixel()] Error:
%s\n",SDL_GetError());
return 0;
}
}

// Depende del modo grafico
switch(s->format->BytesPerPixel)
{
// Modo 8bit con paleta
case 1:
 {
  ret=*((Uint8*)s->pixels + y * s->pitch + x);
     break;
 }

// Modo 16bit
case 2:
 {
  ret=*((Uint16*)s->pixels + y * s->pitch/2 + x);
     break;
 }

// Modo 24bit (muy lento)
case 3:
 {
  Uint8 *pix;
  int shift;
  Uint32 color;

  pix=(Uint8*)s->pixels + y * s->pitch + x * 3;
  shift=s->format->Rshift;
  color=*(pix+shift/8)<<shift;
  shift=s->format->Gshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Bshift;
  color|=*(pix+shift/8)<<shift;
  shift=s->format->Ashift;
  color|=*(pix+shift/8)<<shift;
  ret=color;
  break;
 }

// Modo 32bit
case 4:
 {
  ret=*((Uint32*)s->pixels + y * s->pitch/4 + x);
  break;
 }
}

// Desbloqueamos la superficie
 if(SDL_MUSTLOCK(s))

{
SDL_UnlockSurface(s);
}
return ret;
}


–

----- Original Message -----
From: "shred "
To:
Sent: Thursday, October 30, 2003 6:45 PM
Subject: Re: [SDL] Low Framerate

---------- Original Message ----------------------------------
From: “Alessandro Ardolino”
Reply-To: sdl at libsdl.org
Date: Thu, 30 Oct 2003 12:29:47 +0100

Hello,

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.

I’ve included a routine for print in sdtout.txt the fps I would.

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?

Thanks

You may want to make sure that you aren’t compiling in debug mode.
This

can really slow things down.

Shred


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Using SDL_DisplayFormat(),
I’ve an increment in framerate.

On a P4 2.4GHZ 256mb RAM and an ATI IGP 32mb (it’s a laptop)
the framerate is 60fps.

On a AMD 1.7xp 256mb RAM and a GeforceFX 5200 128mb,
I’ve a framerate of 86 fps.
I’ had 22fps on this system first.

Now the performance are better,
but so far from 800/1000 fps…

Alessandro

#On a P4 2.4GHZ 256mb RAM and an ATI IGP 32mb (it’s a laptop)
#the framerate is 60fps.
#On a AMD 1.7xp 256mb RAM and a GeforceFX 5200 128mb,
#I’ve a framerate of 86 fps.
#I’ had 22fps on this system first.
#Now the performance are better,
#but so far from 800/1000 fps…

I am not sure how you calculate you framerate, but make sure you do
calculate potential_framerate and not actual_framerate.

The actual framerate depends solely of what video mode you are
currently using. For example, my current video mode uses 60Hz, and I
can’t (easily) change that in my games.

The potential framerate, on the other hand, is given by

pot_fps = 1000 / msec_to_render;

… where msec_to_render contain a measure of how many milliseconds the
rendering of the graphics took last time around the game loop. The
idea with potential framerate is to give a measure of how fast the
graphics could ideally be rendered, if not limited by the actual
framerate and such.

Now, lets say you have a function called render() which does all the
rendering, but DOESN’T do any vsync or any other video-beam
synchronization. Then you could use the following code to get an
approximation to the potential framerate of your game:

Uint 32 before, after, msec_to_render;
float pot_fps;
before = SDL_GetTicks();
render();
after = SDL_GetTicks();
msec_to_render = after - before;
pot_fps = 1000.0 / (float)msec_to_render;

Good luck, and don’t forget to do the vsync’ing or whatever you do
also, or else you would get tearing…

/Olof

my problem was with SDL_DisplayFormat and
with refresh rate of monitors.

thanks to all
Alessandro