Restore Tut00, Tut01 and Tut02
This commit is contained in:
parent
a54049494e
commit
ac89667b75
|
|
@ -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
|
|
||||||
|
|
@ -6,19 +6,13 @@
|
||||||
#include <Nazara/Physics3D.hpp>
|
#include <Nazara/Physics3D.hpp>
|
||||||
#include <Nazara/Renderer.hpp>
|
#include <Nazara/Renderer.hpp>
|
||||||
#include <Nazara/Utility.hpp>
|
#include <Nazara/Utility.hpp>
|
||||||
#include <NazaraSDK/Application.hpp>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// This "example" has only one purpose: Giving an empty project for you to test whatever you want
|
// 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
|
// 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);
|
Nz::Modules<Nz::Audio, Nz::Core, Nz::Graphics, Nz::Network, Nz::Physics2D, Nz::Physics3D, Nz::Renderer, Nz::Utility> nazara;
|
||||||
|
|
||||||
// Do what you want here
|
|
||||||
Nz::LuaInstance lua;
|
|
||||||
std::cout << lua.Execute("return {key = 42}") << std::endl;
|
|
||||||
std::cout << lua.DumpStack() << std::endl;
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -1,55 +1,70 @@
|
||||||
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World
|
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World
|
||||||
|
|
||||||
#include <Nazara/Graphics.hpp>
|
#include <Nazara/Graphics.hpp>
|
||||||
|
#include <Nazara/Graphics/Components.hpp>
|
||||||
|
#include <Nazara/Graphics/Systems.hpp>
|
||||||
#include <Nazara/Renderer.hpp>
|
#include <Nazara/Renderer.hpp>
|
||||||
#include <Nazara/Utility.hpp>
|
#include <Nazara/Utility.hpp>
|
||||||
#include <NazaraSDK/Application.hpp>
|
#include <Nazara/Utility/Components.hpp>
|
||||||
#include <NazaraSDK/Components.hpp>
|
#include <entt/entt.hpp>
|
||||||
#include <NazaraSDK/Systems.hpp>
|
|
||||||
#include <NazaraSDK/World.hpp>
|
|
||||||
#include <iostream>
|
#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>();
|
Nz::RenderWindow mainWindow(Nz::Graphics::Instance()->GetRenderDevice(), Nz::VideoMode(1280, 720, 32), "Test");
|
||||||
mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test");
|
|
||||||
|
|
||||||
|
entt::registry registry;
|
||||||
|
Nz::RenderSystem renderSystem(registry);
|
||||||
|
|
||||||
Ndk::World& world = application.AddWorld();
|
entt::entity cameraEntity = registry.create();
|
||||||
world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
|
{
|
||||||
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214)));
|
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>();
|
|
||||||
|
|
||||||
Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
|
|
||||||
viewer.SetTarget(&mainWindow);
|
|
||||||
viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
|
|
||||||
|
|
||||||
Nz::SimpleTextDrawer textDrawer;
|
Nz::SimpleTextDrawer textDrawer;
|
||||||
textDrawer.SetCharacterSize(72);
|
textDrawer.SetCharacterSize(72);
|
||||||
textDrawer.SetOutlineThickness(4.f);
|
textDrawer.SetOutlineThickness(4.f);
|
||||||
textDrawer.SetText("Hello world !");
|
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);
|
textSprite->Update(textDrawer);
|
||||||
|
|
||||||
Ndk::EntityHandle text = world.CreateEntity();
|
entt::entity textEntity = registry.create();
|
||||||
Ndk::NodeComponent& nodeComponent = text->AddComponent<Ndk::NodeComponent>();
|
|
||||||
|
|
||||||
Ndk::GraphicsComponent& graphicsComponent = text->AddComponent<Ndk::GraphicsComponent>();
|
|
||||||
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())
|
|
||||||
{
|
{
|
||||||
mainWindow.Display();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (mainWindow.IsOpen())
|
||||||
|
{
|
||||||
|
mainWindow.ProcessEvents();
|
||||||
|
|
||||||
|
Nz::RenderFrame renderFrame = mainWindow.AcquireFrame();
|
||||||
|
renderSystem.Render(registry, renderFrame);
|
||||||
|
|
||||||
|
renderFrame.Present();
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
target("Tut01_HelloWorld")
|
||||||
|
set_group("Examples")
|
||||||
|
set_kind("binary")
|
||||||
|
add_deps("NazaraGraphics")
|
||||||
|
add_packages("entt")
|
||||||
|
add_files("main.cpp")
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -1,49 +1,87 @@
|
||||||
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Gestion-des-événements
|
// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Gestion-des-événements
|
||||||
|
|
||||||
#include <Nazara/Graphics.hpp>
|
#include <Nazara/Graphics.hpp>
|
||||||
|
#include <Nazara/Graphics/Components.hpp>
|
||||||
|
#include <Nazara/Graphics/Systems.hpp>
|
||||||
#include <Nazara/Renderer.hpp>
|
#include <Nazara/Renderer.hpp>
|
||||||
#include <Nazara/Utility.hpp>
|
#include <Nazara/Utility.hpp>
|
||||||
#include <NazaraSDK/Application.hpp>
|
#include <Nazara/Utility/Components.hpp>
|
||||||
#include <NazaraSDK/Components.hpp>
|
#include <entt/entt.hpp>
|
||||||
#include <NazaraSDK/Systems.hpp>
|
|
||||||
#include <NazaraSDK/World.hpp>
|
|
||||||
#include <iostream>
|
#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>();
|
Nz::RenderWindow mainWindow(Nz::Graphics::Instance()->GetRenderDevice(), Nz::VideoMode(1280, 720, 32), "Test");
|
||||||
mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test");
|
|
||||||
|
|
||||||
mainWindow.EnableCloseOnQuit(false);
|
entt::registry registry;
|
||||||
|
Nz::RenderSystem renderSystem(registry);
|
||||||
|
|
||||||
Ndk::World& world = application.AddWorld();
|
entt::entity cameraEntity = registry.create();
|
||||||
world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
|
{
|
||||||
world.GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214)));
|
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();
|
Nz::SimpleTextDrawer textDrawer;
|
||||||
viewEntity->AddComponent<Ndk::NodeComponent>();
|
textDrawer.SetCharacterSize(72);
|
||||||
|
textDrawer.SetOutlineThickness(4.f);
|
||||||
|
textDrawer.SetText("Press a key");
|
||||||
|
|
||||||
Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
|
std::shared_ptr<Nz::Material> material = std::make_shared<Nz::Material>();
|
||||||
viewer.SetTarget(&mainWindow);
|
|
||||||
viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
|
|
||||||
|
|
||||||
|
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();
|
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
|
// Profitons-en aussi pour nous donner un moyen de quitter le programme
|
||||||
if (e.virtualKey == Nz::Keyboard::VKey::Escape)
|
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 (mainWindow.IsOpen())
|
||||||
while (application.Run())
|
|
||||||
{
|
{
|
||||||
mainWindow.Display();
|
mainWindow.ProcessEvents();
|
||||||
|
|
||||||
|
Nz::RenderFrame renderFrame = mainWindow.AcquireFrame();
|
||||||
|
renderSystem.Render(registry, renderFrame);
|
||||||
|
|
||||||
|
renderFrame.Present();
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
target("Tut02_Events")
|
||||||
|
set_group("Examples")
|
||||||
|
set_kind("binary")
|
||||||
|
add_deps("NazaraGraphics")
|
||||||
|
add_packages("entt")
|
||||||
|
add_files("main.cpp")
|
||||||
Loading…
Reference in New Issue