imgui_impl_dx11.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. // ImGui Win32 + DirectX11 binding
  2. // https://github.com/ocornut/imgui
  3. #include <imgui.h>
  4. #include "imgui_impl_dx11.h"
  5. // DirectX
  6. #include <d3d11.h>
  7. #include <d3dcompiler.h>
  8. #define DIRECTINPUT_VERSION 0x0800
  9. #include <dinput.h>
  10. // Data
  11. static INT64 g_Time = 0;
  12. static INT64 g_TicksPerSecond = 0;
  13. static HWND g_hWnd = 0;
  14. static ID3D11Device* g_pd3dDevice = NULL;
  15. static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
  16. static ID3D11Buffer* g_pVB = NULL;
  17. static ID3D10Blob * g_pVertexShaderBlob = NULL;
  18. static ID3D11VertexShader* g_pVertexShader = NULL;
  19. static ID3D11InputLayout* g_pInputLayout = NULL;
  20. static ID3D11Buffer* g_pVertexConstantBuffer = NULL;
  21. static ID3D10Blob * g_pPixelShaderBlob = NULL;
  22. static ID3D11PixelShader* g_pPixelShader = NULL;
  23. static ID3D11SamplerState* g_pFontSampler = NULL;
  24. static ID3D11ShaderResourceView*g_pFontTextureView = NULL;
  25. static ID3D11BlendState* g_blendState = NULL;
  26. static int VERTEX_BUFFER_SIZE = 30000; // TODO: Make vertex buffer smaller and grow dynamically as needed.
  27. struct CUSTOMVERTEX
  28. {
  29. float pos[2];
  30. float uv[2];
  31. unsigned int col;
  32. };
  33. struct VERTEX_CONSTANT_BUFFER
  34. {
  35. float mvp[4][4];
  36. };
  37. // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
  38. // If text or lines are blurry when integrating ImGui in your engine:
  39. // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
  40. static void ImGui_ImplDX11_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
  41. {
  42. // Copy and convert all vertices into a single contiguous buffer
  43. D3D11_MAPPED_SUBRESOURCE mappedResource;
  44. if (g_pd3dDeviceContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK)
  45. return;
  46. CUSTOMVERTEX* vtx_dst = (CUSTOMVERTEX*)mappedResource.pData;
  47. for (int n = 0; n < cmd_lists_count; n++)
  48. {
  49. const ImDrawList* cmd_list = cmd_lists[n];
  50. const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0];
  51. for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++)
  52. {
  53. vtx_dst->pos[0] = vtx_src->pos.x;
  54. vtx_dst->pos[1] = vtx_src->pos.y;
  55. vtx_dst->uv[0] = vtx_src->uv.x;
  56. vtx_dst->uv[1] = vtx_src->uv.y;
  57. vtx_dst->col = vtx_src->col;
  58. vtx_dst++;
  59. vtx_src++;
  60. }
  61. }
  62. g_pd3dDeviceContext->Unmap(g_pVB, 0);
  63. // Setup orthographic projection matrix into our constant buffer
  64. {
  65. D3D11_MAPPED_SUBRESOURCE mappedResource;
  66. if (g_pd3dDeviceContext->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK)
  67. return;
  68. VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource.pData;
  69. const float L = 0.0f;
  70. const float R = ImGui::GetIO().DisplaySize.x;
  71. const float B = ImGui::GetIO().DisplaySize.y;
  72. const float T = 0.0f;
  73. const float mvp[4][4] =
  74. {
  75. { 2.0f/(R-L), 0.0f, 0.0f, 0.0f},
  76. { 0.0f, 2.0f/(T-B), 0.0f, 0.0f,},
  77. { 0.0f, 0.0f, 0.5f, 0.0f },
  78. { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
  79. };
  80. memcpy(&pConstantBuffer->mvp, mvp, sizeof(mvp));
  81. g_pd3dDeviceContext->Unmap(g_pVertexConstantBuffer, 0);
  82. }
  83. // Setup viewport
  84. {
  85. D3D11_VIEWPORT vp;
  86. memset(&vp, 0, sizeof(D3D11_VIEWPORT));
  87. vp.Width = ImGui::GetIO().DisplaySize.x;
  88. vp.Height = ImGui::GetIO().DisplaySize.y;
  89. vp.MinDepth = 0.0f;
  90. vp.MaxDepth = 1.0f;
  91. vp.TopLeftX = 0;
  92. vp.TopLeftY = 0;
  93. g_pd3dDeviceContext->RSSetViewports(1, &vp);
  94. }
  95. // Bind shader and vertex buffers
  96. unsigned int stride = sizeof(CUSTOMVERTEX);
  97. unsigned int offset = 0;
  98. g_pd3dDeviceContext->IASetInputLayout(g_pInputLayout);
  99. g_pd3dDeviceContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
  100. g_pd3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  101. g_pd3dDeviceContext->VSSetShader(g_pVertexShader, NULL, 0);
  102. g_pd3dDeviceContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
  103. g_pd3dDeviceContext->PSSetShader(g_pPixelShader, NULL, 0);
  104. g_pd3dDeviceContext->PSSetSamplers(0, 1, &g_pFontSampler);
  105. // Setup render state
  106. const float blendFactor[4] = { 0.f, 0.f, 0.f, 0.f };
  107. g_pd3dDeviceContext->OMSetBlendState(g_blendState, blendFactor, 0xffffffff);
  108. // Render command lists
  109. int vtx_offset = 0;
  110. for (int n = 0; n < cmd_lists_count; n++)
  111. {
  112. const ImDrawList* cmd_list = cmd_lists[n];
  113. for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
  114. {
  115. const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
  116. if (pcmd->user_callback)
  117. {
  118. pcmd->user_callback(cmd_list, pcmd);
  119. }
  120. else
  121. {
  122. const D3D11_RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w };
  123. g_pd3dDeviceContext->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&pcmd->texture_id);
  124. g_pd3dDeviceContext->RSSetScissorRects(1, &r);
  125. g_pd3dDeviceContext->Draw(pcmd->vtx_count, vtx_offset);
  126. }
  127. vtx_offset += pcmd->vtx_count;
  128. }
  129. }
  130. // Restore modified state
  131. g_pd3dDeviceContext->IASetInputLayout(NULL);
  132. g_pd3dDeviceContext->PSSetShader(NULL, NULL, 0);
  133. g_pd3dDeviceContext->VSSetShader(NULL, NULL, 0);
  134. }
  135. LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam)
  136. {
  137. ImGuiIO& io = ImGui::GetIO();
  138. switch (msg)
  139. {
  140. case WM_LBUTTONDOWN:
  141. io.MouseDown[0] = true;
  142. return true;
  143. case WM_LBUTTONUP:
  144. io.MouseDown[0] = false;
  145. return true;
  146. case WM_RBUTTONDOWN:
  147. io.MouseDown[1] = true;
  148. return true;
  149. case WM_RBUTTONUP:
  150. io.MouseDown[1] = false;
  151. return true;
  152. case WM_MOUSEWHEEL:
  153. io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
  154. return true;
  155. case WM_MOUSEMOVE:
  156. io.MousePos.x = (signed short)(lParam);
  157. io.MousePos.y = (signed short)(lParam >> 16);
  158. return true;
  159. case WM_KEYDOWN:
  160. if (wParam < 256)
  161. io.KeysDown[wParam] = 1;
  162. return true;
  163. case WM_KEYUP:
  164. if (wParam < 256)
  165. io.KeysDown[wParam] = 0;
  166. return true;
  167. case WM_CHAR:
  168. // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
  169. if (wParam > 0 && wParam < 0x10000)
  170. io.AddInputCharacter((unsigned short)wParam);
  171. return true;
  172. }
  173. return 0;
  174. }
  175. static void ImGui_ImplDX11_CreateFontsTexture()
  176. {
  177. ImGuiIO& io = ImGui::GetIO();
  178. // Build
  179. unsigned char* pixels;
  180. int width, height;
  181. io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
  182. // Create DX11 texture
  183. {
  184. D3D11_TEXTURE2D_DESC texDesc;
  185. ZeroMemory(&texDesc, sizeof(texDesc));
  186. texDesc.Width = width;
  187. texDesc.Height = height;
  188. texDesc.MipLevels = 1;
  189. texDesc.ArraySize = 1;
  190. texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  191. texDesc.SampleDesc.Count = 1;
  192. texDesc.Usage = D3D11_USAGE_DEFAULT;
  193. texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
  194. texDesc.CPUAccessFlags = 0;
  195. ID3D11Texture2D *pTexture = NULL;
  196. D3D11_SUBRESOURCE_DATA subResource;
  197. subResource.pSysMem = pixels;
  198. subResource.SysMemPitch = texDesc.Width * 4;
  199. subResource.SysMemSlicePitch = 0;
  200. g_pd3dDevice->CreateTexture2D(&texDesc, &subResource, &pTexture);
  201. // Create texture view
  202. D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
  203. ZeroMemory(&srvDesc, sizeof(srvDesc));
  204. srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  205. srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
  206. srvDesc.Texture2D.MipLevels = texDesc.MipLevels;
  207. srvDesc.Texture2D.MostDetailedMip = 0;
  208. g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &g_pFontTextureView);
  209. pTexture->Release();
  210. }
  211. // Store our identifier
  212. io.Fonts->TexID = (void *)g_pFontTextureView;
  213. // Create texture sampler
  214. {
  215. D3D11_SAMPLER_DESC samplerDesc;
  216. ZeroMemory(&samplerDesc, sizeof(samplerDesc));
  217. samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
  218. samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
  219. samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
  220. samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
  221. samplerDesc.MipLODBias = 0.f;
  222. samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
  223. samplerDesc.MinLOD = 0.f;
  224. samplerDesc.MaxLOD = 0.f;
  225. g_pd3dDevice->CreateSamplerState(&samplerDesc, &g_pFontSampler);
  226. }
  227. }
  228. bool ImGui_ImplDX11_CreateDeviceObjects()
  229. {
  230. if (!g_pd3dDevice)
  231. return false;
  232. if (g_pVB)
  233. ImGui_ImplDX11_InvalidateDeviceObjects();
  234. // Create the vertex shader
  235. {
  236. static const char* vertexShader =
  237. "cbuffer vertexBuffer : register(c0) \
  238. {\
  239. float4x4 ProjectionMatrix; \
  240. };\
  241. struct VS_INPUT\
  242. {\
  243. float2 pos : POSITION;\
  244. float4 col : COLOR0;\
  245. float2 uv : TEXCOORD0;\
  246. };\
  247. \
  248. struct PS_INPUT\
  249. {\
  250. float4 pos : SV_POSITION;\
  251. float4 col : COLOR0;\
  252. float2 uv : TEXCOORD0;\
  253. };\
  254. \
  255. PS_INPUT main(VS_INPUT input)\
  256. {\
  257. PS_INPUT output;\
  258. output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
  259. output.col = input.col;\
  260. output.uv = input.uv;\
  261. return output;\
  262. }";
  263. D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, NULL);
  264. if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
  265. return false;
  266. if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK)
  267. return false;
  268. // Create the input layout
  269. D3D11_INPUT_ELEMENT_DESC localLayout[] = {
  270. { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 },
  271. { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((CUSTOMVERTEX*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
  272. { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
  273. };
  274. if (g_pd3dDevice->CreateInputLayout(localLayout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK)
  275. return false;
  276. // Create the constant buffer
  277. {
  278. D3D11_BUFFER_DESC cbDesc;
  279. cbDesc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER);
  280. cbDesc.Usage = D3D11_USAGE_DYNAMIC;
  281. cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
  282. cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
  283. cbDesc.MiscFlags = 0;
  284. g_pd3dDevice->CreateBuffer(&cbDesc, NULL, &g_pVertexConstantBuffer);
  285. }
  286. }
  287. // Create the pixel shader
  288. {
  289. static const char* pixelShader =
  290. "struct PS_INPUT\
  291. {\
  292. float4 pos : SV_POSITION;\
  293. float4 col : COLOR0;\
  294. float2 uv : TEXCOORD0;\
  295. };\
  296. sampler sampler0;\
  297. Texture2D texture0;\
  298. \
  299. float4 main(PS_INPUT input) : SV_Target\
  300. {\
  301. float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \
  302. return out_col; \
  303. }";
  304. D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, NULL);
  305. if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
  306. return false;
  307. if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK)
  308. return false;
  309. }
  310. // Create the blending setup
  311. {
  312. D3D11_BLEND_DESC desc;
  313. ZeroMemory(&desc, sizeof(desc));
  314. desc.AlphaToCoverageEnable = false;
  315. desc.RenderTarget[0].BlendEnable = true;
  316. desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
  317. desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
  318. desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
  319. desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
  320. desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
  321. desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
  322. desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
  323. g_pd3dDevice->CreateBlendState(&desc, &g_blendState);
  324. }
  325. // Create the vertex buffer
  326. {
  327. D3D11_BUFFER_DESC bufferDesc;
  328. memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
  329. bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
  330. bufferDesc.ByteWidth = VERTEX_BUFFER_SIZE * sizeof(CUSTOMVERTEX);
  331. bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  332. bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
  333. bufferDesc.MiscFlags = 0;
  334. if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pVB) < 0)
  335. return false;
  336. }
  337. ImGui_ImplDX11_CreateFontsTexture();
  338. return true;
  339. }
  340. void ImGui_ImplDX11_InvalidateDeviceObjects()
  341. {
  342. if (!g_pd3dDevice)
  343. return;
  344. if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
  345. if (g_pFontTextureView) { g_pFontTextureView->Release(); ImGui::GetIO().Fonts->TexID = 0; }
  346. if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
  347. if (g_blendState) { g_blendState->Release(); g_blendState = NULL; }
  348. if (g_pPixelShader) { g_pPixelShader->Release(); g_pPixelShader = NULL; }
  349. if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; }
  350. if (g_pVertexConstantBuffer) { g_pVertexConstantBuffer->Release(); g_pVertexConstantBuffer = NULL; }
  351. if (g_pInputLayout) { g_pInputLayout->Release(); g_pInputLayout = NULL; }
  352. if (g_pVertexShader) { g_pVertexShader->Release(); g_pVertexShader = NULL; }
  353. if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; }
  354. }
  355. bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context)
  356. {
  357. g_hWnd = (HWND)hwnd;
  358. g_pd3dDevice = device;
  359. g_pd3dDeviceContext = device_context;
  360. if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
  361. return false;
  362. if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
  363. return false;
  364. ImGuiIO& io = ImGui::GetIO();
  365. io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime.
  366. io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT;
  367. io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
  368. io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
  369. io.KeyMap[ImGuiKey_DownArrow] = VK_UP;
  370. io.KeyMap[ImGuiKey_Home] = VK_HOME;
  371. io.KeyMap[ImGuiKey_End] = VK_END;
  372. io.KeyMap[ImGuiKey_Delete] = VK_DELETE;
  373. io.KeyMap[ImGuiKey_Backspace] = VK_BACK;
  374. io.KeyMap[ImGuiKey_Enter] = VK_RETURN;
  375. io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE;
  376. io.KeyMap[ImGuiKey_A] = 'A';
  377. io.KeyMap[ImGuiKey_C] = 'C';
  378. io.KeyMap[ImGuiKey_V] = 'V';
  379. io.KeyMap[ImGuiKey_X] = 'X';
  380. io.KeyMap[ImGuiKey_Y] = 'Y';
  381. io.KeyMap[ImGuiKey_Z] = 'Z';
  382. io.RenderDrawListsFn = ImGui_ImplDX11_RenderDrawLists;
  383. io.ImeWindowHandle = g_hWnd;
  384. return true;
  385. }
  386. void ImGui_ImplDX11_Shutdown()
  387. {
  388. ImGui_ImplDX11_InvalidateDeviceObjects();
  389. ImGui::Shutdown();
  390. g_pd3dDevice = NULL;
  391. g_pd3dDeviceContext = NULL;
  392. g_hWnd = (HWND)0;
  393. }
  394. void ImGui_ImplDX11_NewFrame()
  395. {
  396. if (!g_pVB)
  397. ImGui_ImplDX11_CreateDeviceObjects();
  398. ImGuiIO& io = ImGui::GetIO();
  399. // Setup display size (every frame to accommodate for window resizing)
  400. RECT rect;
  401. GetClientRect(g_hWnd, &rect);
  402. io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));
  403. // Setup time step
  404. INT64 current_time;
  405. QueryPerformanceCounter((LARGE_INTEGER *)&current_time);
  406. io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
  407. g_Time = current_time;
  408. // Read keyboard modifiers inputs
  409. io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
  410. io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
  411. io.KeyAlt = (GetKeyState(VK_MENU) & 0x8000) != 0;
  412. // io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events
  413. // io.MousePos : filled by WM_MOUSEMOVE events
  414. // io.MouseDown : filled by WM_*BUTTON* events
  415. // io.MouseWheel : filled by WM_MOUSEWHEEL events
  416. // Start the frame
  417. ImGui::NewFrame();
  418. }