Solved

Flickering graphic

Posted on 1997-03-13
7
637 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

831 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