Earlier quoted context omitted.
I like softbuffer, but it owns its window and doesn't support as many events / integrations as winit.
You might be confusing softbuffer for minifb here, as softbuffer doesn't do any window handling of its own. All window management and event handling happens through winit (or another crate providing a HasWindowHandle implementation).
Software rendering in 500 lines of bare C++
51–60 of 83 posts
Re: Software rendering in 500 lines of bare C++
#52Ok I'm following along but how do I view the tga files that this program produces? Windows can't open them.
Re: Software rendering in 500 lines of bare C++
#53Re: Software rendering in 500 lines of bare C++
#54on the topic of software rendering, im surprised how little gustavo pezzi's lectures get mentioned here on hacker news.
Re: Software rendering in 500 lines of bare C++
#55This resource, along with Mathematics for Computer Graphics by John Vince [1], was truly indispensable when I wrote my own software renderer [2]. This was long before LLMs, so the whole process took me at least a couple months - most of it trying to wrap my head around math behind computer graphics and tracking down C segmentation faults. Fun times. [1]: https://www.amazon.co.uk/Mathematics-Computer-Graphics-John-...…
Re: Software rendering in 500 lines of bare C++
#56Earlier quoted context omitted.
I'm clearly super old-school when it comes to rasterisation, and a lot of this has flown above my head. I have a ton of questions; I hope you can answer them. > (1) discard (fast but not a great user experience) What are we discarding here, and why is it fast but not a great user experience? > (2) primitive synthesis I assume this is retriangulating clipped triangles that are now no longer triangles? > reverse transf…
Sorry I was so terse! Let's ignore guard band, for now. Our rasterization surface is a rectangle. We don't need to "geometrically clip" a triangle to the rectangle's surface. Instead, we just walk the surface of the rectangle and ask two questions: (1) does the triangle capture this (sub)sample; and, (2) what's the interpolated value of the attributes at this (sub)sample. In practice, for software rasterizers, we're…
Re: Software rendering in 500 lines of bare C++
#57I wish we could have just one of these tutorials properly cover the concern of triangle clipping. This is the part that I struggle with the most in a software renderer. If you are going to be building a practical one, this is something you will eventually have to deal with, even for super basic scenes. Any time geometry intersects the view frustum you need to clip those triangles.
I have a whole chapter on that! https://gabrielgambetta.com/computer-graphics-from-scratch/1...
Presumably if you clip against all 6 planes, you get 3+6-2 = 7 triangles in the worst case, which is kind of annoying. However, if you're going to use the AAAB triangle raster method as described in this HN post, then it seems there's no need to clip against left/right/top/bottom planes of the frustum, since it is simpler to just clip the screen-space AABB of the triangle instead. So one just needs to clip against near/far. This is simpler and faster.
I was curious if you had given any thought on that, or if you plan on working on a second book with more details on these nuances.
Re: Software rendering in 500 lines of bare C++
#58Earlier quoted context omitted.
Not necessarily. Most desktop OS compositors provide a void** buffer that can be blitted to. Sure, this buffer will probably end up going through the compositor which does GPU hardware acceleration anyway, but it is definitely possible to shrink the application-side stack without relying on D2D/GLUT/GLEW/GLFW/SDL/WGPU in this case. On Windows: CreateDIBSection and BitBlt On macOS: CALayer and CATransaction commit Not…
I have done this on a number of platforms over the years. Going back to before createDIBSection existed (In fact I had something break when Windows provided an easy path and took away the method I had been using). Linux has always been a weird kettle of fish, the thing that worked best for me was imlib2 which was originally part of enlightenment. It did what it was supposed to do, hid pixel format conversion without…
I've used SDL for this in the past.
Re: Software rendering in 500 lines of bare C++
#59I went through this a few months ago in Rust. I wrote all the code by hand, no LLMs. Then I went ahead and added a small "game" on top, plus some special effects like pixelization shaders and chromatic aberration at the edge of a flashlight. https://github.com/kshitijl/tinyrenderer-rs if anyone is interested! The repo has lots and lots of in-progress screenshots so you can see the renderer come to life, plus all the…
Re: Software rendering in 500 lines of bare C++
#60Earlier quoted context omitted.
Not necessarily. Most desktop OS compositors provide a void** buffer that can be blitted to. Sure, this buffer will probably end up going through the compositor which does GPU hardware acceleration anyway, but it is definitely possible to shrink the application-side stack without relying on D2D/GLUT/GLEW/GLFW/SDL/WGPU in this case. On Windows: CreateDIBSection and BitBlt On macOS: CALayer and CATransaction commit Not…
I have done this on a number of platforms over the years. Going back to before createDIBSection existed (In fact I had something break when Windows provided an easy path and took away the method I had been using). Linux has always been a weird kettle of fish, the thing that worked best for me was imlib2 which was originally part of enlightenment. It did what it was supposed to do, hid pixel format conversion without…
But of course that's X11 and much simpler.