Advertisement
Lynix

Nazara first example

Mar 19th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <Nazara/Graphics.hpp>
  2. #include <Nazara/Renderer.hpp>
  3. #include <Nazara/Utility.hpp>
  4. #include <NDK/Application.hpp>
  5. #include <NDK/Components.hpp>
  6. #include <NDK/Systems.hpp>
  7. #include <NDK/World.hpp>
  8. #include <iostream>
  9.  
  10. int main()
  11. {
  12.     Ndk::Application application;
  13.  
  14.     Nz::RenderWindow& mainWindow = application.AddWindow<Nz::RenderWindow>();
  15.     mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test");
  16.  
  17.     Ndk::World& world = application.AddWorld();
  18.     world.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
  19.  
  20.     Nz::TextSpriteRef textSprite = Nz::TextSprite::New();
  21.     textSprite->Update(Nz::SimpleTextDrawer::Draw("Hello world !", 72));
  22.  
  23.     Nz::Boxf textSize = textSprite->GetBoundingVolume().obb.localBox;
  24.  
  25.     Ndk::EntityHandle text = world.CreateEntity();
  26.     Ndk::NodeComponent& nodeComponent = text->AddComponent<Ndk::NodeComponent>();
  27.     nodeComponent.SetPosition(mainWindow.GetWidth() / 2 - textSize.width / 2, mainWindow.GetHeight() / 2 - textSize.height / 2);
  28.  
  29.     Ndk::GraphicsComponent& graphicsComponent = text->AddComponent<Ndk::GraphicsComponent>();
  30.     graphicsComponent.Attach(textSprite);
  31.  
  32.     Ndk::EntityHandle viewEntity = world.CreateEntity();
  33.     viewEntity->AddComponent<Ndk::NodeComponent>();
  34.  
  35.     Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
  36.     viewer.SetTarget(&mainWindow);
  37.     viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
  38.  
  39.     while (application.Run())
  40.     {
  41.         Nz::WindowEvent event;
  42.         while (mainWindow.PollEvent(&event))
  43.         {
  44.             if (event.type == Nz::WindowEventType_Quit)
  45.                 Ndk::Application::Instance()->Quit();
  46.         }
  47.  
  48.         mainWindow.Display();
  49.     }
  50.  
  51.     return EXIT_SUCCESS;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement