Graphics.h refresh screen

扶醉桌前 提交于 2019-12-13 06:10:44

问题


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.



来源:https://stackoverflow.com/questions/35998602/graphics-h-refresh-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!