Live data from Hacker News

Software rendering in 500 lines of bare C++

haqr.eu

71–80 of 83 posts

Re: Software rendering in 500 lines of bare C++

#71
post #61

Earlier quoted context omitted.

[flagged]

It is a fashion thing, it is more relevant to discuss about a game engine does ECS, than what the game is all about. Meanwhile, games like Minecraft, Balatro, Stardew Valley, Celeste, Geometry Wars,... blow up in adoption.

[flagged]

Re: Software rendering in 500 lines of bare C++

#72
There's basically no such thing as "bare C++" anymore. On any modern machine you are relying on piles of code. You can't just write to registers to edit vram and output video like on some 80s computer. It all happens on top of a thick stack of APIs, drivers and firmware.

Re: Software rendering in 500 lines of bare C++

#73

Is the Foley/Van Dam book still a go to resource for this? It seems it was updated in 2013, but, honestly, I’m more familiar with the ‘82 edition that was dedicated to 2D. Back in the day, it was The Book for computer graphics.

I haven't looked at my copy in years. To me, the book is a peculiar encyclopedia with some historical importance.

I found the course note from this github to be a good refresher on the subject. While the repo source code style is distasteful to me and their old-school rasteriser in the course is too naive and unoptimal, it's still a better read than Foley I'd assume :)

Re: Software rendering in 500 lines of bare C++

#74
post #47

Earlier quoted context omitted.

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…

https://zserge.com/posts/fenster/ is what I used when I wanted "basic graphics" in a cross-platform way. But of course that's X11 and much simpler.

Ah, got me hooked readying the rest of the post with the "BGI and BASIC’s painting commands" reference. :)

Great overview of the whole approach you took there.

Re: Software rendering in 500 lines of bare C++

#75
post #57

Earlier quoted context omitted.

I have a whole chapter on that! https://gabrielgambetta.com/computer-graphics-from-scratch/1...

I bought and I am reading through your book as I build a sw rasterizer. On the chapter of clipping, it was not entirely clear to me how many planes you clip against and how many triangles result. 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 see…

My book tries to be as accessible as possible; a high schooler with little to no knowledge of linear algebra should be able to understand all of it. So in every case I've chosen simplicity (code and/or conceptually) over performance, but without sacrificing correctness. Not always an easy balancing act!

I would not recommend anyone to write a production rasterizer using the algorithms in my book. This website seems more performance-focused (Bresenham is the obvious choice to draw lines, for example).

Specifically about clipping, you can ignore all the planes except the near plane, and everything will be fine. You'll try to draw more pixels outside the canvas but that's just slow, not problematic. The near plane does protect you from divisions by zero and from points with negative Z, which project upside down and mess things up.

Re: Software rendering in 500 lines of bare C++

#76
post #14

This 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-...…

How many hours a day over the couple months?

Re: Software rendering in 500 lines of bare C++

#78
post #57

Earlier quoted context omitted.

I bought and I am reading through your book as I build a sw rasterizer. On the chapter of clipping, it was not entirely clear to me how many planes you clip against and how many triangles result. 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 see…

My book tries to be as accessible as possible; a high schooler with little to no knowledge of linear algebra should be able to understand all of it. So in every case I've chosen simplicity (code and/or conceptually) over performance, but without sacrificing correctness. Not always an easy balancing act! I would not recommend anyone to write a production rasterizer using the algorithms in my book. This website seems m…

Yeah, the book has a nice balance, it's precisely why I picked it up. It allowed me to get something up and running quickly, then iterate over it.

Re: Software rendering in 500 lines of bare C++

#79
post #45

on the topic of software rendering, im surprised how little gustavo pezzi's lectures get mentioned here on hacker news.

Hey! Gustavo here. Thanks for the mention. The 3D software renderer course is still one of my favorites, even though it was one of the first ones I've published. I recently re-recorded the chapter on perspective projection matrix.

Re: Software rendering in 500 lines of bare C++

#80
post #45

on the topic of software rendering, im surprised how little gustavo pezzi's lectures get mentioned here on hacker news.

For anyone wondering, Gustavo runs https://pikuma.com/ which has a host of lectures on a variety of topics from PlayStation 1 programming to maths to triangle rasterisation.

That's right. :-)
Post reply on HN