-
BGI C Help!!!!
Hi
Im using the borland turbo C/C++ compiler and i did some animation of a simple drawing that is 20*20 in size.
Im using the getimage and putimage to put it up and redraw it in order to move it. I entered 2 objects to the buffers (with allocation) and it works ok when they are working seperately.
But when im running them both onscreen they seem to...BLINK. when i disable one it moves smoothly...Now cant be that the bgi is too slow to run 2 objects smoothly?!
I use a third empty buffer inorder to "delete" the former object position.
it looks like this:
while (ch!=27) {
putimage(x,y,buff[1],COPY_PUT); //the object
delay(7);
putimage(x,y,buff[2],COPY_PUT); // Overrides the former with blank.
y+=1;
}
thats basicly how it looks like (for 1 object).
Like i said when i use a second one (in like different position of the screen to run arround it just blinks....HELP).
Any idea?
Thanks
-
You need to wait for the vertical refresh before messing with the screen
http://www.inversereality.org/files/verticalsync.pdf
Basically
- wait for vertical retrace (see the doc)
- remove old
- draw new
-
If you are not using a double buffer all of your images will blink. This is because each image will disappear, albeit for a very brief time, and reappear. I do not know how to use a double buffer in BGI graphics. But if you drop BGI and move to accessing the hardware directly I can help.
Do what Salem says concerning the video refresh. Even with a double buffer if you do not wait for refresh you will get artifacts since you may be updating in the middle of a refresh. This, unfortunately, slows your graphics down to the rate of the refresh since you are waiting on the BIOS.
Go to www.brackeen.com and drop the BGI idea. BGI is great for starting out but it is not designed for the kind of speed needed in games or animation. It is far easier to drop BGI. You'll be amazed at how simple it is to manipulate the graphic hardware.