8 ms·
RGFW: Single-header C99 window abstraction library
- colleagueRiley 2y agoThanks :)
- CyberDildonics 2y agoI love single header libraries and I like the idea here of taking care of one necessity well. It seems like good modularity all around. A quick heads up, the micro UI emscripten example doesn't work on chrome or firefox. The error is: DrawElements doesn't actually prepareClientAttributes properly.
- colleagueRiley 2y agoI'm aware of the errors for the micro UI (on the web), it's something I plan on looking into soon!
- ranger_danger 2y agoThe one big downside I see is that if you want to actually work on the library itself, it's a pain to have to re-compile the entire thing every time you change something. Nuklear (https://github.com/Immediate-Mode-UI/Nuklear https://github.com/Immediate-Mode-UI/Nuklear) uses separate files with a deploy script that combines them all into a single header; I think that approach is quicker for iterating on the code.
- colleagueRiley 2y agoSure, but the library is also relatively small, so it compiles quickly. Although if you want to you can compile it on its own. It's also possible to compile it on its own using `gcc -c -x c -D RGFW_IMPLEMENTATION RGFW.h` Nuklear is not a true single-header style library, it only uses that as a format. The difference is that the design is far less compact and lightweight than a stb-style library. I'm pretty sure GLFW has some files that are nearly the same size as RGFW, for example.
- ranger_danger 2y agoWhy do you claim Nuklear is not a "true single-header style library"? And who gets to say what that even means?
- colleagueRiley 2y agoIt is a single-header library in terms of the format, yes. But it is also not designed to be a single-header library, unlike an STB-style library. Nuklear is a full-sized library that can be compiled into and used as one file. However, RGFW and STB are designed to be lightweight and minimalistic. That's the distinctive part of single-header libraries, also known as STB-style libraries. To be clear, I don't mean this to hate on Nuklear, it's a cool UI library, but its design doesn't match the single-header format.
- ranger_danger 2y agoHow is it not designed to be a single-header library? The README even directly states "Single-header library". How is it not designed to be lightweight and minimalistic? How do you think the design differs from your idea (which is what exactly?) of a "single-header format"?
- colleagueRiley 2y agohttps://github.com/SasLuca/glfw-single-header/blob/master/example/glfw.h https://github.com/SasLuca/glfw-single-header/blob/master/ex...
- ranger_danger 2y agoWhat is this supposed to be telling me? This also looks like it was multiple files concatenated together because there are multiple different header guards throughout the file.
- CyberDildonics 2y agoHave you actually tried? This is 287 KB of C. MSVC on computers from 15 years ago will compile C at about 60 MB/s. I'm skeptical this is actually a problem. SQLite is distributed as a single 6 MB .c file and compiles in ... 0.1 seconds.
- jstimpfle 2y agoThat may be true for extremely simple source code, but it's almost too good to be true. Your number sounded so impressive that I tried with gcc (12.2) on my Linux VM. With -O0, it takes around 27s, with -O2 it's 1m07s. With -E (only preprocess) we are at around 0.320s for the 260K lines of sqlite3.c. Which makes sense, 1M lines/s for the preprocessor and maybe also the AST should be doable (that may be where you got your 60MB/s number from). But compiling is something else. MSVC may be faster here or not, I haven't tested it. A more modern machine (mine is a i5-7600K from 2018) may be 2x or more faster, and running on multiple threads will speed up the build as well.
- mandarax8 2y agoWhat exactly did you try to compile and how? $ time gcc -x c -c RGFW.h -D RGFW_IMPLEMENTATION -fPIC -D RGFW_EXPORT 0.42s user 0.03s system 93% cpu 0.485 total
- jstimpfle 2y agosqlite3, if you read carefully again.
- CyberDildonics 2y ago(that may be where you got your 60MB/s number from) It's not that. I think I messed up and the 0.1 seconds was tcc and msvc was 1 or 2 seconds. Nothing was 27 seconds. Try tcc, even though you are in a VM it should be very fast as a baseline for what's possible. The point is that some people talk about single header files being slow are really saying "what if". C is incredibly fast to compile and the slow parts are the overhead from each compilation unit and the optimizers. 287 KB of source code added to a compilation unit is nothing in the modern era. Not only that, but you can just choose to put a lot of them in the same compilation unit and not touch it again. Every time I've used single file header libraries it makes things simple and fast. I'm not going to change them so dumping them all into a single compilation unit is fine.
- felipefar 2y agoYou could support mobile platforms as well. IIRC, even if Android allows creating only one window per activity, this behavior can be easily mapped on the abstraction that you provide.
- colleagueRiley 2y agoThat's something I plan on looking into at some point. I'm unsure if I want that in the main version or a separate branch for embedded devices. It's low priority though because my main focus is desktop applications.
- slmjkdbtl 2y agosokol_app.h has mobile support
- dmitrygr 2y ago> Wayland support is very experimental and broken You and everyone else, RGFW, you and everyone else.
- colleagueRiley 2y agoX11 needs a real alternative :(
- themerone 2y agoWhat do you expect from an alternative?
- colleagueRiley 2y ago- Better API design - Not being experimental after 11 years I think that Wayland actually has some steps in the right direction, but overall I don't think it's actually a very good alternative. It's way more low-level than X11 and a lot of higher level features, like window decorations, are not even officially supported.
- akira2501 2y agoX11 is fine. It's mostly just Video Games that need an alternative. It'd be nice if there was a "pause X11 video card control and give exclusive access to a single application." Then there's no need to care.
- garbagepatch 2y agoThis was added to raylib as a backend recently: https://github.com/raysan5/raylib/releases#:~:text=RGFW https://github.com/raysan5/raylib/releases#:~:text=RGFW
- lkuty 2y agoTsoding (@TsodingDaily) made a YT video named "This Release is Crazy!!" about the release recently: https://www.youtube.com/watch?v=7ZJ9pJJnxfI https://www.youtube.com/watch?v=7ZJ9pJJnxfI
- eqvinox 2y agoEvery time I see a "single-header C library", I wonder to myself where we'd be if only Windows had a proper package manager. (Especially since that'd force the POSIX world to de-fracture itself too.)
- perching_aix 2y ago> a proper package manager Those are a thing? Wasn't aware.
- raymond_goo 2y agoIsn't the one from Rust pretty good?
- perching_aix 2y agoHaven't worked with it much yet, not really my point either. They were talking about OS package managers, most likely the typical Linux package managers, and so did I.
- linkdd 2y agoscoop? chocolatey? pacman in msys2? winget?
- eqvinox 2y agoRemind me please, which of these is shipped with a default Windows install?
- wis 2y agoI realize you asked sarcastically, but as of relatively recently WinGet is shipped by default with the latest versions of Windows 10 and in Windows 11. [1] But why is being installed by default important? [1] https://www.petergirnus.com/blog/how-to-use-windows-package-manager-winget#:~:text=Is%20winget%20included%20in%20Microsoft%20Windows%2010%20%26%20Windows%2011%3F https://www.petergirnus.com/blog/how-to-use-windows-package-...
- eska 2y agoNot sure whether this is tested on Windows at all. I opened the header and immediately found this `typedef signed long i64`, i.e. i64 is actually i32.
- Conscat 2y agoI'm not sure that issue would be caught by ordinary testing. It will implicitly cast into long long, so it might make little or no difference in this case.
- eska 2y agoA lot of people use i64 in the global namespace, so this will affect later code. It's basically `#define true false`. When I consider a library I will do a quick sniff test to look for very obvious mistakes, at which point I won't look further.
- colleagueRiley 2y ago:( That's disappointing, but I understand.
- colleagueRiley 2y agoI test Windows mainly with MINGW, that might be an issue with MSVC. Feel free to report the issue on the github repository. I'm pretty sure windows uses "long" for 64 bit but linux uses "long long" for 64 bit
- tredre3 2y ago> I'm pretty sure windows uses "long" for 64 bit but linux uses "long long" for 64 bit Windows long is 32bit even on 64bit CPUs. Linux long is arch dependent and is 64bit on x64, 32bit on x86. long long is always 64bit on both platforms.
- colleagueRiley 2y ago
- uecker 2y agoI like simple code written in C, but when does this "single-header" nonsense stop? C has super nice and simple modularization via the classical .h/.c split which ensures fast compilation, proper encapsulation, no instruction bloat via creating multiple instances for all functions.
- colleagueRiley 2y agoTry putting GLFW's source code into one file and then compile it. That will take at least a few seconds, RGFW compiles in less than a second. Where's the bloat? :) https://github.com/SasLuca/glfw-single-header/blob/master/example/glfw.h https://github.com/SasLuca/glfw-single-header/blob/master/ex...
- uecker 2y agoThe issue if if you have many such libraries and any change to the implementation forces recompilation of everything. Maybe not such a big deal for such small libraries, but an annoying trend IMHO.
- tredre3 2y ago> no instruction bloat via creating multiple instances for all functions. This makes me think that you're using single-header libraries wrong. These kind of libraries usually require you to do something special prior to including it to get the actual code and you must do it only in ONE file. For example, you'd #define RGFW_IMPLEMENTATION before #include rgfw.h in exactly ONE .c. If you need the header in other files, you do NOT define RGFW_IMPLEMENTATION and no code will be produced.
- uecker 2y agoWell, I do not use them at all. But I agree that this mechanism would avoid the additional copies. I have seen other single-header libraries though... In any case, forcing me to figure out the specific XYZ_IMPLEMENTATION for each library is less user friendly that just proving a .c and .h file.