Re:The joy of building a ray tracer, for fun, in Rust
by corysama on Tuesday January 04, 2022 @01:52AM
(#29792130)
“Minimal code to put pixels on the screen?” is a question I’ve seen often enough that I’ve made a little gist to link whenever it comes up. https://gist.github.com/CoryBloyd/6725bb78323bb1157ff8d4175d... It requires https://www.libsdl.org/ But, making a window and putting some pixels in it, on all the world’s varied platforms, is the premier feature of that lib.
[ Parent
| on HN ]
Re:The joy of building a ray tracer, for fun, in Rust
by boomlinde on Wednesday January 05, 2022 @09:29AM
(#29809363)
When I want a quick way to get pixels on the screen I just print a PPM image to stdout and pipe my program into `feh -`.
There are two PPM formats, both very simple: http://netpbm.sourceforge.net/doc/ppm.html
For example, the header
printf("P6\n%lu %lu\n255\n", width, height);
followed by width*height triplets of raw bytes representing the RGB values of each pixel.
Re:The joy of building a ray tracer, for fun, in Rust
by svdree on Tuesday January 04, 2022 @08:00AM
(#29794233)
MiniFB is also nice for this purpose: https://github.com/emoon/minifb
Re:The joy of building a ray tracer, for fun, in Rust
by shmerl on Tuesday January 04, 2022 @02:34AM
(#29792351)
Yeah, I figured you could use SDL. But probably more interesting to do it more directly with Rust and some WSI functions to get the needed surface (though it would be a lot more code).
Re:The joy of building a ray tracer, for fun, in Rust
by signa11 on Tuesday January 04, 2022 @02:55AM
(#29792466)
with multithreaded rendering, is it possible to use SDL ?
anecdotally, in my cpu based ray-tracers (i have one in c++ and python so far) , i have found that SDL based rendering causes noticeable slowdowns to become quite useless after the initial novelty wears off.
Re:The joy of building a ray tracer, for fun, in Rust
by corysama on Tuesday January 04, 2022 @02:58PM
(#29799450)
I've checked the code under the hood of SDL and it does pretty much the best you can do for fast uploads of an image from the CPU to the GPU.
My CPU-based ray tracer uses the code I linked. SDL_LockTexture, go wide with threads writing into the locked buffer, SDL_UnlockTexture. If I skip the actual ray tracing, I get 1400 FPS uploading a 1024x1024 image.