This guide is about the way Coherent GT works at runtime and has to be integrated in an application. For a guide on the workflow and how to create beautiful UI with Coherent GT, please refer to our Workflow guide and the Coherent Editor guide.
This guide will show you how to
Note that the sample depends on the Coherent Sample framework and can work with DirectX 11.
Configure the Coherent::UIGT::UISystem settings in a Coherent::UIGT::SystemSettings variable. Here we only set a debugger port for debugging purposes and use everything else by default.
Coherent::UIGT::SystemSettings settings;settings.DebuggerPort = 19999;Coherent::UIGT::UISystem* system = InitializeUIGTSystem(COHERENT_UI_GT_LICENSE,settings,Coherent::LoggingGT::Info);
const char* resourcePath = "coui://uiresources/minRes/MainUI.html";FileResourceHandler fileHandler;Coherent::UIGT::ViewInfo info;info.Width = width;info.Height = height;info.IsTransparent = true;info.ResourceHandlerInstance = &fileHandler;Coherent::UIGT::View* view = system->CreateView(info, resourcePath);
All rendering in Coherent GT is performed by the Renoir graphics library on the GPU. The API-specific piece that connects the Renoir Core to the GPU is distributed for all major graphics APIs (DirectX 9/11, OpenGL, libGNM etc.) in the package. You can directly use the provided code or use it to customize and integrate the rendering in your engine. You can use your own backend by inheriting from the renoir::RendererBackend interface.
renoir::Dx11BackendSettings backendSettings;backendSettings.Device = static_cast<ID3D11Device*>(renderer.GetDevice());std::unique_ptr<renoir::Dx11Backend> backend(new renoir::Dx11Backend(&backendSettings));bool didInitialize = backend->InitializeStaticResources();
Create the Coherent::UIGT::UISystemRenderer using the Coherent::UIGT::UISystem::CreateRenderer method and the backend.
Coherent::UIGT::UISystemRenderer* systemRenderer = system->CreateRenderer(backend.get(), backend.get());
Create the Coherent::UIGT::ViewRenderer using the Coherent::UIGT::UISystemRenderer::CreateViewRenderer method and the textures from the DirectX initialization.
Coherent::UIGT::NativeRenderTarget rt = { texture.TextureRTV, depthStencil.DSV };Coherent::UIGT::ViewRenderer* viewRenderer = systemRenderer->CreateViewRenderer(view,rt,width,height,1/*sample count*/);
Propagate the events to the View event handlers.
std::function<void(const COUI_NMSPC::KeyEventData& e)> onKeyEvent = [&](const COUI_NMSPC::KeyEventData& e){view->KeyEvent(e);};std::function<void(const COUI_NMSPC::MouseEventData& e)> onMouseEvent = [&](const COUI_NMSPC::MouseEventData& e){view->MouseEvent(e);};window.setEvents(onKeyEvent, onMouseEvent);
Always destroy the resources in the following order:
viewRenderer->Destroy();viewRenderer = nullptr;view->Destroy();view = nullptr;systemRenderer->Destroy();systemRenderer = nullptr;system->Uninitialize();system = nullptr;