-
Notifications
You must be signed in to change notification settings - Fork 567
D3D 9
OneshotGH edited this page Apr 9, 2018
·
2 revisions
How to use Nuklear with DirectX9. Here i show you the basics of setting it up and handling the DeviceLost state.
Setting up Nuklear for DirectX rendering.
/* Initiating the GUI */
ctx = nk_d3d9_init(d3ddev, s_width, s_height);
struct nk_font_atlas *atlas;
{struct nk_font_atlas *atlas;
nk_d3d9_font_stash_begin(&atlas);
nk_d3d9_font_stash_end();
}
Handle input events.
MSG msg;
nk_input_begin(ctx);
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT)
running = 0;
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
nk_input_end(ctx);
In WindowProc
if (nk_d3d9_handle_event(hwnd, message, wParam, lParam))
return 0;
While DeviceLost
if (ctx)
{
nk_free(ctx);
ctx = NULL;
}
nk_d3d9_release();
hr = d3ddev->Reset(&d3dpp);
if (SUCCEEDED(hr)) {
ctx = nk_d3d9_init(d3ddev, s_width, s_height);
struct nk_font_atlas *atlas;
nk_d3d9_font_stash_begin(&atlas);
nk_d3d9_font_stash_end();
}
Render
nk_begin(ctx, "TestWindow", nk_rect(50, 50, 400, 250),NK_WINDOW_MOVABLE |NK_WINDOW_TITLE);
nk_end(ctx);
nk_d3d9_render(NK_ANTI_ALIASING_ON);
Code from https://github.com/vurtun/nuklear/blob/master/demo/d3d9/main.c There you can see how to set it up and how to render but its not covered how to recreate resources while the device has been lost.