Solved

Flickering graphic

Posted on 1997-03-13
7
628 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

by:BenWeiss
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion 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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now