Files
NazaraEngine/examples/Tut01/main.cpp
Lynix 42db00a52c Example/Tut01: Improve background color
Former-commit-id: 883a1115cb7fee2581c8a00db0e194482cf6561e [formerly 29bf1560e1953cf52b5c78ccff06cd4505412da3] [formerly a455d8601a37dff40f7f19b3298a7bab86f721ac [formerly 845a30ade4c32adba2d3b031c5bdf85ebbefb7bf]]
Former-commit-id: cda183f3e044cf0798db4e356fc053286e22613d [formerly 17e2ff120bc690719ae5f9eb466afb8fb7728270]
Former-commit-id: e1cd50d13b37cfc293a0405093e0fb57f3990c58
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;
}