C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-12-2001, 02:07 PM   #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?
Hannwaas is offline   Reply With Quote
Old 09-12-2001, 02:28 PM   #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/
Nick is offline   Reply With Quote
Old 09-12-2001, 07:03 PM   #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
Stoned_Coder is offline   Reply With Quote
Old 09-13-2001, 09:59 AM   #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?
Hannwaas is offline   Reply With Quote
Old 09-14-2001, 03:32 AM   #5
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,812
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.
Bubba is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 09:23 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22