diff --git a/examples/Tut00/build_disabled.lua b/examples/Tut00/build_disabled.lua deleted file mode 100644 index 7d64037ff..000000000 --- a/examples/Tut00/build_disabled.lua +++ /dev/null @@ -1,24 +0,0 @@ -EXAMPLE.Name = "Tut00_EmptyProject" - -EXAMPLE.EnableConsole = true - -EXAMPLE.Files = { - "main.cpp" -} - -EXAMPLE.Libraries = { - "NazaraAudio", - "NazaraCore", - "NazaraGraphics", - "NazaraNetwork", - "NazaraPhysics2D", - "NazaraPhysics3D", - "NazaraPlatform", - "NazaraRenderer", - "NazaraUtility", - "NazaraSDK" -} - -if Config.PlatformSDL2 then - table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") -end diff --git a/examples/Tut00/main.cpp b/examples/Tut00/main.cpp index 5057bad12..4453a1c63 100644 --- a/examples/Tut00/main.cpp +++ b/examples/Tut00/main.cpp @@ -6,19 +6,13 @@ #include #include #include -#include #include int main(int argc, char* argv[]) { // This "example" has only one purpose: Giving an empty project for you to test whatever you want // If you wish to have multiple test projects, you only have to copy/paste this directory and change the name in the build.lua - Ndk::Application application(argc, argv); - - // Do what you want here - Nz::LuaInstance lua; - std::cout << lua.Execute("return {key = 42}") << std::endl; - std::cout << lua.DumpStack() << std::endl; + Nz::Modules nazara; return EXIT_SUCCESS; } diff --git a/examples/Tut00/xmake.lua b/examples/Tut00/xmake.lua new file mode 100644 index 000000000..abfa3f76c --- /dev/null +++ b/examples/Tut00/xmake.lua @@ -0,0 +1,5 @@ +target("Tut00_EmptyProject") + set_group("Examples") + set_kind("binary") + add_deps("NazaraAudio", "NazaraGraphics", "NazaraNetwork", "NazaraPhysics2D", "NazaraPhysics3D", "NazaraRenderer", "NazaraUtility") + add_files("main.cpp") diff --git a/examples/Tut01/build_disabled.lua b/examples/Tut01/build_disabled.lua deleted file mode 100644 index 6084317f9..000000000 --- a/examples/Tut01/build_disabled.lua +++ /dev/null @@ -1,15 +0,0 @@ -EXAMPLE.Name = "Tut01_HelloWorld" - -EXAMPLE.EnableConsole = true - -EXAMPLE.Files = { - "main.cpp" -} - -EXAMPLE.Libraries = { - "NazaraSDK" -} - -if Config.PlatformSDL2 then - table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") -end diff --git a/examples/Tut01/main.cpp b/examples/Tut01/main.cpp index 94834829c..2b4156f99 100644 --- a/examples/Tut01/main.cpp +++ b/examples/Tut01/main.cpp @@ -1,55 +1,70 @@ // Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World #include +#include +#include #include #include -#include -#include -#include -#include +#include +#include #include -int main(int argc, char* argv[]) +int main() { - Ndk::Application application(argc, argv); + Nz::Modules nazara; - Nz::RenderWindow& mainWindow = application.AddWindow(); - mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test"); + Nz::RenderWindow mainWindow(Nz::Graphics::Instance()->GetRenderDevice(), Nz::VideoMode(1280, 720, 32), "Test"); + entt::registry registry; + Nz::RenderSystem renderSystem(registry); - Ndk::World& world = application.AddWorld(); - world.GetSystem().SetGlobalUp(Nz::Vector3f::Down()); - world.GetSystem().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214))); - - - Ndk::EntityHandle viewEntity = world.CreateEntity(); - viewEntity->AddComponent(); - - Ndk::CameraComponent& viewer = viewEntity->AddComponent(); - viewer.SetTarget(&mainWindow); - viewer.SetProjectionType(Nz::ProjectionType_Orthogonal); + entt::entity cameraEntity = registry.create(); + { + registry.emplace(cameraEntity); + auto& cameraComponent = registry.emplace(cameraEntity, mainWindow.GetRenderTarget(), Nz::ProjectionType::Orthographic); + cameraComponent.UpdateClearColor(Nz::Color(117, 122, 214, 255)); + } Nz::SimpleTextDrawer textDrawer; textDrawer.SetCharacterSize(72); textDrawer.SetOutlineThickness(4.f); textDrawer.SetText("Hello world !"); - Nz::TextSpriteRef textSprite = Nz::TextSprite::New(); + std::shared_ptr material = std::make_shared(); + + std::shared_ptr materialPass = std::make_shared(Nz::BasicMaterial::GetSettings()); + materialPass->EnableDepthBuffer(true); + materialPass->EnableDepthWrite(false); + materialPass->EnableScissorTest(true); + materialPass->EnableBlending(true); + materialPass->SetBlendEquation(Nz::BlendEquation::Add, Nz::BlendEquation::Add); + materialPass->SetBlendFunc(Nz::BlendFunc::SrcAlpha, Nz::BlendFunc::InvSrcAlpha, Nz::BlendFunc::One, Nz::BlendFunc::One); + + material = std::make_shared(); + material->AddPass("ForwardPass", materialPass); + + std::shared_ptr textSprite = std::make_shared(material); textSprite->Update(textDrawer); - Ndk::EntityHandle text = world.CreateEntity(); - Ndk::NodeComponent& nodeComponent = text->AddComponent(); - - Ndk::GraphicsComponent& graphicsComponent = text->AddComponent(); - graphicsComponent.Attach(textSprite); - - Nz::Boxf textBox = graphicsComponent.GetAABB(); - Nz::Vector2ui windowSize = mainWindow.GetSize(); - nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2); - - while (application.Run()) + entt::entity textEntity = registry.create(); { - mainWindow.Display(); + auto& nodeComponent = registry.emplace(textEntity); + auto& gfxComponent = registry.emplace(textEntity); + gfxComponent.AttachRenderable(textSprite, 0xFFFFFFFF); + + Nz::Boxf textBox = textSprite->GetAABB(); + Nz::Vector2ui windowSize = mainWindow.GetSize(); + nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2); + } + + while (mainWindow.IsOpen()) + { + mainWindow.ProcessEvents(); + + Nz::RenderFrame renderFrame = mainWindow.AcquireFrame(); + renderSystem.Render(registry, renderFrame); + + renderFrame.Present(); } return EXIT_SUCCESS; diff --git a/examples/Tut01/xmake.lua b/examples/Tut01/xmake.lua new file mode 100644 index 000000000..428d6bb18 --- /dev/null +++ b/examples/Tut01/xmake.lua @@ -0,0 +1,6 @@ +target("Tut01_HelloWorld") + set_group("Examples") + set_kind("binary") + add_deps("NazaraGraphics") + add_packages("entt") + add_files("main.cpp") diff --git a/examples/Tut02/build_disabled.lua b/examples/Tut02/build_disabled.lua deleted file mode 100644 index 4ee3cd467..000000000 --- a/examples/Tut02/build_disabled.lua +++ /dev/null @@ -1,15 +0,0 @@ -EXAMPLE.Name = "Tut02_Events" - -EXAMPLE.EnableConsole = true - -EXAMPLE.Files = { - "main.cpp" -} - -EXAMPLE.Libraries = { - "NazaraSDK" -} - -if Config.PlatformSDL2 then - table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2") -end diff --git a/examples/Tut02/main.cpp b/examples/Tut02/main.cpp index cee826531..5eccc0718 100644 --- a/examples/Tut02/main.cpp +++ b/examples/Tut02/main.cpp @@ -1,49 +1,87 @@ // Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Gestion-des-événements #include +#include +#include #include #include -#include -#include -#include -#include +#include +#include #include -int main(int argc, char* argv[]) +int main() { - Ndk::Application application(argc, argv); + Nz::Modules nazara; - Nz::RenderWindow& mainWindow = application.AddWindow(); - mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test"); + Nz::RenderWindow mainWindow(Nz::Graphics::Instance()->GetRenderDevice(), Nz::VideoMode(1280, 720, 32), "Test"); - mainWindow.EnableCloseOnQuit(false); + entt::registry registry; + Nz::RenderSystem renderSystem(registry); - Ndk::World& world = application.AddWorld(); - world.GetSystem().SetGlobalUp(Nz::Vector3f::Down()); - world.GetSystem().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214))); + entt::entity cameraEntity = registry.create(); + { + registry.emplace(cameraEntity); + auto& cameraComponent = registry.emplace(cameraEntity, mainWindow.GetRenderTarget(), Nz::ProjectionType::Orthographic); + cameraComponent.UpdateClearColor(Nz::Color(117, 122, 214, 255)); + } - Ndk::EntityHandle viewEntity = world.CreateEntity(); - viewEntity->AddComponent(); + Nz::SimpleTextDrawer textDrawer; + textDrawer.SetCharacterSize(72); + textDrawer.SetOutlineThickness(4.f); + textDrawer.SetText("Press a key"); - Ndk::CameraComponent& viewer = viewEntity->AddComponent(); - viewer.SetTarget(&mainWindow); - viewer.SetProjectionType(Nz::ProjectionType_Orthogonal); + std::shared_ptr material = std::make_shared(); + std::shared_ptr materialPass = std::make_shared(Nz::BasicMaterial::GetSettings()); + materialPass->EnableDepthBuffer(true); + materialPass->EnableDepthWrite(false); + materialPass->EnableScissorTest(true); + materialPass->EnableBlending(true); + materialPass->SetBlendEquation(Nz::BlendEquation::Add, Nz::BlendEquation::Add); + materialPass->SetBlendFunc(Nz::BlendFunc::SrcAlpha, Nz::BlendFunc::InvSrcAlpha, Nz::BlendFunc::One, Nz::BlendFunc::One); + + material = std::make_shared(); + material->AddPass("ForwardPass", materialPass); + + std::shared_ptr textSprite = std::make_shared(material); + textSprite->Update(textDrawer); + + entt::entity textEntity = registry.create(); + { + auto& nodeComponent = registry.emplace(textEntity); + auto& gfxComponent = registry.emplace(textEntity); + gfxComponent.AttachRenderable(textSprite, 0xFFFFFFFF); + + Nz::Boxf textBox = textSprite->GetAABB(); + Nz::Vector2ui windowSize = mainWindow.GetSize(); + nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2); + } Nz::EventHandler& eventHandler = mainWindow.GetEventHandler(); - eventHandler.OnKeyPressed.Connect([](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e) + eventHandler.OnKeyPressed.Connect([&](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e) { - std::cout << Nz::Keyboard::GetKeyName(e.virtualKey) << std::endl; + textDrawer.SetText("You pressed " + Nz::Keyboard::GetKeyName(e.virtualKey)); + textSprite->Update(textDrawer); + + Nz::Boxf textBox = textSprite->GetAABB(); + Nz::Vector2ui windowSize = mainWindow.GetSize(); + + auto& nodeComponent = registry.get(textEntity); + nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2); // Profitons-en aussi pour nous donner un moyen de quitter le programme if (e.virtualKey == Nz::Keyboard::VKey::Escape) - Ndk::Application::Instance()->Quit(); // Cette ligne casse la boucle Run() de l'application + mainWindow.Close(); // Cette ligne casse la boucle de la fenêtre }); - - while (application.Run()) + while (mainWindow.IsOpen()) { - mainWindow.Display(); + mainWindow.ProcessEvents(); + + Nz::RenderFrame renderFrame = mainWindow.AcquireFrame(); + renderSystem.Render(registry, renderFrame); + + renderFrame.Present(); } return EXIT_SUCCESS; diff --git a/examples/Tut02/xmake.lua b/examples/Tut02/xmake.lua new file mode 100644 index 000000000..a2a4b59bf --- /dev/null +++ b/examples/Tut02/xmake.lua @@ -0,0 +1,6 @@ +target("Tut02_Events") + set_group("Examples") + set_kind("binary") + add_deps("NazaraGraphics") + add_packages("entt") + add_files("main.cpp")