Closed nikhedonia closed 4 months ago
Hello everyone!
I've found this treasure some days ago and was interested if that's possible to use SDL with the Cosmopolitan apps. (I didn't want to use OpenGL for reasons) Of course, rewriting the SDL for cosmopolitan is not possible right now, but @jart said it's okay to link SDL dynamic library, load functions out of there and use them.
I didn't find an example of doing so with SDL (only for zlib), so I decided to make one, just for fun and studying (and to bring some life to this issue :)
Sure, the size is not as good as @jacereda's cosmogfx demo (that is awesome by the way) - 7mb for simple application, but there is 4mb for libs and resources inside the file.
So, there's code: cosmo-sdl2 example
It was done in like 2 days, so don't blame me for troubles with licenses and my real terrible fast written code :)
@Alexiril Great work, thanks! I can confirm it works in Windows 11:
Would you like to support Mac OS too?
Thanks for testing!
Would you like to support Mac OS too?
Sure, once I understand how Cosmopolitan and SDL dylib libraries work in macOS.
@Alexiril Could you add a link to your project to the wiki? https://github.com/jart/cosmopolitan/wiki You could also send a pull request (see CONTRIBUTING.md) creating a contrib/
directory in the root of the mono repo, and adding your code there (don't include the DLLs, ideally write a shell script or something to download those).
Headers like these:
#include <libc/isystem/iostream>
#include <libc/isystem/memory>
#include <libc/isystem/string>
Can be this, with cosmocc:
#include <iostream>
#include <memory>
#include <string>
That applies to the mono repo now too.
Great work on the license/
directory. You're clearly a professional.
You may also want to join our Discord in the #gui channel. https://discord.gg/n66pHA3A
Cosmopolitan can already create a blank canvas on WIN32. If we can do the same thing for X11 then that will cover all our bases. [...] It appears the way it works is you need to open a UNIX domain socket to /tmp/.X11-unix/X0 and then you just send a bunch of binary frames back and forth. [...] So yeah I would be pretty happy if we could talk to X11 directly without needing to touch Linux distro shared objects. X11 is a really old protocol that's been around since the 80's so I can't imagine its wire format will be changing anytime soon.
related read about creating X11 windows without using Xlib or anything, just the X11 docs and socket syscalls:
Hi, @jart. I don't know if you are aware of a less-known, but well-designed, cross-platform native GUI framework written in pure C called NAppGUI: https://github.com/frang75/nappgui_src
I think it could work well with cosmopolitan. They share a very similar spirit, I think.
It's not written in pure C if it depends on GUI libraries. NAppGUI won't work. What will work is SDL. That's what I recommend using with Cosmopolitan for GUIs. (Although creating a command line web server with a browser GUI is a better idea.) See the following project for a demo https://github.com/hclarke/triangle-sine Here's an even better demo of how to do it with cosmo: https://github.com/z-erica/cosmopolitan-sdl2
Well, it wraps the common subset of Win32/GDI, GTK and Cocoa controls into a very thin cross-platform layer that papers over their idiosyncrasies. It does not have any dependencies apart from the OS-provided libraries. Just like SDL2. It is its own thing.
I don't think web stuff, Nuklear or ImGui are comparable to native controls, both from an accessibility and integration standpoint. They definitely aren't native in the way cosmopolitan aims.
Here's 2k LOC in C that works on X11, cocoa, and WinAPI. It's built on fenster and microui and the line count includes both those libraries. I make no claims that it's fast
@tekknolagi That's great! But does it compile with Cosmpolitan libc? Could you provide an APE binary for testing?
I've noticed that cosmopolitan supports the creation of gui applications on windows. I'm curious on your thoughts on how you'd go about extending this to the remaining platforms. I'd be happy to make contributions in this direction but I'm not too familliar on how things work on Mac & BSD.