Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » slow graphics, but move fast when window is moved

This thread is locked; no one can reply to it. rss feed Print
slow graphics, but move fast when window is moved
peter walker
Member #8,572
April 2007

Hi everyone, I was hoping someone could help me.

I am finding that my graphics routine is running slow. I converted my code from VC++ Windows GDI to Allegro and I am finding that there is a significant decrease in the speed in which the graphics is being updated on the screen. A snippet of my code is below. All it does is create a window and place 3 circles in the window and updates the location of those objects via the Update() function.

The really strange thing is that if I move the window created by Allegro i.e. the window inwhich all the graphics is being displayed, the graphics move much faster.

Would anyone know what is going on?

Cheers,
voirin

----------------------------------

1Object * member = new Object[numberOfObjects];
2 
3void moveCircle(){
4
5 {... other routines}
6 
7 for ( int i = 0; i < numberOfObjects; i++ )
8 {
9 member<i>.Update( );
10 member<i>.Draw(screen); // draws circle (screen, x, y, r, color);
11 }
12}
13 
14 
15int main(){
16 
17 member[0] = Object(0,0);
18 member[1] = Object(10,10);
19 member[2] = Object(20,-15);
20 
21 allegro_init();
22 install_keyboard();
23 set_color_depth(8);
24 set_gfx_mode( GFX_AUTODETECT_WINDOWED, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0);
25 
26 while( !key[KEY_ESC]){
27 moveCircles();
28 }
29
30 return 0;
31}
32END_OF_MAIN();

mEmO
Member #1,124
March 2001
avatar

You should use the desktop color depth, use desktop_color_depth() to get it.

---------------------------------------------
There is only one God, and Connor is his son!
http://www.memocomputers.com
Happy birthday!

Archon
Member #4,195
January 2004
avatar

You should control the execution speed of your program with rests.

gnolam
Member #2,030
March 2002
avatar

... no. No you shouldn't. Use proper timing. Not rest(). :P

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Neil Walker
Member #210
April 2000
avatar

That code suggests you're drawing everything directly to the screen. Use a backbuffer instead, e.g.

BITMAP* double=NULL;

... somewhere in initialisation...
double=create_bitmap(SCREEN_W,SCREEN_H);
void moveCircle(){
       

        {... other routines}
        clear(double);
  for ( int i = 0; i < numberOfObjects; i++ )
  {
    member<i>.Update( );
    member<i>.Draw(double); // draws circle (screen, x, y, r, color);
  } 
        blit(double, screen, etc, etc);

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

peter walker
Member #8,572
April 2007

Thanks for the replies everyone. I'll incorporate the suggestions into my code and see how well it executes. Im away from my code till monday.

I want the graphics to run as fast as possible. That is my primary aim - fast object movement - no rest or pauses in the program.

Thanks again
cheers, voirin

Kris Asick
Member #1,424
July 2001

Quote:

You should control the execution speed of your program with rests.

Quote:

... no. No you shouldn't. Use proper timing. Not rest().

Actually, you're both right. Proper timing should be implemented using Allegro's timer system or the Windows High Performance Timer, but you should also add a rest(0) or Sleep(0) to the end of a program loop so that CPU time can be properly given to Allegro's other threads and to other programs running in the background.

Also, if the application runs faster while you're moving the window than when not you might want to disable your background applications and see if one of them is eating up the resources your application wants.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Audric
Member #907
January 2001

peter walker said:

I want the graphics to run as fast as possible. That is my primary aim - fast object movement - no rest or pauses in the program.

OK for the idea of "timing your drawing code", but don't dismiss rest(0).

If you don't explicitely yield to Windows when it's the best moment to do so, Windows WILL suspend your program at random moments, and it will cause an extra waste of time every time it's in the middle of a sensitive operation - like a screen redraw, with locked DirecX surfaces.

Neil Black
Member #7,867
October 2006
avatar

[n00b question] I've asked here before, but I still don't know how to use proper timing instead of rest() I'll probalby just go look it up in the manual though, so don't worry.[/n00b question]

Goalie Ca
Member #2,579
July 2002
avatar

Aah.. time to spread the love of the wiki: http://wiki.allegro.cc/Timers
And instead of rest() i recommend my semaphore solution. Of course you can call other semaphore functions to implement all of the regular volatile int models if you so need for your un-lagger or whatever.

note: as a community we really should post all answers to common (and not so common) questions on the wiki and points users to that.

-------------
Bah weep granah weep nini bong!

Go to: