mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-25 13:07:01 +00:00
Examples: DirectX10: Minor tweaks, updated to latest example changes (#424)
This commit is contained in:
parent
dadd03fc11
commit
9596e6f794
@ -41,6 +41,10 @@ opengl3_example/
|
|||||||
directx9_example/
|
directx9_example/
|
||||||
DirectX9 example, Windows only.
|
DirectX9 example, Windows only.
|
||||||
|
|
||||||
|
directx10_example/
|
||||||
|
DirectX10 example, Windows only.
|
||||||
|
This is quite long and tedious, because: DirectX10.
|
||||||
|
|
||||||
directx11_example/
|
directx11_example/
|
||||||
DirectX11 example, Windows only.
|
DirectX11 example, Windows only.
|
||||||
This is quite long and tedious, because: DirectX11.
|
This is quite long and tedious, because: DirectX11.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// ImGui Win32 + DirectX10 binding
|
// ImGui Win32 + DirectX10 binding
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project.
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
// See main.cpp for an example of using this.
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
@ -44,8 +44,6 @@ struct VERTEX_CONSTANT_BUFFER
|
|||||||
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||||
void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
|
void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
void* vtx_resourceData;
|
|
||||||
void* idx_resourceData;
|
|
||||||
// Create and grow vertex/index buffers if needed
|
// Create and grow vertex/index buffers if needed
|
||||||
if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
|
if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
|
||||||
{
|
{
|
||||||
@ -58,7 +56,7 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||||
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||||
desc.MiscFlags = 0;
|
desc.MiscFlags = 0;
|
||||||
if (g_pd3dDevice->CreateBuffer(&desc, nullptr, &g_pVB) < 0)
|
if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVB) < 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,14 +70,16 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
bufferDesc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx);
|
bufferDesc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx);
|
||||||
bufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
bufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||||
bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||||
if (g_pd3dDevice->CreateBuffer(&bufferDesc, nullptr, &g_pIB) < 0)
|
if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pIB) < 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, &vtx_resourceData);
|
// Copy and convert all vertices into a single contiguous buffer
|
||||||
g_pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, &idx_resourceData);
|
ImDrawVert* vtx_dst = NULL;
|
||||||
ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resourceData;
|
ImDrawIdx* idx_dst = NULL;
|
||||||
ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resourceData;
|
g_pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vtx_dst);
|
||||||
|
g_pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&idx_dst);
|
||||||
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||||
{
|
{
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||||
@ -88,16 +88,16 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
vtx_dst += cmd_list->VtxBuffer.size();
|
vtx_dst += cmd_list->VtxBuffer.size();
|
||||||
idx_dst += cmd_list->IdxBuffer.size();
|
idx_dst += cmd_list->IdxBuffer.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pVB->Unmap();
|
g_pVB->Unmap();
|
||||||
g_pIB->Unmap();
|
g_pIB->Unmap();
|
||||||
|
|
||||||
// Setup orthographic projection matrix into our constant buffer
|
// Setup orthographic projection matrix into our constant buffer
|
||||||
{
|
{
|
||||||
void* pmappedResource;
|
void* mappedResource;
|
||||||
g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pmappedResource);
|
if (g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)pmappedResource;
|
VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource;
|
||||||
const float L = 0.0f;
|
const float L = 0.0f;
|
||||||
const float R = ImGui::GetIO().DisplaySize.x;
|
const float R = ImGui::GetIO().DisplaySize.x;
|
||||||
const float B = ImGui::GetIO().DisplaySize.y;
|
const float B = ImGui::GetIO().DisplaySize.y;
|
||||||
@ -105,7 +105,7 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
const float mvp[4][4] =
|
const float mvp[4][4] =
|
||||||
{
|
{
|
||||||
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
||||||
{ 0.0f, 2.0f / (T - B), 0.0f, 0.0f, },
|
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
||||||
{ 0.0f, 0.0f, 0.5f, 0.0f },
|
{ 0.0f, 0.0f, 0.5f, 0.0f },
|
||||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
||||||
};
|
};
|
||||||
@ -346,7 +346,7 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
|||||||
cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
|
cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
|
||||||
cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||||
cbDesc.MiscFlags = 0;
|
cbDesc.MiscFlags = 0;
|
||||||
g_pd3dDevice->CreateBuffer(&cbDesc, nullptr, &g_pVertexConstantBuffer);
|
g_pd3dDevice->CreateBuffer(&cbDesc, NULL, &g_pVertexConstantBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// ImGui Win32 + DirectX10 binding
|
// ImGui Win32 + DirectX10 binding
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project.
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
// See main.cpp for an example of using this.
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
struct ID3D10Device;
|
struct ID3D10Device;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// ImGui - standalone example application for DirectX 10
|
// ImGui - standalone example application for DirectX 10
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "imgui_impl_dx10.h"
|
#include "imgui_impl_dx10.h"
|
||||||
@ -147,7 +148,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplDX10_Init(hwnd, g_pd3dDevice);
|
ImGui_ImplDX10_Init(hwnd, g_pd3dDevice);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// (see extra_fonts/README.txt for more details)
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
//ImGuiIO& io = ImGui::GetIO();
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
@ -156,12 +157,6 @@ int main(int, char**)
|
|||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
|
||||||
//static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
|
|
||||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
|
||||||
|
|
||||||
bool show_test_window = true;
|
bool show_test_window = true;
|
||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_col = ImColor(114, 144, 154);
|
ImVec4 clear_col = ImColor(114, 144, 154);
|
||||||
|
@ -106,7 +106,7 @@ void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
const float mvp[4][4] =
|
const float mvp[4][4] =
|
||||||
{
|
{
|
||||||
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
||||||
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f,},
|
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
||||||
{ 0.0f, 0.0f, 0.5f, 0.0f },
|
{ 0.0f, 0.0f, 0.5f, 0.0f },
|
||||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user