Results 1 to 5 of 5

Thread: ClrScr Without Flashing

  1. #1

    ClrScr Without Flashing

    System: WinXP
    Compiler/IDE: FreePascal.
    Libraries/API: Crt

    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?
    --MagicRPG--

  2. #2

    ClrScr Without Flashing

    use double buffering.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #3

    ClrScr Without Flashing

    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.


    So basically,

    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.

    [size=9px]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 [/size]

  4. #4

    ClrScr Without Flashing

    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.
    --MagicRPG--

  5. #5

    ClrScr Without Flashing

    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 ops:
    But it also works for text-based apps.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •