1#include "imguiManager.h"
2#include "application_class.h"
7imguiManager::imguiManager()
10 m_frameTimeHistoryIndex = 0;
16 total_vertex_count_ = 0;
17 total_triangle_count_ = 0;
18 visible_triangle_count_ = 0;
19 current_frame_time_ = 0;
21 showObjectWindow =
false;
22 showTerrainWindow =
false;
23 showLightWindow =
false;
24 showOldSceneWindow =
false;
25 showEngineSettingsWindow =
false;
26 showLogWindow =
false;
27 showStatsWindow =
false;
30 for (
int i = 0; i < FRAME_HISTORY_COUNT; i++)
32 m_frameTimeHistory[i] = 0.0f;
36 {&showObjectWindow, [&](){WidgetObjectWindow();}},
37 {&showEngineSettingsWindow, [&](){WidgetEngineSettingsWindow();}},
38 {&showTerrainWindow, [&](){WidgetTerrainWindow();}},
39 {&showLightWindow, [&](){WidgetLightWindow();}},
40 {&showLogWindow, [&](){WidgetLogWindow();}},
41 {&showOldSceneWindow, [&](){WidgetRenderWindow(ImVec2(800, 600));}},
42 {&showStatsWindow, [&](){WidgetRenderStats();}}
46imguiManager::~imguiManager()
50bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext)
52 Logger::Get().Log(
"Initializing imgui", __FILE__, __LINE__, Logger::LogLevel::Initialize);
55 m_deviceContext = deviceContext;
58 ImGui::CreateContext();
60 io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
61 io->ConfigFlags |= ImGuiConfigFlags_DockingEnable;
62 io->FontGlobalScale = 1.0f;
64 ImGui_ImplWin32_Init(hwnd);
65 ImGui_ImplDX11_Init(m_device, m_deviceContext);
68 ImGui::StyleColorsDark();
71 ImGuiStyle& style = ImGui::GetStyle();
74 ImVec4 background_dark = ImVec4(0.10f, 0.10f, 0.10f, 1.00f);
75 ImVec4 background = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
76 ImVec4 background_light = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
77 ImVec4 accent = ImVec4(0.14f, 0.44f, 0.80f, 0.50f);
78 ImVec4 accent_light = ImVec4(0.14f, 0.44f, 0.80f, 1.00f);
79 ImVec4 text = ImVec4(1.0f, 1.0f, 1.0f, 1.00f);
80 ImVec4 text_dim = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
83 style.WindowPadding = ImVec2(4.0f, 4.0f);
84 style.FramePadding = ImVec2(4.0f, 3.0f);
85 style.ItemSpacing = ImVec2(4.0f, 3.0f);
86 style.ItemInnerSpacing = ImVec2(3.0f, 3.0f);
87 style.DisplayWindowPadding = ImVec2(0.0f, 0.0f);
88 style.DisplaySafeAreaPadding = ImVec2(0.0f, 0.0f);
89 style.TouchExtraPadding = ImVec2(0.0f, 0.0f);
90 style.IndentSpacing = 20.0f;
91 style.ScrollbarSize = 14.0f;
92 style.GrabMinSize = 10.0f;
95 style.WindowRounding = 4.0f;
96 style.ChildRounding = 4.0f;
97 style.FrameRounding = 3.0f;
98 style.PopupRounding = 4.0f;
99 style.ScrollbarRounding = 9.0f;
100 style.GrabRounding = 3.0f;
101 style.TabRounding = 4.0f;
104 style.Colors[ImGuiCol_Text] = text;
105 style.Colors[ImGuiCol_TextDisabled] = text_dim;
106 style.Colors[ImGuiCol_WindowBg] = background;
107 style.Colors[ImGuiCol_ChildBg] = background_dark;
108 style.Colors[ImGuiCol_PopupBg] = background_dark;
109 style.Colors[ImGuiCol_Border] = ImVec4(0.25f, 0.25f, 0.27f, 1.00f);
110 style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
113 style.Colors[ImGuiCol_FrameBg] = background_light;
114 style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
115 style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f);
118 style.Colors[ImGuiCol_TitleBg] = background_dark;
119 style.Colors[ImGuiCol_TitleBgActive] = accent;
120 style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.12f, 0.12f, 0.12f, 0.90f);
123 style.Colors[ImGuiCol_MenuBarBg] = background_dark;
124 style.Colors[ImGuiCol_ScrollbarBg] = background_dark;
125 style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f);
126 style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
127 style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
130 style.Colors[ImGuiCol_CheckMark] = accent_light;
131 style.Colors[ImGuiCol_SliderGrab] = accent;
132 style.Colors[ImGuiCol_SliderGrabActive] = accent_light;
133 style.Colors[ImGuiCol_Button] = background_light;
134 style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f);
135 style.Colors[ImGuiCol_ButtonActive] = accent;
138 style.Colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
139 style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
140 style.Colors[ImGuiCol_HeaderActive] = accent;
142 style.Colors[ImGuiCol_Separator] = ImVec4(0.28f, 0.28f, 0.28f, 1.00f);
143 style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f);
144 style.Colors[ImGuiCol_SeparatorActive] = accent;
146 style.Colors[ImGuiCol_Tab] = background_dark;
147 style.Colors[ImGuiCol_TabHovered] = accent;
148 style.Colors[ImGuiCol_TabActive] = accent;
149 style.Colors[ImGuiCol_TabUnfocused] = background_dark;
150 style.Colors[ImGuiCol_TabUnfocusedActive] = background;
153 style.Colors[ImGuiCol_DockingPreview] = accent;
154 style.Colors[ImGuiCol_DockingEmptyBg] = background_light;
157 ImFontConfig fontConfig;
158 fontConfig.OversampleH = 2;
159 fontConfig.OversampleV = 2;
160 fontConfig.PixelSnapH =
true;
161 fontConfig.RasterizerMultiply = 1.2f;
162 io->Fonts->AddFontDefault(&fontConfig);
170 unsigned char* pixels;
172 io->Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
176 if (!scene_manager_->initialize(app_.get())) {
177 Logger::Get().Log(
"Failed to initialize scene manager", __FILE__, __LINE__, Logger::LogLevel::Error);
181 stats_ = app_->get_stats();
183 total_triangle_count_ = stats_->get_triangle_count_ptr();
184 total_vertex_count_ = stats_->get_vertex_count_ptr();
186 Logger::Get().Log(
"imgui initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
191void imguiManager::Shutdown()
193 Logger::Get().Log(
"Shutting down imgui", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
194 ImGui_ImplDX11_Shutdown();
195 ImGui_ImplWin32_Shutdown();
196 ImGui::DestroyContext();
197 Logger::Get().Log(
"imgui shutdown", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
200void imguiManager::Render()
207 ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
213void imguiManager::NewFrame()
215 ImGui_ImplDX11_NewFrame();
216 ImGui_ImplWin32_NewFrame();
220void imguiManager::SetupDockspace() {
222 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
223 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
224 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
227 ImGui::PushStyleVar(ImGuiStyleVar_DockingSeparatorSize, 1.0f);
230 ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
231 ImGuiViewport* viewport = ImGui::GetMainViewport();
232 ImGui::SetNextWindowPos(viewport->Pos);
233 ImGui::SetNextWindowSize(viewport->Size);
234 ImGui::SetNextWindowViewport(viewport->ID);
235 window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
236 window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
238 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
240 ImGui::Begin(
"DockSpace",
nullptr, window_flags);
243 ImGui::PopStyleVar(4);
244 ImGui::PopStyleColor();
247 ImGuiID dockspace_id = ImGui::GetID(
"MainDockSpace");
248 ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_PassthruCentralNode;
249 ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
251 if (ImGui::BeginMenuBar()) {
252 if (ImGui::BeginMenu(
"Windows")) {
253 ImGui::MenuItem(
"Object Window", NULL, &showObjectWindow);
254 ImGui::MenuItem(
"Terrain Window", NULL, &showTerrainWindow);
255 ImGui::MenuItem(
"Light Window", NULL, &showLightWindow);
256 ImGui::MenuItem(
"Engine Settings Window", NULL, &showEngineSettingsWindow);
257 ImGui::MenuItem(
"Log Window", NULL, &showLogWindow);
258 ImGui::MenuItem(
"render Stats", NULL, &showStatsWindow);
262 if (ImGui::BeginMenu(
"Scene")) {
263 if (ImGui::MenuItem(
"Save Scene")) {
264 scene_manager_->save_scene();
266 if (ImGui::MenuItem(
"Save Scene As...")) {
267 scene_manager_->save_scene_as();
269 if (ImGui::MenuItem(
"Load Scene")) {
270 scene_manager_->load_scene();
281void imguiManager::WidgetSpeedSlider(
float* speed)
283 ImGui::SliderFloat(
"Speed", speed, 0.0f, 100.0f);
286void imguiManager::WidgetButton()
288 static int counter = 0;
290 if (ImGui::Button(
"Button"))
293 ImGui::Text(
"counter = %d", counter);
296void imguiManager::WidgetAddObject()
298 if (ImGui::CollapsingHeader(
"Objects"))
300 if (ImGui::Button(
"Add Cube"))
305 if (ImGui::Button(
"Import Object"))
310 ZeroMemory(&ofn,
sizeof(ofn));
311 ofn.lStructSize =
sizeof(ofn);
312 ofn.hwndOwner = NULL;
313 ofn.lpstrFile = szFile;
314 ofn.lpstrFile[0] =
'\0';
315 ofn.nMaxFile =
sizeof(szFile);
316 ofn.lpstrFilter = L
"OBJ\0*.obj\0KOBJ\0*.kobj\0TXT\0*.txt";
317 ofn.nFilterIndex = 1;
318 ofn.lpstrFileTitle = NULL;
319 ofn.nMaxFileTitle = 0;
320 ofn.lpstrInitialDir = NULL;
321 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
323 if (GetOpenFileName(&ofn))
325 std::wstring filepath = ofn.lpstrFile;
327 WCHAR exePath[MAX_PATH];
328 GetModuleFileName(NULL,exePath,MAX_PATH);
329 std::wstring exeDir = exePath;
330 size_t pos = exeDir.find_last_of(L
"\\/");
331 if(pos != std::wstring::npos)
333 exeDir = exeDir.substr(0, pos);
336 std::wstring targetDir = exeDir + L
"\\Content\\Assets\\Kobject";
339 DWORD ftyp = GetFileAttributesW(targetDir.c_str());
340 if( ftyp == INVALID_FILE_ATTRIBUTES)
342 std::wstring contentDir = exeDir + L
"\\Content";
343 if (GetFileAttributes(contentDir.c_str()) == INVALID_FILE_ATTRIBUTES)
345 CreateDirectory(contentDir.c_str(), NULL);
347 std::wstring assetsDir = contentDir + L
"\\Assets";
348 if (GetFileAttributes(assetsDir.c_str()) == INVALID_FILE_ATTRIBUTES)
350 CreateDirectory(assetsDir.c_str(), NULL);
352 std::wstring kobjectDir = assetsDir + L
"\\Kobject";
353 if (GetFileAttributes(kobjectDir.c_str()) == INVALID_FILE_ATTRIBUTES)
355 CreateDirectory(kobjectDir.c_str(), NULL);
359 size_t posFile = filepath.find_last_of(L
"\\/");
360 std::wstring filename = (posFile != std::wstring::npos) ? filepath.substr(posFile + 1) : filepath;
362 std::wstring targetPath = targetDir + L
"\\" + filename;
364 if (!CopyFile(filepath.c_str(), targetPath.c_str(), FALSE))
367 MessageBox(NULL, L
"Erreur lors de la copie du fichier.", L
"Erreur", MB_OK);
372 std::wstring relativePath = targetPath.substr(exeDir.size());
375 if (!relativePath.empty() && (relativePath[0] == L
'\\' || relativePath[0] == L
'/'))
377 relativePath.erase(0, 1);
381 std::replace(relativePath.begin(), relativePath.end(), L
'\\', L
'/');
382 app_->add_kobject(relativePath);
389 ImGui::Text(
"Number of cubes: %d", app_->get_entity_manager()->GetEntityCount());
393void imguiManager::WidgetObjectWindow()
395 ImGui::Begin(
"Objects", &showObjectWindow);
401 for (
auto& entity : entities)
409 if (identity && transform)
411 std::string headerName = identity->GetName() +
" " + std::to_string(identity->GetId());
412 if (ImGui::CollapsingHeader(headerName.c_str()))
415 XMVECTOR position = transform->GetPosition();
416 XMVECTOR rotation = transform->GetRotation();
417 XMVECTOR scale = transform->GetScale();
419 float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) };
420 std::string posLabel =
"Position##" + std::to_string(identity->GetId());
421 if (ImGui::DragFloat3(posLabel.c_str(), pos))
423 transform->SetPosition(XMVectorSet(pos[0], pos[1], pos[2], 0.0f));
424 transform->UpdateWorldMatrix();
427 float rot[3] = { XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation) };
428 std::string rotLabel =
"Rotation##" + std::to_string(identity->GetId());
429 if (ImGui::DragFloat3(rotLabel.c_str(), rot))
431 transform->SetRotation(XMVectorSet(rot[0], rot[1], rot[2], 0.0f));
432 transform->UpdateWorldMatrix();
435 float scl[3] = { XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale) };
436 std::string sclLabel =
"Scale##" + std::to_string(identity->GetId());
437 if (ImGui::DragFloat3(sclLabel.c_str(), scl))
439 transform->SetScale(XMVectorSet(scl[0], scl[1], scl[2], 0.0f));
440 transform->UpdateWorldMatrix();
446 if (render && render->GetModel())
449 std::vector<std::string> textureCategories = {
450 "Diffuse",
"Normal",
"Specular",
"Alpha"
453 std::vector<TextureType> textureTypes = {
454 TextureType::Diffuse, TextureType::Normal,
455 TextureType::Specular, TextureType::Alpha
459 std::string textureChildId =
"TextureChild##" + std::to_string(identity->GetId());
460 ImGui::BeginChild(textureChildId.c_str(), ImVec2(0, 200),
true, ImGuiWindowFlags_HorizontalScrollbar);
463 for (
int typeIndex = 0; typeIndex < textureCategories.size(); typeIndex++)
465 TextureType type = textureTypes[typeIndex];
466 std::string typeName = textureCategories[typeIndex];
469 std::string categoryLabel = typeName +
"##" + std::to_string(identity->GetId());
470 ImGui::Text(
"%s:", typeName.c_str());
474 int textureCount = 0;
475 while (render->GetModel()->GetTexture(type, textureCount) !=
nullptr)
481 std::string groupId =
"TextureGroup_" + std::to_string(identity->GetId()) +
"_" + std::to_string(typeIndex);
483 for (
int texIndex = 0; texIndex < textureCount; texIndex++)
485 ID3D11ShaderResourceView* texture = render->GetModel()->GetTexture(type, texIndex);
489 std::string buttonId =
"tex##" + std::to_string(identity->GetId()) +
"_" +
490 std::to_string(typeIndex) +
"_" +
491 std::to_string(texIndex);
493 if (ImGui::ImageButton(buttonId.c_str(), (ImTextureID)texture, ImVec2(48, 48)))
497 WCHAR szFile[260] = {0};
498 ZeroMemory(&ofn,
sizeof(ofn));
499 ofn.lStructSize =
sizeof(ofn);
500 ofn.hwndOwner = NULL;
501 ofn.lpstrFile = szFile;
502 ofn.nMaxFile =
sizeof(szFile);
503 ofn.lpstrFilter = L
"Texture\0*.png;*.jpg;*.dds\0";
504 ofn.nFilterIndex = 1;
505 ofn.lpstrInitialDir = NULL;
506 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
508 if (GetOpenFileName(&ofn))
511 render->GetModel()->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, type, texIndex);
516 if (ImGui::IsItemHovered())
518 ImGui::BeginTooltip();
519 ImGui::Text(
"%s %d", typeName.c_str(), texIndex);
520 ImGui::Image((ImTextureID)texture, ImVec2(192, 192));
529 std::string addButtonLabel =
"+##" + std::to_string(identity->GetId()) +
"_" + std::to_string(typeIndex);
530 if (ImGui::Button(addButtonLabel.c_str(), ImVec2(48, 48)))
534 WCHAR szFile[260] = {0};
535 ZeroMemory(&ofn,
sizeof(ofn));
536 ofn.lStructSize =
sizeof(ofn);
537 ofn.hwndOwner = NULL;
538 ofn.lpstrFile = szFile;
539 ofn.nMaxFile =
sizeof(szFile);
540 ofn.lpstrFilter = L
"Texture\0*.png;*.jpg;*.dds\0";
541 ofn.nFilterIndex = 1;
542 ofn.lpstrInitialDir = NULL;
543 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
545 if (GetOpenFileName(&ofn))
548 render->GetModel()->AddTexture(m_device, m_deviceContext, ofn.lpstrFile, type);
562 std::string deleteLabel =
"Delete##" + std::to_string(identity->GetId());
563 if (ImGui::Button(deleteLabel.c_str()))
565 app_->delete_entity_by_id(identity->GetId());
576 const char* shaderOptions[] = {
577 "Enable Global Lighting",
579 "Enable Cel Shading",
580 "Enable Normal Mapping",
581 "Enable Specular Mapping",
582 "Enable Alpha Mapping"
585 std::vector<ecs::ShaderType> shaderTypes = {
586 ecs::ShaderType::SUNLIGHT,
587 ecs::ShaderType::LIGHTING,
588 ecs::ShaderType::CEL_SHADING,
589 ecs::ShaderType::NORMAL_MAPPING,
590 ecs::ShaderType::SPECULAR_MAPPING,
591 ecs::ShaderType::ALPHA_MAPPING
595 int currentShader = 0;
597 for (
size_t i = 0; i < shaderTypes.size(); i++)
599 if (shaderTypes[i] == activeShader)
601 currentShader =
static_cast<int>(i);
607 std::string shaderComboId =
"Shader Options##" + std::to_string(identity->GetId());
608 if (ImGui::BeginCombo(shaderComboId.c_str(), shaderOptions[currentShader]))
610 for (
int i = 0; i < IM_ARRAYSIZE(shaderOptions); i++)
613 std::string shaderSelectableId = std::to_string(i) +
"##shader_" + std::to_string(identity->GetId());
614 bool isSelected = (currentShader == i);
615 if (ImGui::Selectable(shaderOptions[i], isSelected))
619 shader->SetActiveShader(shaderTypes[i]);
624 ImGui::SetItemDefaultFocus();
633 bool isPhysicsEnabled = (
physics !=
nullptr);
634 std::string physicsLabel =
"Physics##" + std::to_string(identity->GetId());
636 if (ImGui::Checkbox(physicsLabel.c_str(), &isPhysicsEnabled))
638 if (isPhysicsEnabled && !
physics)
644 else if (!isPhysicsEnabled &&
physics)
655 bool gravityEnabled =
physics->IsGravityEnabled();
656 std::string gravityLabel =
"Gravity##" + std::to_string(identity->GetId());
657 if (ImGui::Checkbox(gravityLabel.c_str(), &gravityEnabled))
659 physics->SetGravityEnabled(gravityEnabled);
663 std::string typeLabel =
"Type##" + std::to_string(identity->GetId());
666 if (ImGui::RadioButton((
"None##" + std::to_string(identity->GetId())).c_str(),
667 type == ecs::ObjectType::Unknown))
669 identity->SetType(ecs::ObjectType::Unknown);
672 if (ImGui::RadioButton((
"Cube##" + std::to_string(identity->GetId())).c_str(),
673 type == ecs::ObjectType::Cube))
675 identity->SetType(ecs::ObjectType::Cube);
678 if (ImGui::RadioButton((
"Sphere##" + std::to_string(identity->GetId())).c_str(),
679 type == ecs::ObjectType::Sphere))
681 identity->SetType(ecs::ObjectType::Sphere);
684 if (ImGui::RadioButton((
"Terrain##" + std::to_string(identity->GetId())).c_str(),
685 type == ecs::ObjectType::Terrain))
687 identity->SetType(ecs::ObjectType::Terrain);
701void imguiManager::WidgetTerrainWindow()
703 ImGui::Begin(
"Terrain", &showTerrainWindow);
705 ImGui::Text(
"Number of terrain cubes: %d", app_->get_terrain_entity_count());
709 if (ImGui::Button(
"Generate Flat Terrain"))
711 app_->generate_terrain();
717 ImGui::Text(
"Number of cubes on each side: ");
719 ImGui::InputInt(
"##SideCount", &m_SideCount);
727 if (ImGui::Button(
"Generate BigCube Terrain"))
729 app_->create_big_cube(m_SideCount);
734 if (ImGui::Button(
"Delete All Terrain Cubes"))
736 app_->delete_terrain();
744bool imguiManager::ImGuiWidgetRenderer()
753 ImGui::Begin(
"Khaotic Engine", NULL);
755 float speed = app_->get_speed();
757 WidgetSpeedSlider(&speed);
758 app_->set_speed(speed);
765 for (
const auto& entry : widgets_)
767 if (*entry.show ==
true) {entry.func();}
776void imguiManager::WidgetLightWindow()
778 ImGui::Begin(
"Light", &showLightWindow);
784 XMFLOAT3 direction = sunLight->GetDirection();
785 float dir[3] = { direction.x, direction.y, direction.z };
786 if (ImGui::DragFloat3(
"Sun Direction", dir))
788 sunLight->SetDirection(dir[0], dir[1], dir[2]);
791 XMFLOAT4 color = sunLight->GetDiffuseColor();
792 float col[3] = { color.x, color.y, color.z };
793 if (ImGui::ColorEdit3(
"Sun Color", col))
795 sunLight->SetDiffuseColor(col[0], col[1], col[2], 1.0f);
798 float intensity = sunLight->GetIntensity();
799 if (ImGui::DragFloat(
"Sun Intensity", &intensity, 0.1f, 0.0f, 100.0f))
801 sunLight->SetIntensity(intensity);
811 for(
auto& light : app_->get_lights())
813 std::string headerName =
"Light " + std::to_string(index);
814 if (ImGui::CollapsingHeader(headerName.c_str()))
816 XMVECTOR position = app_->get_light_position(index);
817 XMVECTOR color = app_->get_light_color(index);
818 float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) };
819 float col[3] = { XMVectorGetX(color), XMVectorGetY(color), XMVectorGetZ(color) };
821 std::string posLabel =
"Position##" + std::to_string(index);
822 std::string colLabel =
"Color##" + std::to_string(index);
824 if (ImGui::DragFloat3(posLabel.c_str(), pos))
826 app_->set_light_position(index, XMVectorSet(pos[0], pos[1], pos[2], 0.0f));
829 if (ImGui::ColorEdit3(colLabel.c_str(), col))
831 app_->set_light_color(index, XMVectorSet(col[0], col[1], col[2], 0.0f));
841void imguiManager::WidgetEngineSettingsWindow()
843 ImGui::Begin(
"Engine Settings", &showEngineSettingsWindow);
846 ImGui::Text(
"General");
849 bool vsync = app_->get_vsync();
850 if (ImGui::Checkbox(
"Vsync", &vsync))
852 app_->set_vsync(vsync);
858 ImGui::Text(
"Culling");
861 float frustumTolerance = app_->get_frustum_tolerance();
862 if (ImGui::DragFloat(
"Frustum Tolerance", &frustumTolerance, 0.1f, 0.0f, 100.0f))
864 app_->set_frustum_tolerance(frustumTolerance);
871 ImGui::Text(
"physics");
874 int physicsInterval = app_->get_physics_tick_rate();
875 if (ImGui::InputInt(
"physics Tick Rate", &physicsInterval))
877 app_->set_physics_tick_rate(physicsInterval);
881 XMVECTOR gravity = app_->get_physics()->GetGravity();
882 float gravityValues[3] = { XMVectorGetX(gravity), XMVectorGetY(gravity), XMVectorGetZ(gravity) };
883 if (ImGui::DragFloat3(
"Gravity", gravityValues))
885 app_->get_physics()->SetGravity(XMVectorSet(gravityValues[0], gravityValues[1], gravityValues[2], 0.0f));
891void imguiManager::WidgetLogWindow()
893 ImGui::Begin(
"Log Window" , &showLogWindow);
896 static ImGuiTextFilter filter;
897 filter.Draw(
"Filter ", 180);
902 if (ImGui::Button(
"Open Log File"))
904 ShellExecuteA(NULL,
"open", Logger::Get().m_logFilePath.c_str(), NULL, NULL, SW_SHOWNORMAL);
911 if (ImGui::BeginMenu(
"Log Levels"))
913 for (
size_t i = 0; i < Logger::LogLevelCount; ++i)
915 bool isVisible = !Logger::Get().m_disabledLogLevels[i];
916 if (ImGui::Checkbox(Logger::Get().GetLogLevelInfo(
static_cast<Logger::LogLevel
>(i)).name, &isVisible))
918 Logger::Get().m_disabledLogLevels[i] = !isVisible;
924 const auto& logBuffer = Logger::Get().GetLogBuffer();
925 std::vector<Logger::LogEntry> logfiltered;
926 int logCount = logBuffer.size();
929 ImGui::BeginChild(
"Log");
931 for (
const auto& log : logBuffer)
933 if (filter.PassFilter(log.message.c_str()) && !Logger::Get().m_disabledLogLevels[
static_cast<size_t>(log.level)])
935 logfiltered.push_back(log);
939 if (logfiltered.size() == 0)
941 ImGui::Text(
"No logs to display.");
945 ImGuiListClipper clipper;
946 clipper.Begin(logCount);
947 while (clipper.Step())
949 for (
int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
951 if (i < logfiltered.size()) {
952 const auto& log = logfiltered[i];
953 ImGui::TextColored(Logger::Get().GetLogLevelInfo(log.level).color, log.message.c_str());
962 if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
964 ImGui::SetScrollHereY(1.0f);
972void imguiManager::WidgetRenderWindow(ImVec2 availableSize)
974 ImGui::Begin(
"render Window");
976 ImVec2 oldWindowSize = windowSize;
977 windowSize = ImGui::GetContentRegionAvail();
980 if (oldWindowSize.x != windowSize.x || oldWindowSize.y != windowSize.y)
982 app_->set_window_size(windowSize);
987 float aspectRatio = app_->get_aspect_ratio();
989 if (windowSize.x / windowSize.y > aspectRatio)
991 windowSize.x = windowSize.y * aspectRatio;
995 windowSize.y = windowSize.x / aspectRatio;
998 ID3D11ShaderResourceView* texture = app_->get_scene_texture()->GetShaderResourceView();
1005 app_->get_direct_3d()->turn_z_buffer_off();
1006 app_->get_direct_3d()->enable_alpha_blending();
1008 ImGui::Image((ImTextureID)texture, windowSize, ImVec2(0, 0), ImVec2(1, 1), ImVec4(1, 1, 1, 1));
1012 ImGui::Text(
"render texture is not available.");
1018void imguiManager::WidgetRenderStats()
1020 ImGui::Begin(
"render Stats");
1022 current_fps_ = stats_->get_current_fps();
1023 min_fps_ = stats_->get_min_fps();
1024 max_fps_ = stats_->get_max_fps();
1025 draw_calls_ = stats_->get_draw_calls();
1031 visible_triangle_count_ = stats_->get_visible_triangle_count();
1032 current_frame_time_ = stats_->get_frame_time();
1034 m_frameTimeHistory[m_frameTimeHistoryIndex] = current_frame_time_;
1035 m_frameTimeHistoryIndex = (m_frameTimeHistoryIndex + 1) % FRAME_HISTORY_COUNT;
1037 ImGui::Text(
"FPS: %d", current_fps_);
1039 ImGui::Text(
"Min Fps: %d", min_fps_);
1041 ImGui::Text(
"Max Fps: %d", max_fps_);
1046 float frameTimeMin = FLT_MAX;
1047 float frameTimeMax = 0.0f;
1048 for (
int i = 0; i < FRAME_HISTORY_COUNT; i++) {
1049 if (m_frameTimeHistory[i] > 0.0f) {
1050 frameTimeMin = min(frameTimeMin, m_frameTimeHistory[i]);
1051 frameTimeMax = max(frameTimeMax, m_frameTimeHistory[i]);
1055 if (frameTimeMax == 0.0f) frameTimeMax = 0.033f;
1056 if (frameTimeMin == FLT_MAX) frameTimeMin = 0.0f;
1059 float margin = (frameTimeMax - frameTimeMin) * 0.1f;
1060 frameTimeMin = max(0.0f, frameTimeMin - margin);
1061 frameTimeMax += margin;
1064 ImGui::Text(
"Frame Time: %.3f ms", current_frame_time_ * 1000.0f);
1065 ImGui::PlotLines(
"FrameTimeGraph",
1067 FRAME_HISTORY_COUNT,
1068 m_frameTimeHistoryIndex,
1074 ImGui::Text(
"Draw Calls: %d", draw_calls_);
1078 ImGui::Text(
"Statistiques de rendu:");
1079 ImGui::Text(
"Vertices total: %d", *total_vertex_count_);
1081 ImGui::Text(
"Triangles total: %d", *total_triangle_count_);
1083 ImGui::Text(
"Triangles visibles: %d", visible_triangle_count_);
1085 app_->get_direct_3d()->get_video_card_info(card_name_, video_memory_);
1086 cpu_name_ = stats_->get_cpu_name();
1087 version_driver_ = stats_->get_gpu_driver_version(app_->get_direct_3d()->get_device());
1089 ImGui::Columns(3,
"GPUCPURAMColumns",
false);
1090 ImGui::SetColumnWidth(0, ImGui::GetWindowWidth() * 0.33f);
1091 ImGui::SetColumnWidth(1, ImGui::GetWindowWidth() * 0.33f);
1094 if (ImGui::CollapsingHeader(
"Informations GPU"))
1096 ImGui::Text(
"Carte graphique: %s", card_name_);
1097 ImGui::Text(
"Memoire video: %d Mo", video_memory_);
1098 ImGui::Text(
"Pilote: %s", version_driver_.c_str());
1101 ImGui::NextColumn();
1104 if (ImGui::CollapsingHeader(
"Informations CPU"))
1106 SYSTEM_INFO sysInfo;
1107 GetSystemInfo(&sysInfo);
1108 ImGui::Text(
"Processeur: %s", cpu_name_.c_str());
1109 ImGui::Text(
"Nombre de coeurs: %u", sysInfo.dwNumberOfProcessors);
1110 ImGui::Text(
"Architecture: %s", (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) ?
"x64" :
"x86");
1111 ImGui::Text(
"Taille de la page: %u octets", sysInfo.dwPageSize);
1112 ImGui::Text(
"Taille du cache: %u octets", sysInfo.dwAllocationGranularity);
1113 ImGui::Text(
"Type de processeur: %u", sysInfo.wProcessorLevel);
1114 ImGui::Text(
"Version du processeur: %u", sysInfo.wProcessorRevision);
1117 ImGui::NextColumn();
1119 if (ImGui::CollapsingHeader(
"Informations RAM"))
1121 MEMORYSTATUSEX mem_info;
1122 mem_info.dwLength =
sizeof(MEMORYSTATUSEX);
1123 GlobalMemoryStatusEx(&mem_info);
1124 ImGui::Text(
"Memoire totale: %llu Mo", mem_info.ullTotalPhys / (1024 * 1024));
1125 ImGui::Text(
"Memoire disponible: %llu Mo", mem_info.ullAvailPhys / (1024 * 1024));
1126 ImGui::Text(
"Memoire utilisee: %llu Mo", (mem_info.ullTotalPhys - mem_info.ullAvailPhys) / (1024 * 1024));