Jump to content

Search the Community

Showing results for tags 'noesisgui'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to UNIGINE Forums
    • News & Announcements
    • Getting started
  • Development
    • Content Creation
    • World Design
    • Rendering
    • Animation
    • Physics, Navigation and Path Finding
    • UI Systems
    • Sound & Video
    • Editor
    • C++ Programming
    • C# Programming
    • Networking
    • Sim IG (Image Generator)
    • VR Discussions
    • General
  • Improving UNIGINE
    • Documentation
    • Feedback for UNIGINE team
    • Bug Reports
    • Unigine SDK Beta feedback
  • Community
    • Add-on Store (https://store.unigine.com/)
    • Showcase
    • Collaboration
    • Tools, Plugins, Materials & Tutorials
    • General Discussions
  • Legacy
    • UnigineScript

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Found 1 result

  1. Implementation NoesisGUI GUI sample

    Hi, At the last time I make a few tests about implementing NoesisGUI GUI framework into Unigine (just display layer and mouse movement and left button down). This is just prototype, needs refactoring (especially see header file) and maybe some optimize. It's not documented anywhere, so I would like to share with it: AppWorldLogic.h: #include <NoesisGUI.h> #include "D3D11RenderDevice.h" #include <windows.h> #define WIN32_LEAN_AND_MEAN #include <d3d11.h> #include <UnigineApp.h> #include <UnigineTextures.h> #include <UnigineGame.h> #include <UnigineMaterial.h> #include <UnigineMaterials.h> #include <UnigineLogic.h> #include "UnigineWidgets.h" #include "UnigineGui.h" #include "UnigineTextures.h" using namespace Noesis; using namespace Unigine; class AppWorldLogic : public Unigine::WorldLogic { public: Noesis::Core::Ptr<RenderDevice> device; Noesis::Core::Ptr<VGContext> context; ID3D11Device* pDevice; ID3D11DeviceContext* pContext; ID3D11RenderTargetView* pTexNoesisRTV; Noesis::IRenderer* renderer; ID3D11RenderTargetView* ppOldRtv = nullptr; ID3D11DepthStencilView* ppOldDsv = nullptr; Noesis::Core::Ptr<Noesis::IView> g_XamlView; Noesis::Core::Ptr<FrameworkElement> xaml; Unigine::TexturePtr pTexNoesisPtr; Game *game; WidgetSpritePtr hud; TexturePtr my_texture; WidgetLabelPtr widget_label; void createLabel(); void createHUDWidgetSprite(); int SetWidgetSpriteTexture(Unigine::WidgetSpritePtr sprite); bool is_click = false; AppWorldLogic(); virtual ~AppWorldLogic(); virtual int init(); virtual int update(); virtual int render(); virtual int flush(); virtual int shutdown(); virtual int destroy(); virtual int save(const Unigine::StreamPtr &stream); virtual int restore(const Unigine::StreamPtr &stream); }; AppWorldLogic.cpp: #include <NoesisGUI.h> #include "D3D11RenderDevice.h" #include "AppWorldLogic.h" #include <UnigineApp.h> #include <UnigineTextures.h> #include <UnigineGame.h> #include <UnigineMaterial.h> #include <UnigineMaterials.h> using namespace Noesis; // Error handler are invoked for fatal errors. You must never return from here void NoesisErrorHandler(const NsChar* filename, NsSize line, const NsChar* desc, NsBool fatal) { Log::message("Blad noesis %s \n", desc); } int AppWorldLogic::init() { // Write here code to be called on world initialization: initialize resources for your world scene during the world start. Noesis::GUI::Init(NoesisErrorHandler); Noesis::GUI::SetResourceProvider("."); xaml = Noesis::GUI::LoadXaml<FrameworkElement>("PasswordBox.xaml"); g_XamlView = Noesis::GUI::CreateView(xaml.GetPtr()); g_XamlView->SetSize(1600, 900); g_XamlView->SetAntialiasingMode(Noesis::Gui::AntialiasingMode_MSAA); game = Game::get(); Materials *materials = Materials::get(); MaterialPtr m = materials->findMaterial("noesis_mat"); int num = m->findTexture("albedo"); pDevice = static_cast<ID3D11Device*>(Unigine::App::get()->getD3D11Device()); pContext = nullptr; pDevice->GetImmediateContext(&pContext); // Initializes renderer. This could be done in a render thread device = *new Noesis::Render::D3D11RenderDevice(pContext); context = Noesis::GUI::CreateVGContext(device.GetPtr(), Noesis::VGOptions()); g_XamlView->GetRenderer()->Init(context.GetPtr()); renderer = g_XamlView->GetRenderer(); pTexNoesisPtr = Unigine::Texture::create(); pTexNoesisPtr->create2D(1600, 900, Unigine::Texture::FORMAT_RGBA8, Unigine::Texture::USAGE_RENDER); createHUDWidgetSprite(); createLabel(); SetWidgetSpriteTexture(hud); return 1; } void AppWorldLogic::createLabel() { GuiPtr gui = Unigine::Gui::get(); widget_label = WidgetLabel::create(gui, "Label text"); widget_label->setToolTip("This is a label"); widget_label->arrange(); widget_label->setPosition(10, 10); gui->addChild(widget_label->getWidget(), Unigine::Gui::ALIGN_OVERLAP | Unigine::Gui::ALIGN_FIXED); } int AppWorldLogic::SetWidgetSpriteTexture(Unigine::WidgetSpritePtr sprite) { my_texture = Unigine::Texture::create(); const int width = int(800); const int height = int(600); int flags = Unigine::Texture::FILTER_LINEAR | Unigine::Texture::USAGE_RENDER; my_texture->create2D(width, height, Unigine::Texture::FORMAT_RGBA8, flags); sprite->setRender(pTexNoesisPtr); return 1; } void AppWorldLogic::createHUDWidgetSprite() { GuiPtr gui = Unigine::Gui::get(); hud = WidgetSprite::create(gui); hud->setPosition(0, 0); hud->setWidth(1600); hud->setHeight(900); hud->setLayerBlendFunc(0, Unigine::Gui::BLEND_ONE, Unigine::Gui::BLEND_ONE_MINUS_SRC_ALPHA); gui->addChild(hud->getWidget(), Unigine::Gui::ALIGN_OVERLAP); } // start of the main loop int AppWorldLogic::update() { // Write here code to be called before updating each render frame: specify all graphics-related functions you want to be called every frame while your application executes. int mouseX = App::get()->getMouseX(); int mouseY = App::get()->getMouseY(); g_XamlView->MouseMove(mouseX, mouseY); if (App::get()->getMouseButtonState(App::BUTTON_LEFT)) { if (!is_click) { g_XamlView->MouseButtonDown(mouseX, mouseY, MouseButton_Left); } } ControlsPtr controls = Game::get()->getPlayer()->getControls(); return 1; } int AppWorldLogic::render() { // The engine calls this function before rendering each render frame: correct behavior after the state of the node has been updated. float ifps = game->getIFps(); if (pContext != nullptr) { ppOldRtv = nullptr; ppOldDsv = nullptr; pContext->OMGetRenderTargets(1, &ppOldRtv, &ppOldDsv); ID3D11RenderTargetView* pTexNoesisRTV = static_cast<ID3D11RenderTargetView*>(pTexNoesisPtr->getD3D11RenderTargetView()); pContext->OMSetRenderTargets(1, &pTexNoesisRTV, nullptr); // Updates view passing global time g_XamlView->Update(ifps); // Performs rendering operations. Note that the renderer associated to a view is intended // to be used in the render thread. In this simple application it is the main thread renderer = g_XamlView->GetRenderer(); // Applies changes to the render tree renderer->UpdateRenderTree(); // Renders offscreen textures. This step must be done before binding the main render target if (renderer->NeedsOffscreen()) { renderer->RenderOffscreen(); } renderer->Render(); pContext->OMSetRenderTargets(1, &ppOldRtv, ppOldDsv); } return 1; } Also you will need for e.g. D3D11RenderDevice.h and D3D11RenderDevice.cpp files that come with NoesisGUI (I can't share it here because of license agreement). For work it needs an object with "noesis_mat" material at scene. Also it needs PasswordBox.xaml file from sample delivered with NoesisGUI in data folder. It will display a Noesis GUI at the screen /xor at object in scene.
×
×
  • Create New...