View Full Version : ClrScr Without Flashing
13-05-2007, 02:38 PM
Libraries/API: Crt :P
Ok, you know how when you clrscr very often, you get that annoying flash where for a split second, the screen is empty? How do you avoid this?
13-05-2007, 03:28 PM
use double buffering.
13-05-2007, 04:48 PM
As Delfi says, use Double Buffering.
Traditionally, the screen was cleared to allow sprites to be quickly drawn to the screen at a new location, erasing the sprite at the last location.
Before it became inexpensive to blit an image from memory to the screen every frame, there were many tricks used to minimise the amount of data written to the screen each frame.
The simplest of these was to clear the screen.
Another method was to use dirty rectangles, this involved a lot more work, but still allowed you to only update a single surface and only copy the areas which had changed..
It's much faster to bulk fill a piece of memory with 0 than it is to copy from another location, so clrscr was used a lot of the time for simple apps.
The major downside is that if you clrscr on the memory used to draw to the screen, there is a good chance that this image will be drawn to the monitor before you've had a chance to draw the rest of your images.. hence the flicker.
So, the double buffering method was created.
You have 2 pieces of memory. One of which you fill with the current frame's data.
Once a scene has been rendered 100%, you make the completed image, the current display image. Then you work on the other image, swapping the buffers as the images are completed.
This means that you've always got an in-progress image and a completed image. The completed image being the one currently on display.
This method means there is no flickering but it does mean that you need 2 pieces of memory to render to, effectively doubling the video memory requirements for your game.
This technique doesn't just apply to bitmapped graphics either, it applies just as well to text based games.
2 pieces of memory. Working and Display.
You render to the Working surface , then flip your surfaces once you're finished. So current working image becomes current display image.
Keep repeating this as you complete frames and you'll get no flickering as the monitor always displays a completed image.
Some libraries like SDL help you to do this by hiding the mechanics from you, requiring that you only call SDL_flip (or something like that) if you're doing it yourself, you'll have to do a bit of research to find the best way. (ready made libraries are great :))
I hope this helps and Good luck.
If I've made an error in my description or terminology and you spot it, you know enough to not be in the help me forum ;)
14-05-2007, 05:16 AM
OK. It's a text-based app, but it flickers cause it ClrScr's about 1.2 times per second... I figure it would look more professional to not have a flicker.
14-05-2007, 07:13 AM
You could clear the screen in a different way. Just copy your black (or whatever) screen in to the memory and than instead of calling ClrScr, copy back from the memory what has been written earlier. No flickering guarantee ;)
Ehm and this is exactly what jasonf wrote earlier :oops:
But it also works for text-based apps.
Powered by vBulletin® Version 4.1.10 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.