Thread: Speeding up vga graphics and allegro tutorial

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    79

    Speeding up vga graphics and allegro tutorial

    I have a program that reads a sprite from a file and stores it in a twodimensional array. It then draws the sprite to the screen from the array.
    The problems is that sometimes the picture flickers (after all it's quite a lot of pixels to plot, and NO, I do not use BIOS interrupts to plot them).
    Is ther any (easy) way to speed up the drawing?
    I use djgpp btw.

    Also, does anyone know of a good tutorial for the allegro game library?

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    You should know that allegro as functions to load bitmaps
    and blit them. Just drawing the pixels bit by bit with like
    putpixel is very slow.

    http://www.grandgent.com/gfoot/

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Alternatively you could use memcpy() to copy the array to screen memory. Check out the vga tutorials here
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    Thanks for the help.
    About allegro tutorials, I downloaded one called Allegro Vivace but I haven't had time to look much on it yet. Anyone know if it's good or should I try another one?

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The best way to do fast bit blts is either use a fast library and call those functions specific to bit blts or use assembly to code your own. I've tried using the various memory functions in C to do this, but I've found that trying to blt 1 line of pixels from a bitmap to the screen or to a buffer using the memory functions is actually slower than just plotting the pixels via a pointer. Memcpy also requires that the area to be blitted extend from the left side of the screen to the right side. If you have a small bitmap, this can be a waste of time.

    Also for a speed increase do not store your bitmaps in a two dimensional array. It is far slower to access a two dimensional array than a one dimensional or linear array. To access a one dimensional array using two values:

    Offset=y*Width+x

    y = the vertical component
    x = the horizontal component
    Width= the Width of the buffer, image, sprite, etc.
    Offset=the number which would refer to the value at x,y


    As well for very quick calculations use bit shifts instead of multiplications.
    Offset=(y<<6)+(y<<8)+x
    This will give you the offset in memory from segment A000h to plot a pixel at x,y in mode 13h - 320x200x256.
    I've tried turning optimizations on for those who are compiler reliant, but using bit shifts still seems to be faster than just using compiler optimizations.

    As for flickering, it should not do that. Check out www.brackeen.com and www.programmersheaven.com for information on creating a double-buffer for your program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  2. Question about allegro and other graphics libraries....
    By o0obruceleeo0o in forum Game Programming
    Replies: 2
    Last Post: 06-11-2003, 11:02 PM
  3. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM
  4. Allegro graphics trouble
    By Brian in forum C++ Programming
    Replies: 0
    Last Post: 02-25-2002, 02:36 PM
  5. allegro graphics library for linux
    By oldcoyote in forum Linux Programming
    Replies: 3
    Last Post: 10-03-2001, 10:24 AM