1
내 OpenGL 프로그램은 텍스처의 절반 만 렌더링합니다. 24Bit .bmp를로드하기 위해 다음 코드를 사용했습니다. .bmp에서 질감을로드하는 중 이상한 오류가 발생했습니다. openGL
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은 텍스처를 수신하지만 완전히 렌더링하는 데 실패하고 결과는 텍스처의 다른 부분에서 실패한 다른 이미지를 시도 후
처럼 끝. 누구든지이 오류를 인식합니까?
휠을 다시 발명하는 대신 이미지 라이브러리를 사용하는 것이 좋습니다. 적어도 실패하면 렌더링면에서 그 사실을 알게 될 것입니다. – Borgleader
"OpenGL에서 텍스처 크기를 조정"한다는 것은 무엇을 의미합니까? – BWG
처음에는'imageSize'가 잘못되었습니다. '.bmp' (장치 독립적 비트 맵)는 4 바이트 경계에 스캔 라인을 저장합니다. 이미지의 실제 크기는 단순히 'width * height'보다 크므로 4 바이트 정렬을 만족시키기 위해 모든 스캔 라인의 끝에서 여분의 저장 공간을 고려해야합니다. 알파 채널이있는 비트 맵에서는 큰 문제가 아니지만 RGB (24 비트)에서는 큰 문제입니다. –