[英]Strange error loading texture from .bmp openGL
我的openGL程序仅渲染一半的纹理。 我使用以下代码加载了24Bit .bmp。
unsigned char header[54]; // Each BMP file begins by a 54-bytes header
unsigned int dataPos; // Position in the file where the actual data begins
unsigned int width, height;
unsigned int imageSize; // = width*height*3
// Actual RGB data
unsigned char * data;
std::ifstream file("fnai.bmp");
if (!file.is_open()) {
std::cout << "Could not open file: " << "C:\\Users\\Danne\\Documents\\Visual Studio 2013\\Projects\\02 - OpenGL\\BTH24.bmp "<< std::endl;
}
char c;
for (int i = 0; i < 54; i++) {
file.get(c);
header[i] = c;
}
if (header[0] != 'B' || header[1] != 'M') {
std::cout << "Incorrect or corrupt bmp file" << std::endl;
}
dataPos = *(int*)&(header[0x0A]);
imageSize = *(int*)&(header[0x22]);
width = *(int*)&(header[0x12]);
height = *(int*)&(header[0x16]);
if (imageSize == 0) {
imageSize = width*height * 3;
}
if (dataPos == 0) {
dataPos = 54;
}
data = new unsigned char[imageSize*3];
for (int i = 0; i < imageSize*3; i++) {
file.get(c);
data[i] = c;
}
file.close();
加载纹理时,纹理加载并且openGL接收纹理,但无法完全渲染它,结果最终像
尝试不同的图像后,它在纹理的不同部分失败了。 有人认识到这个错误吗?
我认为问题可能出在位图的深度上。 您应该尝试将其与24位(位深度)bmp文件一起使用。 在Photoshop中将文件另存为bmp时,可以更改位深度。 我个人不知道为什么只有24位工作,但是我建议尝试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.