Time to resolve this mystery!
getPixelColor(x, y) is written very badly. Allow me to illustrate roughly what it's doing:
<wrapper for getPixelColor defined with ConsoleFunction>
...
void GuiBitmapCtrl::getPixelColor(int x, int y, ColorI* pOut)
{
Canvas->renderFrame(false); //Render canvas children.
Canvas->renderFrame(false); //It's called twice-- maybe for transparency, since glClear isn't called inbetween.
//renderFrame renders to the back buffer and then swaps it to front.
//Supposedly reading from the back buffer is undefined after a swap, but whatever. This is Blockland.
glReadBuffer(GL_BACK);
unsigned char pixel[3];
glReadPixels(x + this->mBounds.point.x, y + this->mBounds.point.y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);
pOut->set(pixel[0], pixel[1], pixel[2]); //Alpha = 255
}
Summary: The code renders all the canvas contents twice (this includes the scene plus any active GUI controls), then reads a pixel from the back buffer using (Ctrl.position.x + arg_x, Ctrl.position.y + arg_y).
This seems somewhat logical for the most part, but recall that by default OpenGL uses the bottom left corner for the (0, 0) position. Controls in Blockland are positioned with the (0, 0) corner at the top left. Calling getPixelColor(5, 5) on a simple bitmap control located at (100, 100) will make this code evaluate glReadPixels(105, 105, ...), which will return incorrect data, since the y coordinate is flipped.
In conclusion, getPixelColor() sucks. It should return pixels based on the bitmap's texture data, not actual pixels rendered on the canvas.
Correct usage is something like this ((0, 0) being top left corner of control):
%py = getWord(TestBitmapControl.position, 1);
%yRes = getWord(getRes(), 1);
...
%RealY = 10;
%RealX = 10;
TestBitmapControl.getPixelColor(%RealX, -2 * %py + %yRes - %RealY);
Make sure your control is in view, I guess. Obviously I don't recommend this because you will be re-rendering the entire canvas twice for every call, which would badly hurt performance when scanning an entire image, even if it were 64x64.