Live data from Hacker News

Minimal Cross-Platform Graphics

zserge.com

1–10 of 67 posts

Re: Minimal Cross-Platform Graphics

#3
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.

To be able to call that function, I LoadLibrary("dwmapi.dll"), and then GetProcAddress(dwm, "DwmFlush").

Re: Minimal Cross-Platform Graphics

#4
I think this needs much more complexity to be useful.

For the rendering, ideally it needs GPU support.

Input needs much more work, here's an overview for Windows: http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_key...

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.

Here's my attempt at making something similar, couple years ago: https://github.com/Const-me/Vrmac

Re: Minimal Cross-Platform Graphics

#5
Very cool!

This example I think needs editing:

    memset(f->buf, rgb, f->width*f->height*sizeoof(uint32_t));
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.

For clearing (all zero) it's usable, and then I would recommend writing it as:

    memset(f->buf, 0, f->width * f->height * sizeof *f->buf);
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.

[1]: https://man7.org/linux/man-pages/man3/memset.3.html

Re: Minimal Cross-Platform Graphics

#6
post #4

I think this needs much more complexity to be useful. For the rendering, ideally it needs GPU support. Input needs much more work, here's an overview for Windows: http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_key... 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 re…

> Windows' Sleep() function has default resolution 15.6ms, that's not enough for realtime rendering, and relatively hard to fix

Very easy to fix. Call this at the start of your real-time process:

https://learn.microsoft.com/en-us/windows/win32/api/timeapi/...

Use an argument of 1, and windows will come knocking at ~1Khz. This is extremely effective in my experience. Allows you to do some pretty crazy stuff on 1 thread.

Re: Minimal Cross-Platform Graphics

#8
post #4

I think this needs much more complexity to be useful. For the rendering, ideally it needs GPU support. Input needs much more work, here's an overview for Windows: http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_key... 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 re…

No direct access to the command buffers of the GPU? No matrix transform routines? No colorspaces besides RGB? Absolute non-starter.

Re: Minimal Cross-Platform Graphics

#10
This is extremely useful, and the page is beautifully written. Some people write absurd electron behemoths, and then there's this jewel of elegance.

Could this be compiled as an αpε? Such a thing would make many heads explode.

Post reply on HN