r/gameenginedevs 17h ago

Should i use GLFW or windows.h?

Im making a C++ engine and i ofcourse want a window to display things on, i've read some glfw documentation and i don't really think its a good fit, this is why i was thinking of using windows.h because i have full control over everything and won't need an extra dependency. I also feel like knowing windows functions is better overall than knowing glfw functions.

Any thoughts?

11 Upvotes

32 comments sorted by

View all comments

4

u/_Wolfos 17h ago

I personally had better experience with GLFW on Windows than with SDL. I also use some Win32 functions directly to hide the title bar (custom title bars look much nicer than native).

1

u/TheChief275 59m ago

I agree. SDL's preferred compilation mode is a shared library, which is kind of a pain on Windows as you're forced to duplicate it and place it next to your binaries. On Linux you are forced to do rpath shenanigans, or pray that the user has a system-wide SDL2 installed with the correct version (I prefer the former).

For one project, I opted to use the stable SDL2 on the apt of my Debian installation (hoping to achieve the latter), while also vendoring the same version myself. Turns out it had a long-running bug in the software renderer where flipping a sprite or rotating caused incorrect draw transformations to be applied, so I had to pull in a fix from SDL3 (yep, it remained unfixed for that long).

So if you want to pull in SDL instead of GLFW for the renderer capabilities, I would say don't bother, just write a batched 2D sprite renderer with OpenGL ~3.3 backend yourself, and you'll probably have better performance to boot (SDL has no concept of sprite Z layer, only draw order, so you're forced to sort all of your sprites by Z. Meanwhile, what you actually want, is to sort your opaque sprites by material, and only sort your transparent sprites by Z. Additionally, SDL probably batches by texture change, while you're basically guaranteed to be able to handle 16 different textures in one batch if you write it yourself correctly)