Solved

Flickering graphic

Posted on 1997-03-13
7
648 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C hashtable library 3 114
An API detour question 7 109
If a cell in a range equals "YES" return specific Test. 4 51
Excel formula to calculate ID # 4 43
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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and reading files 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.

751 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