delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/02/18:17:09

Message-ID: <386FCE52.DA9E14BC@sympatico.ca>
From: Travis Capener <budtrav AT sympatico DOT ca>
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: allegro
References: <OCMb4.65$Va DOT 1217 AT weber DOT videotron DOT net>
Lines: 69
Date: Sun, 02 Jan 2000 22:16:52 GMT
NNTP-Posting-Host: 216.209.46.219
X-Trace: news20.bellglobal.com 946851412 216.209.46.219 (Sun, 02 Jan 2000 17:16:52 EDT)
NNTP-Posting-Date: Sun, 02 Jan 2000 17:16:52 EDT
Organization: Sympatico
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi Valkir,

There are many ways to do it. Keeping with the way you started, it isn't necessary to erase
the whole screen each frame. You only need to erase the area where the box was drawn, then
move the box, and redraw it. Here is how I re-wrote the code:

#include <allegro.h>

int posX=10;
void draw_screen(BITMAP *bmp)
{
 int x,y;
 for(x=posX;x<posX+20;x++)    // erase old box
  for(y=100;y<120;y++)
   putpixel(bmp,x,y,65);

 posX++;

 for(x=posX;x<posX+20;x++)   // draw new box
  for(y=100;y<120;y++)
   putpixel(bmp,x,y,45);

}

int main(void)
{
   BITMAP *bmp;
   int card = GFX_AUTODETECT;
   int x,y;

   /* set up Allegro */
   allegro_init();
   install_keyboard();
   set_gfx_mode(card, 800,600, 0, 0);
   set_color_depth(8);

   bmp = create_bitmap(SCREEN_W, SCREEN_H);

   for(x=0;x<800;x++)        // fill screen with background colour
    for(y=0;y<600;y++)
     putpixel(bmp,x,y,65);

   while (!keypressed()) {
     draw_screen(bmp);
     vsync();
     blit(bmp, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
   }

   destroy_bitmap(bmp);

   return 0;
}

Obviously to get even better performance you'll want to use a sprite. It's a *lot* more work
for the computer to draw things a pixel at a time rather than blitting a sprite.



Valkir wrote:

> Hello.
> I have that simple program, just to test the speed of allegro.
> here it is.
> int posX=10;
> void draw_screen(BITMAP *bmp)
> {

[...and so on...]

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019