TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Minimal Cross-Platform Graphics

201 pointsby rrampageover 2 years ago

18 comments

abainbridgeover 2 years ago
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&#x27;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(&quot;dwmapi.dll&quot;), and then GetProcAddress(dwm, &quot;DwmFlush&quot;).
评论 #34503195 未加载
评论 #34501998 未加载
panzerboilerover 2 years ago
Perfect companion for this C graphics library: <a href="https:&#x2F;&#x2F;github.com&#x2F;tsoding&#x2F;olive.c">https:&#x2F;&#x2F;github.com&#x2F;tsoding&#x2F;olive.c</a>
HexDecOctBinover 2 years ago
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.
bananaboyover 2 years ago
Very nice! I like that it&#x27;s a single header. I wrote something similar although it&#x27;s not single header, doesn&#x27;t do audio, and no X11 backend <a href="https:&#x2F;&#x2F;github.com&#x2F;samizzo&#x2F;pixie">https:&#x2F;&#x2F;github.com&#x2F;samizzo&#x2F;pixie</a>. I use mine as a backend for Windows ports of MS-DOS demos that I make.
detritesover 2 years ago
A similar x-platform library called TiGR (Tiny GRaphics):<p><a href="https:&#x2F;&#x2F;github.com&#x2F;erkkah&#x2F;tigr">https:&#x2F;&#x2F;github.com&#x2F;erkkah&#x2F;tigr</a><p>Brief discussion:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=34310208" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=34310208</a>
unwindover 2 years ago
Very cool!<p>This example I think needs editing:<p><pre><code> memset(f-&gt;buf, rgb, f-&gt;width*f-&gt;height*sizeoof(uint32_t)); </code></pre> it&#x27;s described as a way to &quot;fill the complete framebuffer with a solid colour&quot;, but &#x27;rgb&#x27; is shown in the previous snipped to be &#x27;uint32_t&#x27;. That is not how &#x27;memset()&#x27; [1] works, it will only use the least significant 8 bits of the &#x27;int&#x27;-typed value argument. So it would use whatever blue bits where in &#x27;rgb&#x27;, only.<p>For clearing (all zero) it&#x27;s usable, and then I would recommend writing it as:<p><pre><code> memset(f-&gt;buf, 0, f-&gt;width * f-&gt;height * sizeof *f-&gt;buf); </code></pre> this both fixes the typo (&quot;sizeoof&quot; 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&#x27;ve been advocating for ... years.<p>[1]: <a href="https:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man3&#x2F;memset.3.html" rel="nofollow">https:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man3&#x2F;memset.3.html</a>
评论 #34502231 未加载
kragenover 2 years ago
since everyone else is posting links to their similar libraries, i thought i&#x27;d post mine too, <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;kragen&#x2F;bubbleos&#x2F;-&#x2F;tree&#x2F;master&#x2F;yeso" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;kragen&#x2F;bubbleos&#x2F;-&#x2F;tree&#x2F;master&#x2F;yeso</a><p>it&#x27;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&#x27;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&#x27;t ported yeso to win32&#x2F;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&#x27;s ffi), and presumably you could use it from zig or rust in the same way as fenster, but i haven&#x27;t tried
评论 #34509961 未加载
Const-meover 2 years ago
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&#x27;s an overview for Windows: <a href="http:&#x2F;&#x2F;blog.ngedit.com&#x2F;2005&#x2F;06&#x2F;13&#x2F;whats-broken-in-the-wm_keydownwm_char-input-model&#x2F;" rel="nofollow">http:&#x2F;&#x2F;blog.ngedit.com&#x2F;2005&#x2F;06&#x2F;13&#x2F;whats-broken-in-the-wm_key...</a><p>Windows&#x27; Sleep() function has default resolution 15.6ms, that&#x27;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&#x27;s my attempt at making something similar, couple years ago: <a href="https:&#x2F;&#x2F;github.com&#x2F;Const-me&#x2F;Vrmac">https:&#x2F;&#x2F;github.com&#x2F;Const-me&#x2F;Vrmac</a>
评论 #34501893 未加载
评论 #34502487 未加载
评论 #34501912 未加载
ibebrett86over 2 years ago
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:&#x2F;&#x2F;github.com&#x2F;ibebrett&#x2F;zigzag">https:&#x2F;&#x2F;github.com&#x2F;ibebrett&#x2F;zigzag</a>
kefirover 2 years ago
Very similar to minifb:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;emoon&#x2F;minifb">https:&#x2F;&#x2F;github.com&#x2F;emoon&#x2F;minifb</a>, <a href="https:&#x2F;&#x2F;docs.rs&#x2F;minifb&#x2F;latest&#x2F;minifb&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.rs&#x2F;minifb&#x2F;latest&#x2F;minifb&#x2F;</a>, <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24172362" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24172362</a>
brabelover 2 years ago
Wonderful. I really wanted something like this to do Graphic the &quot;hard way&quot;, 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.
评论 #34503661 未加载
imadrover 2 years ago
I did something similar to load an image in windows&#x2F;linux <a href="https:&#x2F;&#x2F;imadr.me&#x2F;cross-platform-window-in-c&#x2F;" rel="nofollow">https:&#x2F;&#x2F;imadr.me&#x2F;cross-platform-window-in-c&#x2F;</a>
DrNosferatuover 2 years ago
&quot;raylib&quot; comes to mind, as it is a graphics library also inspired by the Borland BGI graphics library.<p>- Anyone with experience in it &#x2F; any possible synergies?<p>[<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Raylib" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Raylib</a>]
torstenvlover 2 years ago
Very, very cool. Already played doom on it. Maybe I can get my nephew interested in playing with this!
评论 #34515125 未加载
nuc1e0nover 2 years ago
This is very cool, but if I were doing such things I&#x27;d just use SDL (<a href="https:&#x2F;&#x2F;www.libsdl.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.libsdl.org&#x2F;</a>)
jaceredaover 2 years ago
Not so minimal, but if you need GPU rendering I wrote this: <a href="https:&#x2F;&#x2F;github.com&#x2F;jacereda&#x2F;glcv">https:&#x2F;&#x2F;github.com&#x2F;jacereda&#x2F;glcv</a>
评论 #34503714 未加载
synergy20over 2 years ago
Basically a bare-metal SDL2? well done.
enriqutoover 2 years ago
This is extremely useful, and the page is beautifully written. Some people write absurd electron behemoths, and then there&#x27;s this jewel of elegance.<p>Could this be compiled as an αpε? Such a thing would make many heads explode.
评论 #34503391 未加载
评论 #34504114 未加载
评论 #34505124 未加载