Git Product home page Git Product logo

imgui-ws's Introduction

Actions Status

imgui-ws

Dear ImGui over WebSockets

This is a small library that allows to stream a Dear ImGui scene to multiple WebSocket clients at once. This is achieved by sending Dear ImGui's DrawData structure which is then rendered in the browser using WebGL. To reduce the amount of network traffic, we send only the diffs between sequential frames (for more info - see #1).

Live examples

These are sample applications using imgui-ws, running on a Linode 2GB instance:

Example URL Description
demo-null http://imgui-ws.ggerganov.com:5001/ Dear ImGui's demo app
basic-null http://imgui-ws.ggerganov.com:5002/ Basic read-only data visualization
textures-null http://imgui-ws.ggerganov.com:5003/ Textures example

Note that these examples are "headless". This means that no graphics backend (like OpenGL, SDL, Vulkan, etc) is needed on the server, because it does not render anything. The application just generates the Dear ImGui draw data and sends it to any connected WebSocket clients where the actual rendering occurs. This has the advantage of being able to run applications with Dear ImGui interface on almost any kind of hardware, even one without a monitor or a graphics card. For example, the applications can run on a Raspberry Pi, or on a cloud VM as in the examples above.

Tools

There are a few tools that help with the development and the optimization of the ImDrawData compression. To build the SDL-based tools, use cmake -DIMGUI_WS_SUPPORT_SDL2=ON.

  • record-sdl2

    Record the ImDrawData for all rendered frames in a Dear ImGui session

    ./bin/record-sdl2 session.imdd
    
  • replay-sdl2

    Replay a session recorded with the record-sdl2 tool

    ./bin/replay-sdl2 session.imdd
    
  • compressor-benchmark

    Run the available ImDrawData compression algorithms on various pre-recorded Dear ImGui sessions. Reports compression ratio, average required bandwidth and cpu utilization:

    ./bin/compressor-benchmark session0.imdd [session1.imdd] [session2.imdd] [...]
    

Building & running

# build
git clone https://github.com/ggerganov/imgui-ws --recursive
cd imgui-ws && mkdir build && cd build
cmake ..
make

# running
./bin/demo-null 5000

Open some browsers and point them to http://localhost:5000/

Using in your application

A simple way of using this library in your cmake-based application is to add the following to your CMakeLists.txt:

include(FetchContent)
FetchContent_Declare(imgui-ws
    GIT_REPOSITORY    https://github.com/ggerganov/imgui-ws.git
    GIT_TAG           eab5d6b169ed3e5f8d26c4a6cd9a3271dd6e2dda
    GIT_SUBMODULES_RECURSE YES
    )
FetchContent_MakeAvailable(imgui-ws)
set(INCPPECT_DEBUG NO)
# add_executable(«your_executable» «sources»)
# ...
target_link_libraries(«your_executable» imgui imgui-ws)
install(TARGETS incppect uWS)

Dependencies

Screenshot

imgui-ws

Credits

imgui-ws's People

Contributors

ggerganov avatar ihilt avatar wentasah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imgui-ws's Issues

Example for sending external texture/ draw data to clients

Hi @ggerganov

Thanks for your work on imgui-ws, it's a great implementation and should be very useful.

Just wondering if you could provide a quick example for properly rendering external opengl textures in imgui windows.

I can successfully render using normal imgui in a glfw window, however get a blank screen when viewing via imgui-ws.

I have looked at the setTexture function in the header file, however am unsure how this ties in with a texture already rendered using imgui and whether I would need to setTexture for imgui-ws when constructing the original opengl3 texture, etc.

I am also unsure if a rendered opengl texture inside a imgui window is counted inside ImGuiDrawData() when imguiWS.setDrawData(ImGui::GetDrawData()); is called. A quick example or a few pointers would be great.

Kind regards,

Tom.
imgui-ws_texture_window

Windows support

Any insight as to how difficult it would be to support a windows build? I'd love to use this in a project.

How to add Ctrl+c Ctrl+v Ctrl+A function?

Thanks for this brilliant project! I think if I can copy and paste some text on imgui-ws . But i tried and failed.
Take a look at source code:

      struct Event {
          enum Type {
              Unknown = 0,
              Connected,
              Disconnected,
              MouseMove,
              MouseDown,
              MouseUp,
              MouseWheel,
              KeyPress,
              KeyDown,
              KeyUp,
              Resize,
              TakeControl,
          };

Is it difficult to add c-v c-x function?This will be very helpful.
thanks~

Texture support

Option to send texture data to clients. Currently, only the default font texture is sent.

ImDrawData compression benchmarks

Description

The goal is to create a simple framework for benchmarking various ImDrawData compression approaches by running them on the same input buffers and reporting the computation time and compression factors. This will help finding the best compression approach for #1

  • Record generated ImDrawData buffers generated from various scenes and store them in binary files
  • Implement a tool that reads those files and passes them to a custom compression function in the same way as if the buffers were generated by Dear ImGui. The tool would record the processing time and the output size.
  • Implement a tool that renders the binary files (i.e. replay) for display purposes

Client input handling

Capture various mouse/keyboard events in the browser and send them to the server.

ImGuiWS::setTexture pass value as TextureId < 0 can not display image.

  1. https://github.com/ggerganov/incppect/blob/ea0528467cc90ff401e4ba6f926e54fee8cc0ce8/src/incppect.cpp#L145
    Get error value when pass value as -1, maybe check the case of "my_id[%d]"?

  2. var tex_id = incppect.get_int32('imgui.texture_id[%d]', i);

    var texture_id = pi[1]; draw_data_offset += 4;

    int32 is incompatible with uint32. I use (pi[1] << 0) let uint32 -> int32.

  3. Is there any way to use 64-bit texture_id?

High CPU usage with demo-null

I've running demo-null locally and it seems my browser (brave) on Linux is using a lot of CPU resources in >10 threads when just visiting http://localhost:5000. I'm not even interacting with the UI. As soon as I close the tab with the UI the CPU load on those threads goes to 0 %.

Screenshot_2023-09-26_09-31-25

Is this expected?

Improve compression of ImDrawData buffers

Description

It is essential for the successful application of this WebSocket approach to minimise the amount of network traffic between the server and the clients. The WebSocket spec allows for extensions that perform general compression on the transmitted data, but it can only do so much. A custom approach, handcrafted for ImDrawData could significantly reduce the network traffic.

Current implementation

The differences are calculated per ImDrawList. For each ImDrawList, we store the position of the first vertex and subtract this value from all vertices in the draw list. This makes the ImDrawList invariant to shifts. The client takes care to restore the position offset before rendering the data.

If the current ImDrawList curList has the same size as it had in the previous frame prevList - the binary contents of curList and prevList are xored and run-length encoded. Otherwise - we send the full curList.

Ideas to explore

  • Per DrawList differences
  • Deinterleave ImDrawVtx fields
  • Rate control of focused/hovered windows
  • Alternative ImDrawList structure

Web keyCode seem not compatible with imgui IO.KeysDown

When i test ctrl event, ctrl event not enable.
I think key id is not compatible.
open demo-null and "Inputs Navigation & Focus" -> "Keyboard, Gamepad & Navigation State"

  1. pressed x, name is right
  2. pressed s, name is wrong, and not high light in virtual keyboard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.