Link to home
Start Free TrialLog in
Avatar of blaze030297
blaze030297

asked on

Flickering graphic


I need to move some graphic objects on the screen without they flicker.
So (i've Turbo C 1.0) i tried to use the 'setvisualpage' and the
'setactivepage', modifying graphic in the invisible page and switching
beetween pages. I thought in this way i could have stable images.
But it doesn't work :(

To be more precise: the following code is a good example of my problem.
Let there be 2 pages (0 and 1)

Does anyone know why the line on the screen flickers?

setcolor(YELLOW);    
setvisualpage(0);
setactivepage(0);

line(40,40,300,140);    // draws a yellow line on page 0
setactivepage(1);
line(40,40,300,140);    // draws an identical line on page 1

int p=0;              // starting 'visual page'

for (long i=0; i<1000; i++)    // just a few time of suffering :)
{
 p=1-p;                   // switch beetween pages
 setactivepage(p);    // sets active page as the invisible one
 setcolor(BLACK);      
 line(40,40,300,140);  // deletes the line
 setcolor(YELLOW);
 line(40,40,300,140);  // redraws the line in the same place
 setvisualpage(p);     // shows the hidden page
}
ASKER CERTIFIED SOLUTION
Avatar of BenWeiss
BenWeiss

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blaze030297
blaze030297

ASKER

Hi, Ben
too bad i'm almost sure that there are
two pages. I've tried with code like:

setactivepage(0);
setvisualpage(0);
line(0,0,50,50);
setactivepage(1);
line(600,0,400,100);
getch();
....
setvisualpage(1);
getch();
....
setvisualpage(0);

And the behaviour seems to be correct.
At start i can see the first line and not the second.
When i press a key i can see the second line.
When i press a key again i can see the
first line again.
So i think there are actually two pages.
(after all i use only a 640x350x16 resolution)


Blaze, I have to agree with BenWeiss... The BGI is horrible. Making some graphic functions is VERY easy. If you'd like, I could show you how / send you some code. You'll save yourself alot by ditching the BGI. (IMHO)
Blaze,

Okay, then it may be that you are in fact using two video pages.  However, consider also that you are using BGI, and can't be sure how it's handling this.  Probably it's making a BIOS call, or even a VESA one, both of which can be slow.

Also, since you're using a 16 color mode, you're actually using four color planes.  This means that each of your pixels has to be drawn four times!  This is one of the reasons that any current video game you find is in 256 color mode...because it doesn't use color planes, just a byte per pixel.

An excellent book that you might try is "Flights of Fantasy".  It not only goes into how to write fast graphics routines, but how to write a fast 3D graphics engine.

Ben Weiss
Flickering is due to the fact you write the screen when the screen is refreshed... to avoid flickering you have to wait that the refreshing is at the beginning of the screen to be sure a picture wouldn't be draw in two passes.

Raky, do you know if there is a way to
wait the refreshing in C?
Or it can be done only in Assembly?
There is a way to wait the refreshing in C :-( but i can't remember me ... Wait, ...

you have just to look for a register;, but I don't really know which one, but if you find it, you have to wait that this register is set to 0, for flipping the page