Files
NazaraEngine/examples/Tut01/main.cpp
Lynix c94048d8c3 Example/Tut01: Improve background color
Former-commit-id: b761ac19ba3e57a1f55ce96fdaaa95e9f66fc63d [formerly dc635e12aa832e18dd621701d06f23aa4765cb4e] [formerly 7a7fb9b66042870253374cbc9b3d4496f62ff113 [formerly e11cb226ea4a699bd5003c00e94ee4151b6b1969]]
Former-commit-id: 0ec2ee1954521daed6fa31100243f3f916c1d9ab [formerly cb397680ca3bd67b83ef7b67c313ac0d5eeede65]
Former-commit-id: d71b4e6262d53715d13b75db82e52c542aace323
2016-08-29 13:32:16 +02:00

52 lines
1.7 KiB
C++

// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel-01---Hello-World
#include <Nazara/Graphics.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NDK/Application.hpp>
#include <NDK/Components.hpp>
#include <NDK/Systems.hpp>
#include <NDK/World.hpp>
#include <iostream>
int main(int argc, char* argv[])
{
Ndk::Application application(argc, argv);
Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>();
mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test");
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);
Nz::TextSpriteRef textSprite = Nz::TextSprite::New();
textSprite->Update(Nz::SimpleTextDrawer::Draw("Hello world !", 72));
Ndk::EntityHandle text = world.CreateEntity();
Ndk::NodeComponent& nodeComponent = text->AddComponent<Ndk::NodeComponent>();
Ndk::GraphicsComponent& graphicsComponent = text->AddComponent<Ndk::GraphicsComponent>();
graphicsComponent.Attach(textSprite);
Nz::Boxf textBox = graphicsComponent.GetBoundingVolume().aabb;
nodeComponent.SetPosition(mainWindow.GetWidth() / 2 - textBox.width / 2, mainWindow.GetHeight() / 2 - textBox.height / 2);
while (application.Run())
{
mainWindow.Display();
}
return EXIT_SUCCESS;
}