I had a code that was loading a BMP file and displaying a quad with the BMP as texture on screen.
I was restructuring the code and when I tried to test it again, the textures weren't showing anymore.
After a bunch of tests, I got to something really weird.
The reading from the BMP wasn't changed at all, so I don't think that's the cause, and the draw function is also really simple (it's also copied from another project I'm 100% sure it's working).
I tried changing BMPs to see if that was the issue, and a bunch of other images didn't show either.
However a simple checker BMP image I did some time ago for tests was showing perfectly fine.
This is the checker image, and what displays when I call it:
This is another image I tried to display (among a bunch of others) and this is what shows:
After testing for hours and not finding anything, I decided to do a little test, I copied some pixels from the image that wasn't displaying to the one that was:
And then I called it "Weird.bmp" and tried to load it on my code, and this is what happened:
(Note the messed up first pixel row)
Also, another BMP that I was using for tests (640x913 BMP) seems to cause my BMP loading code to bug out/infinite loop, as it's header's height/width are being set to a negative value:
if(fileReader.is_open())
{
char *bitmapFileHeaderChar = new char[sizeof(BITMAPFILEHEADER)];
fileReader.read(bitmapFileHeaderChar, sizeof(BITMAPFILEHEADER));
BITMAPFILEHEADER *bitmapFileHeader = (BITMAPFILEHEADER*)(bitmapFileHeaderChar);
char *bitmapInfoHeaderChar = new char[sizeof(BITMAPINFOHEADER)];
fileReader.read(bitmapInfoHeaderChar, sizeof(BITMAPINFOHEADER));
BITMAPINFOHEADER *bitmapInfoHeader = (BITMAPINFOHEADER*)(bitmapInfoHeaderChar);
_texture->textureHeight = bitmapInfoHeader->biHeight; //On this specific BMP image, this has a -842150451
_texture->textureWidth = bitmapInfoHeader->biWidth; //This too
long imageTotalBytes = _texture->textureHeight * _texture->textureWidth * 4;
_texture->_textureData = new GLubyte[imageTotalBytes];
char pixelInfo[3];
int c = 0;
while(c < imageTotalBytes)
{
fileReader.read(pixelInfo, 3);
_texture->_textureData[c] = (GLubyte)pixelInfo[2];
_texture->_textureData[c - 1] = (GLubyte)pixelInfo[1];
_texture->_textureData[c - 2] = (GLubyte)pixelInfo[0];
_texture->_textureData[c - 3] = 255; //Manually filling alpha
c += 4;
}
fileReader.close();
}
Even after I got the original and re-saved it again, I'm still getting the same wrong header file. And it seems to be just on this specific file.
What could be causing this, or do you have any suggestions on how can I debug this?
Edit: I have this same image that has a negative header value in a binary file I made for test reading/writing, and when I load it from there, it shows perfectly fine.
However, now even my project that I use to load/read files and pack them in a single binary file isn't working anymore because it's reading this BMPs wrongly as well (it's even a different file, same image, in a different folder).