簡體   English   中英

從.bmp openGL加載奇怪的錯誤紋理

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM