Speeding up vga graphics and allegro tutorial

This is a discussion on Speeding up vga graphics and allegro tutorial within the C++ Programming forums, part of the General Programming Boards category; I have a program that reads a sprite from a file and stores it in a twodimensional array. It then ...

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?

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.