Restore Tut00, Tut01 and Tut02

This commit is contained in:
Lynix 2022-02-14 14:47:10 +01:00
parent a54049494e
commit ac89667b75
9 changed files with 126 additions and 116 deletions

View File

@ -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

View File

@ -6,19 +6,13 @@
#include <Nazara/Physics3D.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NazaraSDK/Application.hpp>
#include <iostream>
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<Nz::Audio, Nz::Core, Nz::Graphics, Nz::Network, Nz::Physics2D, Nz::Physics3D, Nz::Renderer, Nz::Utility> nazara;
return EXIT_SUCCESS;
}

5
examples/Tut00/xmake.lua Normal file
View File

@ -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")

View File

@ -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

View File

@ -1,55 +1,70 @@
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World
#include <Nazara/Graphics.hpp>
#include <Nazara/Graphics/Components.hpp>
#include <Nazara/Graphics/Systems.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NazaraSDK/Application.hpp>
#include <NazaraSDK/Components.hpp>
#include <NazaraSDK/Systems.hpp>
#include <NazaraSDK/World.hpp>
#include <Nazara/Utility/Components.hpp>
#include <entt/entt.hpp>
#include <iostream>
int main(int argc, char* argv[])
int main()
{
Ndk::Application application(argc, argv);
Nz::Modules<Nz::Graphics> nazara;
Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>();
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<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214)));
Ndk::EntityHandle viewEntity = world.CreateEntity();
viewEntity->AddComponent<Ndk::NodeComponent>();
Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
viewer.SetTarget(&mainWindow);
viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
entt::entity cameraEntity = registry.create();
{
registry.emplace<Nz::NodeComponent>(cameraEntity);
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(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<Nz::Material> material = std::make_shared<Nz::Material>();
std::shared_ptr<Nz::MaterialPass> materialPass = std::make_shared<Nz::MaterialPass>(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<Nz::Material>();
material->AddPass("ForwardPass", materialPass);
std::shared_ptr<Nz::TextSprite> textSprite = std::make_shared<Nz::TextSprite>(material);
textSprite->Update(textDrawer);
Ndk::EntityHandle text = world.CreateEntity();
Ndk::NodeComponent& nodeComponent = text->AddComponent<Ndk::NodeComponent>();
entt::entity textEntity = registry.create();
{
auto& nodeComponent = registry.emplace<Nz::NodeComponent>(textEntity);
auto& gfxComponent = registry.emplace<Nz::GraphicsComponent>(textEntity);
gfxComponent.AttachRenderable(textSprite, 0xFFFFFFFF);
Ndk::GraphicsComponent& graphicsComponent = text->AddComponent<Ndk::GraphicsComponent>();
graphicsComponent.Attach(textSprite);
Nz::Boxf textBox = graphicsComponent.GetAABB();
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 (application.Run())
while (mainWindow.IsOpen())
{
mainWindow.Display();
mainWindow.ProcessEvents();
Nz::RenderFrame renderFrame = mainWindow.AcquireFrame();
renderSystem.Render(registry, renderFrame);
renderFrame.Present();
}
return EXIT_SUCCESS;

6
examples/Tut01/xmake.lua Normal file
View File

@ -0,0 +1,6 @@
target("Tut01_HelloWorld")
set_group("Examples")
set_kind("binary")
add_deps("NazaraGraphics")
add_packages("entt")
add_files("main.cpp")

View File

@ -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

View File

@ -1,49 +1,87 @@
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Gestion-des-événements
#include <Nazara/Graphics.hpp>
#include <Nazara/Graphics/Components.hpp>
#include <Nazara/Graphics/Systems.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NazaraSDK/Application.hpp>
#include <NazaraSDK/Components.hpp>
#include <NazaraSDK/Systems.hpp>
#include <NazaraSDK/World.hpp>
#include <Nazara/Utility/Components.hpp>
#include <entt/entt.hpp>
#include <iostream>
int main(int argc, char* argv[])
int main()
{
Ndk::Application application(argc, argv);
Nz::Modules<Nz::Graphics> nazara;
Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>();
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<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214)));
entt::entity cameraEntity = registry.create();
{
registry.emplace<Nz::NodeComponent>(cameraEntity);
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(cameraEntity, mainWindow.GetRenderTarget(), Nz::ProjectionType::Orthographic);
cameraComponent.UpdateClearColor(Nz::Color(117, 122, 214, 255));
}
Ndk::EntityHandle viewEntity = world.CreateEntity();
viewEntity->AddComponent<Ndk::NodeComponent>();
Nz::SimpleTextDrawer textDrawer;
textDrawer.SetCharacterSize(72);
textDrawer.SetOutlineThickness(4.f);
textDrawer.SetText("Press a key");
Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
viewer.SetTarget(&mainWindow);
viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
std::shared_ptr<Nz::Material> material = std::make_shared<Nz::Material>();
std::shared_ptr<Nz::MaterialPass> materialPass = std::make_shared<Nz::MaterialPass>(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<Nz::Material>();
material->AddPass("ForwardPass", materialPass);
std::shared_ptr<Nz::TextSprite> textSprite = std::make_shared<Nz::TextSprite>(material);
textSprite->Update(textDrawer);
entt::entity textEntity = registry.create();
{
auto& nodeComponent = registry.emplace<Nz::NodeComponent>(textEntity);
auto& gfxComponent = registry.emplace<Nz::GraphicsComponent>(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<Nz::NodeComponent>(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;

6
examples/Tut02/xmake.lua Normal file
View File

@ -0,0 +1,6 @@
target("Tut02_Events")
set_group("Examples")
set_kind("binary")
add_deps("NazaraGraphics")
add_packages("entt")
add_files("main.cpp")