I have been hunting this strange bug in TGE. When TGE is build in debug mode it always tests if the correct OpenGL state is setup before rendering any objects. For some reason this test has always failed on my Amiga and I have for a long time just been running the engine without these test.

The required state is that texture unit 0 must have GL_TEXTURE_ENV_MODE set to GL_REPLACE, but it always failed because the mode was GL_MODULATE.

Now I set out to find this annoying bug and fix it but debugging on the Amiga is no easy task. There is a semi working GDB but absolutely no tools for debuging OpenGL. So the only way forward was to do the good old binary search with good old trusty printf(...).

Granted, it took quite some time, especially because my TGE port can not exit without crashing, so I had to add some printf(...), compile, watch output, crash, reboot and repeat untill I found the code segment that caused the problem.

It turns out that the misbehaving code segment was this:

glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);

But how can this change the texture environment mode? That is right, it should not change the mode, but it did. That could only be caused by a bug in MiniGL. Two minutes later, I fixed the bug in MiniGL and submitted the code to the MiniGL repository, to the benefit of all Amiga developers.

Best of all TGE stopped complaining about an invalid state and I can move on.