How do you use GLFW with directX

dose anyone knows how to bind GLFW to DirectX I know this is more focused on OpenGL and Vulkan.
I’m trying to use GLFW as My game Engines desktop window for windows, Linux, and mac and don’t want to have to add extra code for win32

You should be able to use the native access interface to get the hWND and then use this to initialize your DX swapchain.

https://www.glfw.org/docs/latest/group__native.html

Adding some more specifics:

For DX you’ll need to create a GLFW window without a client API using the window hint GLFW_NO_API and then use glfwGetWin32Window to get the HWND.Then I believe you should be able to use IDXGIFactory2::CreateSwapChainForHwnd to create a swap chain. This is likely going to involve some fiddling to get right with window resizing, fullscreen etc.

Also note that I’ve not tried this…

1 Like

i’ll test it and let you know thanks for the help

FYI You might also want to take a look at how bgfx integrates with GLFW to create DX devices as a guide.

Where I need to use GLFW_NO_API? In which method?

You need to use this in the glfwWindowHint function prior to creating your window.

Thank you @dougbinks. I’ll try that later. I looked to the documentation of the GLFW library and I’ve found that the glfwWindowHint method needs two parameters. One is GLFW_NO_API and the second one is something called value. What value I should set? Nullptr?

See the context hints section of the window hints documentation.You use GLFW_CLIENT_API as the hint and GLFW_NO_API as the value.

So your window hint call would be:

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

You might find this tutorial on Vulkan with GLFW to be useful as that uses GLFW_NO_API.

Thanks a lot @dougbinks.