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

Integration

Setup

  1. Generate the solutions with netImgui\Build\GenerateProject.bat.
    • Note : Outputed to '*.\netImgui\Build_projects*'
  2. Open the solution vs2019_netImgui_Server.sln and build the netImgui server application.
    • Note : Outputed to '*netImgui\Build_bin*'
  3. 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

Integration

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

    • Note : Your project should now compile on Windows
  2. On platforms with no support for Winsocks or POSIX, functions declared in 'NetImgui_Network.h' needs to 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, will use the Dear ImGui assigned allocator.

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 or Client, it is up to the integrater to decide if they prefer for the Server to attempt connection on a waiting client or the reverse.

  • 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, when providing a callback function to connection function.

  • Note 3: The status of connection 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. Use NetImgui::SendDataTexture(...)

  • Note 1: When using other textures in your Dear ImGui menus, also send them to 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 ImGui::NewFrame() with NetImgui::NewFrame() and ImGui::Render() with NetImGui::EndFrame() in you codebase.

  • Note 1: 'NetImgui::NewFrame()' will return false when not waiting for a new frame, in which case, all Imgui drawing should be skipped. If this requires too much code change, you can instead call 'ImGui::NewFrame() / ImGui::Render()' normally and ignore the results.

  • Note 2: 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 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