diff --git a/examples/Ecs/LogoMini.png b/examples/Ecs/LogoMini.png new file mode 100644 index 0000000..18ea8c4 Binary files /dev/null and b/examples/Ecs/LogoMini.png differ diff --git a/examples/Ecs/example.passlist b/examples/Ecs/example.passlist new file mode 100644 index 0000000..1004d76 --- /dev/null +++ b/examples/Ecs/example.passlist @@ -0,0 +1,61 @@ +passlist "Forward Passlist" +{ + attachment "DepthBuffer" + { + format "PreferredDepthStencil" + } + + pass "DepthPrepass" + { + impl "Depth" + { + MatPass "DepthPass" + } + + depthstenciloutput "DepthBuffer" + } + + attachment "ForwardOutput" + { + format "RGBA16F" + } + + pass "ForwardPass" + { + impl "Forward" + output "Output" "ForwardOutput" + depthstencilinput "DepthBuffer" + depthstenciloutput "DepthBuffer" + flag "LightShadowing" + } + + attachment "Gamma" + { + format "RGBA8" + } + + pass "Gamma correction" + { + impl "PostProcess" + { + Shader "PostProcess.GammaCorrection" + } + + input "Input" "ForwardOutput" + output "Output" "Gamma" + } + + attachment "ImguiOutput" + { + format "RGBA8" + } + + pass "Imgui" + { + impl "Imgui" + input "Input" "Gamma" + output "Output" "ImguiOutput" + } + + output "ImguiOutput" +} diff --git a/examples/Ecs/main.cpp b/examples/Ecs/main.cpp new file mode 100644 index 0000000..b0aaa3d --- /dev/null +++ b/examples/Ecs/main.cpp @@ -0,0 +1,123 @@ + +#include +#include +#include +#include +#include + +#include + +NAZARA_REQUEST_DEDICATED_GPU() + +struct MyImguiWindow + : private Nz::ImguiHandler +{ + MyImguiWindow() + { + Nz::Imgui::Instance()->AddHandler(this); + } + + ~MyImguiWindow() + { + Nz::Imgui::Instance()->RemoveHandler(this); + } + + void OnRenderImgui() override + { + ImGui::Begin("Handler Window"); + ImGui::InputFloat4("position", values); + ImGui::End(); + } + + float values[4] = { 0 }; +}; + +#if 1 +int main(int argc, char* argv[]) +#else +int WinMain(int argc, char* argv[]) +#endif +{ + NazaraUnused(argc); + NazaraUnused(argv); + + Nz::Application nazara; + auto& windowing = nazara.AddComponent(); + std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); + + auto& ecs = nazara.AddComponent(); + auto& world = ecs.AddWorld(); + + auto& renderer = world.AddSystem(); + + std::string windowTitle = "Nazara Imgui Demo"; + Nz::Window& window = windowing.CreateWindow(Nz::VideoMode(1280, 720, 32), windowTitle); + auto& swapchain = renderer.CreateSwapchain(window); + + // Init imgui now that the window is created + Nz::Imgui::Instance()->Init(window); + ImGui::EnsureContextOnThisThread(); + + // configure camera + auto camera = world.CreateEntity(); + auto passList = Nz::PipelinePassList::LoadFromFile("example.passlist"); + camera.emplace(); + + auto& cameraComponent = camera.emplace(&swapchain, passList, Nz::ProjectionType::Perspective); + cameraComponent.UpdateFOV(70.f); + cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f)); + + // Load test texture + Nz::TextureParams texParams; + texParams.renderDevice = Nz::Graphics::Instance()->GetRenderDevice(); + texParams.loadFormat = Nz::PixelFormat::RGBA8; + auto logo = Nz::Texture::LoadFromFile("LogoMini.png", texParams); + + // connect basic handler + window.GetEventHandler().OnQuit.Connect([&window](const auto* handler) { + NazaraUnused(handler); + window.Close(); + }); + + MyImguiWindow mywindow; + float val = 0.f; + float color[4] = { 1,0,0,1 }; + + Nz::MillisecondClock updateClock; + + nazara.AddUpdaterFunc(Nz::ApplicationBase::Interval{ Nz::Time::Milliseconds(16) }, [&](Nz::Time elapsed) { + if (!window.IsOpen()) + return; + + window.ProcessEvents(); + + Nz::Imgui::Instance()->Update(elapsed.AsMilliseconds() / 1000.f); + + if (ImGui::BeginMainMenuBar()) + { + if (ImGui::BeginMenu("Test")) + { + if (ImGui::MenuItem("Test", "Ctrl+O")) + printf("test\n"); + ImGui::EndMenu(); + } + ImGui::EndMainMenuBar(); + } + if (ImGui::BeginPopupModal("toto")) + { + ImGui::EndPopup(); + } + ImGui::Begin("Loop Window"); + ImGui::Image(logo.get()); + ImGui::ImageButton(logo.get()); + ImGui::SliderFloat("test", &val, 0, 10); + ImGui::ColorPicker4("Color", color, ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_InputRGB); + + ImGui::InputFloat4("value from 2nd window", mywindow.values, "%.3f", ImGuiInputTextFlags_ReadOnly); + ImGui::End(); + + Nz::Imgui::Instance()->Render(); + }); + + return nazara.Run(); +} \ No newline at end of file diff --git a/examples/Ecs/xmake.lua b/examples/Ecs/xmake.lua new file mode 100644 index 0000000..2778d28 --- /dev/null +++ b/examples/Ecs/xmake.lua @@ -0,0 +1,7 @@ + +target("NzImgui-ecs-demo") + set_group("Examples") + add_files("main.cpp") + add_packages("nazara") + add_deps("NazaraImgui") + set_rundir(".") \ No newline at end of file