imgui_impl_dx11.cpp 17 KB

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