I started playing with the stencil buffer the other day and apparently it isn’t as mystical as I once thought. A couple of years ago, back when I was still learning how to use openGL and couldn’t upload data to a vertex buffer without failing miserably and copypasting code from everywhere, I tried to use the stencil buffer, and I failed miserably. So I gave up and tried learning about textures instead. A few days ago I got distracted and decided to try again and I totally figured them out. Turns out it’s actually really simple and I was just being bad. After a few hours of work, I had these rendering.
Pretty simple to do but I think they look pretty cool. Next day I decided to take it up a notch. So I tried portal rendering in 3D. And it works. Not crazily complex, but cool for the time I put in.
And I managed that with (almost) no tutorials. At one stage things were drawing weird, e.g., the scenes in the portals were drawing outside the portals sometimes, and I just couldn’t figure out why, so I looked up some tutorials to see where I went wrong. Turns out glClear doesn’t work on buffers that have write masks set to zero (which I was doing while rendering). Protip: reset write masks after messing with them. It seems super obvious but it wasn’t at the time so keep that in mind.
But yeah, I’ve determined that stencil buffers can make things look really cool relatively easily. 10/10 recommend looking into them if you haven’t already. I will most certainly be messing with them more.