Oof. Let’s try not to do that again.
I wanted to make a cloud plane, you see. Nothing complicated, just a plane in the sky with cloud textures on it, to make looking up more interesting. The only issue was that I would have to learn how to draw textures using shaders.
Oh, sure, my engine could already draw textures the old way, like this:
But back then it was a 2D engine I was writing to teach myself the rudiments of graphics programming. So I was using what’s called OpenGL’s Fixed Function Pipeline – the old-school way of drawing where OpenGL gives you a bunch of functions so you can tell it “here are some vertices, please draw them as triangles here using this texture”. Simple, but as dead as a diplodocus. Nowadays, everything is drawn using shaders, where you actually write little programs for your graphics card to run directly. Shaders are more powerful, but the FFP was what I was used to and I didn’t want to learn too many new things at once.
When I made the jump to 3D programming, I made the jump to shaders, but up until now I hadn’t had to draw textures. Turns out it’s pretty easy. And that’s where the trouble started.
Now that I was using shaders for everything, I thought, it was time to rationalise and streamline how I used them, which had been a bit ad hoc up until now. You know, like a real, grown-up programmer, like Randall Munroe.
You’ve basically got your choice of analogies here. We can either go with “falling down a fractal rabbit hole”, where every bit of code you rewrite turns out to require another bit of code to be rewritten which requires another bit of code to be rewritten until you start to forget your own name, or we can go with “replacing all the moving parts of a car engine with new ones while the car is still running”. Take your pick.
For a long while, nothing worked. Including all the bits that had previously worked, like my lovely scrolling terrain and the sky dome. Eventually, I crawled out of the next-to-last rabbit hole (yeah, went with that one in the end) back into the first rabbit hole, because that’s how fractals work, and then out into daylight. Beautiful, cloudy daylight.
Ah, it was worth it. I’m going to be doing a lot more work with shaders and textures from here on in, and I now have a solid foundation of flexible yet well-structured code on which to build.
Now if you’ll excuse me, I have some tidying to do.