Solved

Flickering graphic

Posted on 1997-03-13
7
641 Views
Last Modified: 2008-03-17

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
}
0
Comment
Question by:blaze030297
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 2

Accepted Solution

by:
BenWeiss earned 70 total points
ID: 1249546
blaze,

I don't have my docs here, but I'd be willing to bet that you're using a video mode that only has one video page.  Check your video card, find out how much VRAM you have, and check the video mode you're using in the documentation.  If you find that you can't find that info, try using a 320x200 - 16 color mode, and see if the problem persists.

Also, as a former video-game programmer, I would highly recommend forgetting Borland's BGI (Borland Graphic Interface).  It's pretty well known to be slow.  You'd be better off buying or checking out from a library a graphics book, and learning how to implement fast graphics routines in Assembly Language.  However, since you're running Turbo C, while you might be able to do inline assembly (I can't remember if it has that capability), I do know that it doesn't come with Turbo Assembler.  However, you can get almost as good graphics in C if you write your graphics routines using integer math and pointers.

Ben Weiss
0
 

Author Comment

by:blaze030297
ID: 1249547
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)


0
 

Expert Comment

by:gcormier
ID: 1249548
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)
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 2

Expert Comment

by:BenWeiss
ID: 1249549
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
0
 
LVL 1

Expert Comment

by:raky
ID: 1249550
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.

0
 

Author Comment

by:blaze030297
ID: 1249551
Raky, do you know if there is a way to
wait the refreshing in C?
Or it can be done only in Assembly?
0
 
LVL 1

Expert Comment

by:raky
ID: 1249552
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



0

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question