Funny bugs: textures be hard
A few years ago, I ventured into the wonderful world of textures as a way for my emulator to render actual graphics.
More recently, I had a go at it again to develop a simplistic UI for Goholint, which I might write about at some point.
SDL has plenty of useful tools and functions to create, manipulate and draw onto textures. Yet, in some specific cases, I’ve had to write raw bytes to a texture buffer myself.
I mentioned some potential gotchas back then:
- We have to know the texture’s exact dimensions in pixels (obviously).
- SDL must be told what the texture’s “pitch” is (that is, how many bytes are needed to draw one horizontal line the full width of that texture).
- The texture’s internal bytes representing red, blue, green and alpha components must be in the right order (Endianness Is A Pain™).
Exhibit A
So, this is what happens when you get some (or all) of those things wrong. Some of those bugs, I think I can explain1. Others… not so much. There have definitely been moments where nothing made sense anymore and I just had to revert changes to try again.
I’ll just put those screenshots down below.
Lessons learned
I have since learned to use the proper RGBA32 setting for my textures, and I also try to avoid directly writing a texture’s raw bytes, using SDL’s dedicated functions instead. I still occasionally forget that there is only one renderer and I need to be careful with the order I draw things in.
In the mean time, I got some funny-looking bugs. Textures be hard, I swear!
-
Although to be honest, I don’t always remember exactly what caused the earlier bugs, apart from “I screwed up writing those texture bytes”. The good thing is that those bugs got fixed by Past Me, somehow. Good job, Past Tiger! ↩︎