Home > Software design >  There is in Directx something similar to glfwSetWindowUserPointer?
There is in Directx something similar to glfwSetWindowUserPointer?

Time:09-19

So, I was using OpenGL with GLFW until now. Now I want to include DirectX in my project and I'm wondering, there is in directx, HWND something similar to glfwSetWindowUserPointer?

I have this struct:

    struct WindowData
    {
        std::string Title;
        int X, Y;
        int Width, Height;
        bool VSync;
        bool Fullscreen;
    };

And I want to send an instance of this struct as a WindowUserPointer

CodePudding user response:

There are some tutorials on the Internet that appear to cover how to integrate DirectX with GLFW windowing and the like. For details on creating a Direct3D 11 device, see this blog post.

That said, if you want to author a 'native' DirectX application, a Win32 rendering loop and Direct3D device setup is quite simple. For examples of doing this for DirectX 11 and DirectX12 for both classic Win32 and the Universal Windows Platform (UWP), see the directx-vs-templates GitHub project.

HWND hwnd = CreateWindowExW(0, L"MyAppWindowClass", g_szAppName, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, nullptr, nullptr, hInstance,
    nullptr);
if (!hwnd)
    return 1;

ShowWindow(hwnd, nCmdShow);

SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(g_game.get()));
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    auto game = reinterpret_cast<Game*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
...

For utility code including GamePad/Keyboard/Mouse input handling, audio, and DirectX support, see DirectX Tool Kit for DX11 / DX12.

  • Related