#How to decide on what approach to take regarding window creation from the os?

1 messages · Page 1 of 1 (latest)

brisk herald
#

I'm aware there are existing C libraries that I could use? I also saw there is a zig-gamedev library ?
what should be my thought process when weighing what could be the pros and cons?

How daunting is it really to do it natively from scratch natively? (I believe Ghostty had this approach) - my main concern here is honestly just intimidation from it being too complex and being stuck holding me back from being able to continue learning on top of that foundation.

My goal is to chip away at concepts by building on that foundation of getting a window created, then playing around with how to manipulate the graphics/display within that window etc.

Most of my experience is in higher level web applications so I'm taking this as an opportunity to combine learning zig with more low level programming projects.

(I'm on mac)

worldly plank
#

(which is more than decent enough for dvui to use as a window backend along side openGL(i think))

#

In my experience, opening and running a window in windows isn't too hard, its like 60 LoC (when using zigwin32)

tulip pilot
#

It sounds to me like you need to decide what your goal is. If you are really interested in going down to the OS level and managing things from scratch, that's awesome, and what you should focus on. Start small and just day "I'm going to open a window", and once that's fine "I'm going to draw a square" and build from there.

If your goal is to make an application or game, while staying relatively low level without getting sucked into the OS layer, something like SDL or Raylib is great. SDL for example, you can open a window and draw to it without much code, but it's not an entire framework that abstracts away all the details either.

I was in a similar situation to you, and I decided to start with some simple games, and used SDL3 as my windowing/input/rendering layer. I bounce back and forth between Mac and Linux, so I would have to write two platform layer implementations, and I wanted to get something on screen faster than that. But there's absolutely nothing wrong with going down to the platform first, as long as you sort your goals out.

Also: https://www.youtube.com/watch?v=Ee3EtYb8d1o&pp=ygUVaGFuZG1hZGUgaGVybyBkYXkgMDAx

Don't know if you're familiar with Handmade Hero, but Casey starts with the Windows API in C, and proceeds to build an entire game from there (over many many episodes). In terms of hours spent to what you get out, I don't think there's a better learning resource out there. It's obviously Windows and C instead of Mac and Zig, but broadly all the same principles still apply, and I believe there are people who ported code episode by episode to Mac.

Day 001 of coding on Handmade Hero. See http://handmadehero.org for details.

  1. Review of C on Windows
  2. Command subst. subst w: c:/hmh
  3. WinMain entry point
  4. Navigating windows shell
  5. Setting up minimal build system.
  6. Windows MessageBox
▶ Play video
brisk herald
#

Thank you both @worldly plank and @tulip pilot. I do need to define my goal (and try to not make it realistic) combining the idea of a final product and the learning experience. Sort of following the concept behind that video series.

Right now my thought process is that if I follow along Caseys series, I'll be able to understand the concepts implemented here: https://github.com/ypsvlq/wio/blob/master/src/macos.zig. Depending on how that goes, I might be up for the challenge of doing the implementation natively for the sake of learning and then building on it.

Is that a valid thought process?

tulip pilot
brisk herald
#

yeah, going to watch him develop the concepts of interacting with the operating system's api and then attempt to achieve the functionalities I find myself interested in but on mac on my own. I'm sure that will send me down other rabbit holes 😂 and I might go on side quests since I'm not sure I'm in it for a game as the destination, we'll see when I get there.

tulip pilot
#

Ted Bendixson, the guy who made Mooselutions, did the same thing (I'm pretty sure it was him). He talks about it on the Wookash Podcast.

brisk herald
#

nice! I'll look it up

tulip pilot
#

Also if you haven't watched the podcast, it's incredible. Casey, Sean Barrett, Ryan Fleury, Ginger Bill, and a ton of other great devs have done interviews. There are also code reviews and live coding sessions

brisk herald
#

thanks for sharing, I need more hours in the day lol

tulip pilot
# brisk herald thanks for sharing, I need more hours in the day lol

The only way I get through any of it is to listen on long drives and what not lol

Ted Bendixson apparently posted some of his stuff. Don't know how closely it follows Handmade but might help: https://github.com/TheoBendixson/Handmade-Hero-MacOS-Platform-Layer-Non-Video

GitHub

What if Casey Muratori started Handmade Hero on a Mac? That's what this is. - TheoBendixson/Handmade-Hero-MacOS-Platform-Layer-Non-Video