'How to display an image in real-time using Rust?
I am trying to write a ray tracer and want to render my image in real time in a GUI window. Basically, I have a buffer: Vec<u8>
that is constantly updating. The question is how do I display it on the screen after completing each row. I was thinking about using iced or egui, but couldn't figure out how to output changing image without copying it each time. Solutions that are using other toolkits are also welcome.
egui asks for TextureId:
ui.image(my_texture_id, [640.0, 480.0]);
but doesn't say where to get it
Solution 1:[1]
For egui there's some example here and a note here if you want to go 3D (with an example too).
For iced there's a bunch of examples, and some of them are using image/image_viewer (e.g. pokedex).
A way to go would be to copy their code, make it compile/run, and then tweak it with your logic. If something goes wrong - you'd have more input for a more concrete SO question.
Also I don't think that there's anything wrong per se in copying the data for the purpose of buffering (see this).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | battlmonstr |