jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.21k stars 586 forks source link

cross platform GUI / 2D software rendering #35

Open nikhedonia opened 3 years ago

nikhedonia commented 3 years ago

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.

Alexiril commented 3 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 :)

niutech commented 3 months ago

@Alexiril Great work, thanks! I can confirm it works in Windows 11:

cosmo-sdl2

Would you like to support Mac OS too?

Alexiril commented 3 months ago

Thanks for testing!

Would you like to support Mac OS too?

Sure, once I understand how Cosmopolitan and SDL dylib libraries work in macOS.

jart commented 3 months ago

@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

franciscod commented 1 month ago

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:

https://hereket.com/posts/from-scratch-x11-windowing/