I have a 256256 .BMP (24 bit) as my background. When I display it, it works correctly, but if I change the .BMP to 512512 and change the values in the algorithm according to these values, I get a weird picture (totally mixed up colors). I tried it with the same bitmap scaled down to 64*64 and it worked. So, the problem shouldn’t be in the .BMP file.
What I do is:
//********************************************************************************************
Graphics::TBitmap* back;
back = new Graphics::TBitmap;
GLubyte ***textureimage;
//memory alloc
textureimage = new unsigned char **[512];
for(p=0;p<512;p++)
textureimage[p] = new GLubyte *[512];
for(n=0;n<512;n++)
for(p=0;p<512;p++)
textureimage[p][n] = new GLubyte [4];
//load BMP
back->LoadFromFile(the_filename_of_the_texture);
//get colors from BMP and stuff them into “textureimage”
for(int i = 0; i < 512; i++)
for(int j = 0; j < 512; j++)
{
textureimage[511-j][i][0]= (GLbyte)GetRValue(back->Canvas->Pixels[i][j]);
textureimage[511-j][i][1]= (GLbyte)GetGValue(back->Canvas->Pixels[i][j]);
textureimage[511-j][i][2]= (GLbyte)GetBValue(back->Canvas->Pixels[i][j]);
textureimage[511-j][i][3]= (GLbyte)255;
}
//building texture
glGenTextures(1, &background[1]);
glBindTexture(GL_TEXTURE_2D, background[1]);
glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0,
GL_RGBA, GL_UNSIGNED_BYTE, textureimage);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//********************************************************************************************
In the original version, that ran well, “512” was “256” and “511” was “255”.
When I change "GLubyte textureimage;" to “GLubyte textureimage[256][256][4]” it works fine, but with [512][512][4] I get a stack overflow (which is normal). So, I tried with pointers, but now it is impossible to get a correct map.
What did I do wrong?
How can I use a bigger (5125124, or even bigger (10241024*4)) bitmap as a texture?