# How do you use GLFW with directX

**URL:** <https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415>\
**Category:** support\
**Created:** [September 18, 2019, 11:06am UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415 "2019-09-18T11:06:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pheonixfirewingz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/pheonixfirewingz/32/279_2.png) [@pheonixfirewingz](https://discourse.glfw.org/u/pheonixfirewingz)\
**Post date:** [September 18, 2019, 11:06am UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/1 "2019-09-18T11:06:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [September 18, 2019, 12:12pm UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/2 "2019-09-18T12:12:28Z")

</div>

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](https://www.glfw.org/docs/latest/group__native.html)

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [September 18, 2019, 7:06pm UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/3 "2019-09-18T19:06:17Z")

</div>

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](https://www.glfw.org/docs/latest/window_guide.html#GLFW_CLIENT_API_hint) and then use [glfwGetWin32Window to get the HWND](https://www.glfw.org/docs/latest/group__native.html#gafe5079aa79038b0079fc09d5f0a8e667).Then I believe you should be able to use [IDXGIFactory2::CreateSwapChainForHwnd](https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_2/nf-dxgi1_2-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…

---

<div class="post-metadata">

**Author:** ![pheonixfirewingz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/pheonixfirewingz/32/279_2.png) [@pheonixfirewingz](https://discourse.glfw.org/u/pheonixfirewingz)\
**Post date:** [September 18, 2019, 10:20pm UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/4 "2019-09-18T22:20:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [September 19, 2019, 6:17am UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/5 "2019-09-19T06:17:28Z")

</div>

FYI You might also want to take a look at how [bgfx integrates with GLFW](https://bkaradzic.github.io/bgfx/overview.html#sdl-glfw-etc) to create DX devices as a guide.

---

<div class="post-metadata">

**Author:** ![pvorisek25](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@pvorisek25](https://discourse.glfw.org/u/pvorisek25)\
**Post date:** [September 26, 2019, 5:59am UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/6 "2019-09-26T05:59:44Z")

</div>

Where I need to use GLFW\_NO\_API? In which method?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [September 26, 2019, 7:04am UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/7 "2019-09-26T07:04:27Z")

</div>

You need to use this in the [glfwWindowHint](https://www.glfw.org/docs/latest/group__window.html#ga7d9c8c62384b1e2821c4dc48952d2033) function prior to creating your window.

---

<div class="post-metadata">

**Author:** ![pvorisek25](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@pvorisek25](https://discourse.glfw.org/u/pvorisek25)\
**Post date:** [September 28, 2019, 1:36pm UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/8 "2019-09-28T13:36:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [September 28, 2019, 3:14pm UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/9 "2019-09-28T15:14:23Z")

</div>

See the [context hints](https://www.glfw.org/docs/latest/window_guide.html#window_hints_ctx) 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](https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Base_code) to be useful as that uses GLFW\_NO\_API.

---

<div class="post-metadata">

**Author:** ![pvorisek25](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@pvorisek25](https://discourse.glfw.org/u/pvorisek25)\
**Post date:** [September 29, 2019, 7:49am UTC](https://discourse.glfw.org/t/how-do-you-use-glfw-with-directx/1415/10 "2019-09-29T07:49:46Z")

</div>

Thanks a lot @dougbinks.
