Skip to content
Sammyfreg edited this page Aug 15, 2020 · 15 revisions

Integration

Setup

  1. Copy the sources files in .\netImgui\Code\Client\ to your codebase and add them to your build process.
    • Note : When only targetting Windows OS, the netImgui compiled libraries can be used for linking instead
  2. (Optional) Generate the solutions with netImgui\Build\GenerateProject.bat.
    • Note : Outputed to '*.\netImgui\Build_projects*'
  3. (Optional) Open the solution vs2019_netImgui_Server.sln and build the netImgui server application.
    • Note : Outputed to '*netImgui\Build_bin*'

Integration

  1. Edit 'NetImgui_Config.h' with the valid path to Dear ImGui header file : #include <imgui.h>.

    • Note : Your project should now compile
  2. On platforms without support either Winsocks or POSIX, the functions declared in 'NetImgui_Network.h' needs to also be implemented.

    • Allows data exchange between the netImgui server and your application using socket connection.
    • 'NetImgui_NetworkWin32.cpp' can be used as a reference.

Note : All memory allocations done by netImgui client code are using the allocator assigned to Dear ImGui.

Changes to codebase

Very few changes needed when displaying same local Dear ImGui content on the remote netImgui server.

Note 1: 'vs2019_netImgui_Sample.sln' offers a good example of integrating netImgui to a codebase, 'SampleClient.cpp' source file in particular.

Note 2: The file 'ServerInfoTab.cpp' in the netImgui Server application, also offer a good self-contained example of netImgui client code integration.

1. [Init]
  • In your program startup, add a call to : NetImgui::Startup()
2. [Connect]
  • In your program startup (or potentially elsewhere), add a call to : NetImgui::ConnectToApp(...) or NetImgui::ConnectFromApp(...)

  • Note 1: Connection can be initiated from either the Server (ConnectFromApp) or Client (ConnectToApp), it is up to the integrater to decide which one they prefer.

  • Note 2: When initializing a connection, a new communication thread will be created using std::thread by default. A custom threading implementation can be used instead, by providing a callback function to the connection function.

  • Note 3: The connection status can be determined with : NetImgui::IsConnected() and NetImgui::IsConnectionPending().

3. [Send Texture]

Upon creation of the Dear ImGui Font texture, netImgui also needs to be made aware of it by using NetImgui::SendDataTexture(...).

  • Note 1: Other textures used by your Dear ImGui menus also need to be forwarded to the netImgui server.

  • Note 2: Updating the textures can either be done before or after establishing a connection to the netImgui server.

4. [Step Draw]

When netImgui is connected, replace calls to these 2 functions in you codebase :

  • ImGui::NewFrame() with NetImgui::NewFrame()
  • ImGui::Render() with NetImGui::EndFrame() .
  • Note 1: These two functions can help keeping the logic clean, when Imgui menus should only be displayed either locally or remotely, but not both.
//=================================================================================================
// Helper function to start a new Imgui frame.
// Can be used when Imgui Content is only displayed locally or remotely, but not both
//
//! @return : True when we started a new ImGui frame and drawing should be done.
//=================================================================================================
bool Imgui_NewFrame()
{
    if( NetImgui::IsConnected() )
    {
        return NetImgui::NewFrame();
    }
    ImGui::NewFrame();
    return true;
}

//=================================================================================================
// Helper function to end a new Imgui frame.
// Can be used when Imgui Content is only displayed locally or remotely, but not both
//
//! @return : True when a local ImGui render has completed, and should be displayed onscreen
//=================================================================================================
bool Imgui_EndFrame()
{
    if( NetImgui::IsRemoteDraw() )
    {
        NetImgui::EndFrame();
        return false;
    }	
    ImGui::Render();
    return true;	
}
  • Note 2 (Important): NetImgui::NewFrame() returns false when there is no need to refresh the UI. In which case, ImGui is not configured to received drawing commands menu drawing should be skipped using the test :

if( NetImgui::IsConnected() && !NetImgui::IsRemoteDraw() ) return;.

If this requires too much changes to your codebase, ImGui::NewFrame() / ImGui::Render() can be called instead, and just ignore the resulting rendering.

  • Note 3: NetImgui::IsRemoteDraw() can be used to customize the content when drawing ImGui menus.

  • Note 4: It is possible to both have content displayed on the netImgui server application and some different content in your own application, simultaneously.

5. [Step Shutdown]

In your program shutdown, add a call to : NetImgui::Shutdown()

Clone this wiki locally