I made my own bitmap loader. There's a function that loads the data from the file. It is 24bit.
This is the file's hex data:
42 4d 46 00 00 00 00 00 00 00 36 00 00 00 28 00
00 00 02 00 00 00 02 00 00 00 01 00 18 00 00 00
00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 ff ff ff ff 00 00 ff 00
00 00 ff 00 00 00
This is my loader (also outputs info to a file):
void load_texture(std::string path)
{
std::ifstream f;
f.open(path, std::ios_base::binary);
std::vector<unsigned char> store;
char buf[255];
while(!f.eof())
{
unsigned char g;
f >> g;
store.push_back(g);
}
f.close();
std::ofstream l("info.txt");
int offset = store[0xA];
int width = store[0x12];
int height = store[0x16];
int sizeraw = ((width*3)*height)+height-1*2;
int a = store[(int)offset+1];
int pad = 0;
std::vector<BGR*> imageraw;
std::vector<int*> image;
for(int y = 0; y < height;y++)
{
for(int x = pad; x < pad + (width*3); x+=3)
{
imageraw.push_back(new BGR(store[offset +x], store[offset +x+1], store[offset +x+2]));
}
pad += (width*3)+2;
}
for(int i = 0; i < imageraw.size(); i++)
{
l << "---------------------------------\n";
image.push_back(new int(imageraw[i]->B));
image.push_back(new int(imageraw[i]->G));
image.push_back(new int(imageraw[i]->R));
l << "B : "; l << imageraw[i]->B; l << " \n";
l << "G : "; l << imageraw[i]->G; l << " \n";
l << "R : "; l << imageraw[i]->R; l << " \n";
}
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,width, height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image.data());
l.close();
}
And this is the BGR structure:
struct BGR
{
int B;
int G;
int R;
BGR(int a, int b, int c): B(a), G(b), R(c) {};
};
I don't know why, but OpenGL displays the image in the wrong colors. I also have to point out that I'm a beginner at working with hexadecimal data in files. Also, the output to the file (info.txt) comes out correct.
Why does OpenGL display the wrong colors?
Another thing, what I wanna give to OGL is the integer values of BGR, like the ones in info.txt. No hex nor bin. EDIT:
This is the file result:
---------------------------------
B : 0
G : 0
R : 255
---------------------------------
B : 255
G : 255
R : 255
---------------------------------
B : 255
G : 0
R : 0
---------------------------------
B : 0
G : 255
R : 0