I used to use a timer to limit the frame rate to 60 Hz too. But on Windows, I found that DwmFlush() seems to act like WaitVSync(), so I've been using that in preference for years now. I think this is undocumented behaviour. I guess what it actually does is wait until the compositor is ready for another frame.<p>To be able to call that function, I LoadLibrary("dwmapi.dll"), and then GetProcAddress(dwm, "DwmFlush").
Perfect companion for this C graphics library: <a href="https://github.com/tsoding/olive.c">https://github.com/tsoding/olive.c</a>
Is there any similar tutorial for XCB? Most documentation only covers libx11, and trying to extrapolate libxcb usage from that is tricky at best and heisenbug-prone at worst.
Very nice! I like that it's a single header. I wrote something similar although it's not single header, doesn't do audio, and no X11 backend <a href="https://github.com/samizzo/pixie">https://github.com/samizzo/pixie</a>. I use mine as a backend for Windows ports of MS-DOS demos that I make.
A similar x-platform library called TiGR (Tiny GRaphics):<p><a href="https://github.com/erkkah/tigr">https://github.com/erkkah/tigr</a><p>Brief discussion:<p><a href="https://news.ycombinator.com/item?id=34310208" rel="nofollow">https://news.ycombinator.com/item?id=34310208</a>
Very cool!<p>This example I think needs editing:<p><pre><code> memset(f->buf, rgb, f->width*f->height*sizeoof(uint32_t));
</code></pre>
it's described as a way to "fill the complete framebuffer with a solid colour", but 'rgb' is shown in the previous snipped to be 'uint32_t'. That is not how 'memset()' [1] works, it will only use the least significant 8 bits of the 'int'-typed value argument. So it would use whatever blue bits where in 'rgb', only.<p>For clearing (all zero) it's usable, and then I would recommend writing it as:<p><pre><code> memset(f->buf, 0, f->width * f->height * sizeof *f->buf);
</code></pre>
this both fixes the typo ("sizeoof" sounds like a C lecturer being punched in the guts), and avoids duplicating the type and instead inferring it from the actual object, which is more DRY and a style I've been advocating for ... years.<p>[1]: <a href="https://man7.org/linux/man-pages/man3/memset.3.html" rel="nofollow">https://man7.org/linux/man-pages/man3/memset.3.html</a>
since everyone else is posting links to their similar libraries, i thought i'd post mine too, <a href="https://gitlab.com/kragen/bubbleos/-/tree/master/yeso" rel="nofollow">https://gitlab.com/kragen/bubbleos/-/tree/master/yeso</a><p>it's probably a bit more efficient than fenster on x-windows because it uses shared memory, and i think the programming interface is a little nicer (see the readme above for code examples)<p>apps i've written in yeso include an adm-3a terminal emulator, a tetris game, a raytracer, an rpn calculator, a fractal explorer, and so on<p>i haven't ported yeso to win32/64, macos, android, or the browser canvas yet, just x-windows, the linux framebuffer (partly), and a window system implemented in yeso called wercam<p>it includes bindings for c, python (via cffi), and lua (via luajit's ffi), and presumably you could use it from zig or rust in the same way as fenster, but i haven't tried
I think this needs much more complexity to be useful.<p>For the rendering, ideally it needs GPU support.<p>Input needs much more work, here's an overview for Windows: <a href="http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/" rel="nofollow">http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_key...</a><p>Windows' Sleep() function has default resolution 15.6ms, that's not enough for realtime rendering, and relatively hard to fix, ideally need a modern OS and a waitable timer created with high resolution flag.<p>Here's my attempt at making something similar, couple years ago: <a href="https://github.com/Const-me/Vrmac">https://github.com/Const-me/Vrmac</a>
If anyone is interested in getting into zig, we made a library that has similar goals (and can run on WASM in the browser): <a href="https://github.com/ibebrett/zigzag">https://github.com/ibebrett/zigzag</a>
Very similar to minifb:<p><a href="https://github.com/emoon/minifb">https://github.com/emoon/minifb</a>, <a href="https://docs.rs/minifb/latest/minifb/" rel="nofollow">https://docs.rs/minifb/latest/minifb/</a>, <a href="https://news.ycombinator.com/item?id=24172362" rel="nofollow">https://news.ycombinator.com/item?id=24172362</a>
Wonderful. I really wanted something like this to do Graphic the "hard way", also the most fun way... I was trying to use Tcl-TK for that but this seems a lot lower level, perfect for what I wanted to do which is to write a small GUI toolkit for tiny apps.
I did something similar to load an image in windows/linux <a href="https://imadr.me/cross-platform-window-in-c/" rel="nofollow">https://imadr.me/cross-platform-window-in-c/</a>
"raylib" comes to mind, as it is a graphics library also inspired by the Borland BGI graphics library.<p>- Anyone with experience in it / any possible synergies?<p>[<a href="https://en.wikipedia.org/wiki/Raylib" rel="nofollow">https://en.wikipedia.org/wiki/Raylib</a>]
This is very cool, but if I were doing such things I'd just use SDL (<a href="https://www.libsdl.org/" rel="nofollow">https://www.libsdl.org/</a>)
Not so minimal, but if you need GPU rendering I wrote this: <a href="https://github.com/jacereda/glcv">https://github.com/jacereda/glcv</a>
This is extremely useful, and the page is beautifully written. Some people write absurd electron behemoths, and then there's this jewel of elegance.<p>Could this be compiled as an αpε? Such a thing would make many heads explode.