Graphics.h refresh screen

2019-09-09 17:17发布

问题:

I made a small program that displays a 3d cube that you can scale on any axis using the arrow keys. Only problem is that im using cleardevice(); for refreshing the cube ( so that there is no "smearing" when scaling the cube ). that works fine its just that every time the cube refreshes using this method the screen goes black for a split second resulting in annoying flickering. Is there a better way of refreshing the screen every time the user changes the cube? I did actually research this but i wasnt able to find anything suitable (Maybe im just bad at researching but i couldn't find anything for the live of me)

回答1:

there are 2 ways to handle this:

  1. Double buffering

    I do not use BGI so I stick to their docs. for WinBGIm you can use

    • int swapbuffers (void);

    On oldstyle BGI use this:

    int oldv = getvisualpage( );
    int olda = getactivepage( );
    setvisualpage(olda);
    setactivepage(oldv);
    
  2. use vertical synchronization with monitor

    You need to wait for VSync before calling cleardevice();. On DOS you can use VGA BIOS or direct VGA/VESA access to obtain the signal. On higher OS you need to use some kind of gfx API or Driver API to get VSync.

    In both cases consult the documentation for target platform.