Register
handmade.network»Forums»Programming C on Mac os X
41 posts
Programming C on Mac os X
1 month, 2 weeks ago Edited by BernFeth on March 5, 2021, 1:52 p.m. Reason: Initial post
Hey guys,

My pc fried and I have no longer windows.

Is it possible to open a window, get events, render something be it software or hardware, but not using sdl or xcode, etc.

Can I program pure C and use their api like we do on windows? What about a debugger (not xcode)

Thanks!
107 posts / 1 project
Programming C on Mac os X
1 month, 2 weeks ago Edited by Dawoodoz on March 5, 2021, 5:02 p.m.
SDL is written in C, so using the system calls directly should work in theory. Newer versions of their operating system are however said to remove both X11 and OpenGL support. This forces you to either use their own APIs or install compatibility layers on top of the native calls which would be just as bad as having to rely on SDL as a dependency. Just the intent of dropping OpenGL without adopting Vulkan (proving that the legacy excuse was bullshit) makes the platform into another potential vendor lock-in after Windows. I had to abandon my Direct 3D engine when Windows went bad, so I'm not doing that mistake again.
https://venturebeat.com/2018/06/0...ame-developers-threaten-to-leave/
https://www.cnet.com/news/apple-t...upport-and-more-in-mountain-lion/

I would install Linux Manjaro instead, which pretty much beats Windows 10 in every aspect (speed, security, privacy, ease of use, driver support for older peripherals, GPU installation with automatic hardware detection, no start menu ads, no forced updates, no pre-installed spyware, not using your computer as a cloud server, not hogging 100% of the CPU for no reason). All your old Windows games won't work on Linux of course (around 30% supported on Steam), but then you just buy new AAA games with native support for Linux on sales and move on.
Miles
111 posts / 4 projects
Programming C on Mac os X
1 month, 2 weeks ago
SDL relies on Objective-C APIs on macos. It's not written entirely in C. Theoretically there may be hacky ways to call into those APIs from plain C code, but the realistic answer is "no, you probably can't write a macos platform layer in pure C". I don't know of any decent debuggers other than xcode, though that doesn't mean they don't exist. Obviously there are command line debuggers, but I assume that's not what you want.
Mārtiņš Možeiko
2205 posts / 1 project
Programming C on Mac os X
1 month, 2 weeks ago Edited by Mārtiņš Možeiko on March 5, 2021, 8:09 p.m.
There is some of functionality in macOS that is accessible just by C code, but for most of stuff involving window will be ObjectiveC code. It's not a lot of amount of code, you can easily wrap it in C interface, just like SDL or glfw does.

Technically all ObjectiveC code is compiled down to C function calls. So you can easily replace any ObjectiveC code with C code - it's completely doable. Here's example for iOS applicaiton in C: https://stackoverflow.com/questio.../how-to-write-ios-app-purely-in-c

It basically requires changing [obj method] calls to objc_msgSend(obj, methodSelector).
You will need good understanding ObjectiveC to do this correctly though.

For debugger without xcode your only choice is lldb in commandline. It can do everything that xcode can (as xcode does use lldb internally), but it will require learning bunch of lldb commands. Otherwise if you want GUI for debugger, Xcode will be your only choice.
41 posts
Programming C on Mac os X
1 month, 2 weeks ago
I see,

thanks all for answering.

I decided I will surrender myself to using SDL for now and come back to this later, maybe together with casey when he ports handmade hero.
22 posts
Programming C on Mac os X
1 month, 2 weeks ago

Do you have backup discs for the Apple machine? Maybe research if it will accept Linux or BSD? HMH has a Linux version on Github that uses SDL.
Steve
20 posts

Code Monkey

Programming C on Mac os X
1 month, 2 weeks ago Edited by Steve on March 6, 2021, 5:28 a.m.
If you only want to learn and follow the handmade hero coding project, but your computer is now a Mac then checkout:

Ted's Video series on Handmade macOS Platform Layer:
https://www.youtube.com/user/shredbots/videos

or this untested port:
https://github.com/itfrombit/osx_handmade

Otherwise, continue on your current path using SDL.

---

You can also consider GFLW or SFML for a lower-level or simpler library (with fewer features).

GFLW: https://www.glfw.org
SFML: https://www.sfml-dev.org

Lastly, if you want to actually make macOS apps with some native UI interface, but code all logic in C then you can just learn enough ObjC and AppKit to get a window up and running, and then call directly into your C code because ObjC is literally a superset of C.

[EDIT: ah crap, sorry, apparently SFML is C++ ... well, if you don't mind your library being c++ you could still write C for your code]


I see 0xdeadc0de everywhere
41 posts
Programming C on Mac os X
1 month, 2 weeks ago
I'll be using my dads imac for a while so I can't really install another os on it.


Ted's Video series on Handmade macOS Platform Layer:
https://www.youtube.com/user/shredbots/videos


Cool! I didn't know about that,

I will be following that series, thanks a lot!
Miles
111 posts / 4 projects
Programming C on Mac os X
1 month, 2 weeks ago
mmozeiko
For debugger without xcode your only choice is lldb in commandline. Otherwise if you want GUI for debugger, Xcode will be your only choice.


That's a strange claim to make with so much confidence. There are at least a few GUI debuggers for macos that I could find just by searching around, I just can't vouch for them because I haven't personally tried any of them. And for command line debuggers, GDB is available on macos as well, so LLDB definitely isn't your only choice.

stevetranby
You can also consider GFLW or SFML for a lower-level or simpler library (with fewer features).


SFML is a higher-level library than SDL, and I wouldn't personally recommend it because it's written in a very obnoxious object-oriented C++ style.