Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
Developers
 Brain Games Forums : Developers
Subject Topic: which is faster? sdl or allegro ? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
ttwttmttj
Guest
Guest


Joined: 25 January 2003
Posts: -368
Posted: 02 June 2004 at 09:24 | IP Logged Quote ttwttmttj

hi!

  how to calculte the cost of time :bliting a picture to screen ?

  below is two pieces of code , one is wrote with sdl , and the other with allegro.

  after running the code i got the result:

  the one with sdl is working with 20fps , and the allegro is working with 50fps

  same envionment , same picture , same 640x480x16 mode

  (linux 2.4.26 with rivafb driver) 

  i wonder to know why , is allegro faster then sdl ? or my code is mistake ?

//SDL source

SDL_INIT(SDL_INIT_VIDEO);
SDL_SetVideoMode(640,480,16,SDL_SWSURFACE);
SDL_Surface *pbmp = IMG_Load(abc.bmp);  // abc.bmp is a 640x480x16bit picture
SDL_Surface * pScreen = SDL_GetVideoSurface();
cout<<time(NULL)<<endl;
for(int i=0;i<times;++i) // times = 1000
{
  SDL_BlitSurface(pbmp,NULL,pScreen,NULL);
  SDL_Flip(pScreen);
}
cout<<time(NULL)<<endl;

while the code running , my moniter working at:37.5K/75hz
1086172036
1086172082
so, 46s / 1000 is 21.7fps

//ALLEGRO source
allegro_init();
set_color_depth(16);
set_gfx_mode(GFX_FBCON,640,480,0,0);

PALETTE the_palette;
BITMAP * the_image = load_bitmap(abc.bmp,the_palette);
set_palette(the_palette);

cout<<time(NULL)<<endl;
for(int i=0;i<1000;++i)
  blit(the_image,screen,0,0,0,0,the_image->w,the_image->h);
cout<<time(NULL)<<endl;

while the code running , my monitor working at:31.5k/60hz
1086172468
1086172487
so 19seconds/1000frames is: 52.6fps

  why ?


  wmj

Back to Top View ttwttmttj's Profile Search for other posts by ttwttmttj Send Private Message Add to Buddy List
 
Popolon
Admin Group
Admin Group
Avatar

Joined: 05 November 2002
Location: Spain
Posts: 3135
Posted: 02 June 2004 at 09:45 | IP Logged Quote Popolon

I do not know a lot about Allegro, but I see two points to discuss in this code:

- In SDL if you want to be sure that the image is optimized for blitting you have to do this:

SDL_Surface *pbmp_tmp = IMG_Load("abc.bmp");
SDL_Surface *pbmp = SDL_DisplayFormat(pbmp_tmp);
SDL_FreeSurface(ptmp_tmp);

The SDL_DisplayFormat function converts the bitmap to the specific format needed for the fastest blitting with the current video settings.

- In the Allegro code I do not see the FLIP instruction, isn't it needed?

Back to Top View Popolon's Profile Search for other posts by Popolon Visit Popolon's Homepage Send Private Message Add to Buddy List
 
guest
Guest
Guest


Joined: 25 January 2003
Posts: -368
Posted: 02 June 2004 at 12:52 | IP Logged Quote guest

thanks for reply.

after i modified the code like your reply.

1086201691

1086201737

so 46seconds/1000 so result is 21.739fps

compared with allegro it's really slow.

Back to Top View guest's Profile Search for other posts by guest Send Private Message Add to Buddy List
 
Popolon
Admin Group
Admin Group
Avatar

Joined: 05 November 2002
Location: Spain
Posts: 3135
Posted: 02 June 2004 at 16:13 | IP Logged Quote Popolon

there's another point in the code where maybe you can gain speed, when you set the video mode, try to set it hardware accelerated, i.e:

SDL_SetVideoMode(640,480,16,SDL_HWSURFACE|SDL_DOUBLEBUFFER);

otherwise you are performing software blits.

Moreover, you can also try to put the loaded surface in a hardware surface by creating a new hardware surfaces an blitting the loaded image there (otherwise you will be moving the surface from main memory to video memory at each frame)

SDL is designed to give the programmer complete control and sometimes you have to do a lot of things by hand (such as moving surfaces from main memory to video memory to achieve hardware accelerated blits, etc.).

Moreover, there's one thing that I do not understand in the allegro code: when does it perform the screen flip? (in SDL you use the SDL_Flip() instruction, or the SDL_FlipRectangles) but how can you know that Allegro is flipping after each blit?

And as a last point, you should check whether your code is synchronizing with the screen refresh (when performing the flip), since this can drastically reduce the fps.
Back to Top View Popolon's Profile Search for other posts by Popolon Visit Popolon's Homepage Send Private Message Add to Buddy List
 
Devilkin
Guest
Guest


Joined: 25 January 2003
Posts: -368
Posted: 11 September 2004 at 05:26 | IP Logged Quote Devilkin

The way the allegro code is written there is NO double buffering. This is driectl bluitting the image to video. I think thats all there is to it, SLD is waiting or retrace and flipping pages, allegro is just drawing straight to video memory
Back to Top View Devilkin's Profile Search for other posts by Devilkin Send Private Message Add to Buddy List
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.01
Copyright ©2001-2003 Web Wiz Guide

This page was generated in 0,1719 seconds.