Linux framebuffer graphics and VSync

前端 未结 2 558
我寻月下人不归
我寻月下人不归 2021-01-13 22:40

I\'m making a game in C that works on the linux framebuffer. So far I have a red 100x100 square that moves in tandem with the mouse, just like a pointer. I have implemented

2条回答
  •  情歌与酒
    2021-01-13 23:02

    Unfortunately I've learned the hard way that @Steven Bell's answer isn't quite right. Though he is right that a screen refresh could easily happen during the memcpy the proper resolution is not to create a virtual framebuffer of double the size of the screen and pan between them as so many threads suggest. Anyone who attempts this solution will receive an error described here: invalid argument error when setting yres_virtual in fb_var_screeninfo.

    Per this thread: https://forum.odroid.com/viewtopic.php?f=55&t=8741 it is not quite possible to truly double buffer the framebuffer (/dev/fb0, although I have heard that the raspberry PI might be an exception to this rule). But that doesn't mean there isn't a way to double buffer in linux using low level graphics.

    The real solution here is to use libdrm (/dev/dri/card0) to draw low level graphics to the screen. There is a really nice example of how to do this here: https://github.com/dvdhrm/docs/blob/master/drm-howto/modeset-vsync.c that I used myself when I was trying to solve this problem.

    Anyways I hope I've saved someone the amazing headache that I had to go through to figure this out in the future.

提交回复
热议问题