[問題] 讀取bmp影像檔
請問一下
我利用C++ 藉由 opengl 讀取影像檔
我在windows的VC++6.0 下可以讀取
可是在mac 的XCode (C++ tool) 下就無法讀取了
請問是何種原因
以下為source code 取材自opengl超級聖經 第二版
請問是哪裏有問題
///// source code 開始
LoadDIBitmap(const char *filename, /* I - File to load */
BITMAPINFO **info) /* O - Bitmap information */
{
FILE *fp; /* Open file pointer */
GLubyte *bits; /* Bitmap pixel bits */
int bitsize; /* Size of bitmap */
int infosize; /* Size of header information */
BITMAPFILEHEADER header; /* File header */
/* Try opening the file; use "rb" mode to read this *binary* file. */
if ((fp = fopen(filename, "rb")) == NULL)
return (NULL);
/* Read the file header and any following bitmap information... */
if (fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1)
{
/* Couldn't read the file header - return NULL... */
fclose(fp);
return (NULL);
}
if (header.bfType != 'MB') /* Check for BM reversed... */
{
/* Not a bitmap file - return NULL... */
fclose(fp);
return (NULL);
}
infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL)
{
/* Couldn't allocate memory for bitmap info - return NULL... */
fclose(fp);
return (NULL);
}
if (fread(*info, 1, infosize, fp) < infosize)
{
/* Couldn't read the bitmap header - return NULL... */
free(*info);
fclose(fp);
return (NULL);
}
/* Now that we have all the header info read in, allocate memory for *
* the bitmap and read *it* in... */
if ((bitsize = (*info)->bmiHeader.biSizeImage) == 0)
bitsize = ((*info)->bmiHeader.biWidth *
(*info)->bmiHeader.biBitCount + 7) / 8 *
abs((*info)->bmiHeader.biHeight);
if ((bits = malloc(bitsize)) == NULL)
{
/* Couldn't allocate memory - return NULL! */
free(*info);
fclose(fp);
return (NULL);
}
if (fread(bits, 1, bitsize, fp) < bitsize)
{
/* Couldn't read bitmap - free memory and return NULL! */
free(*info);
free(bits);
fclose(fp);
return (NULL);
}
/* OK, everything went fine - return the allocated bitmap... */
fclose(fp);
return (bits);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.96.77.105
※ 編輯: wcmein 來自: 140.96.77.105 (07/26 13:11)
推
07/26 14:06, , 1F
07/26 14:06, 1F
→
07/26 14:20, , 2F
07/26 14:20, 2F
→
07/26 14:22, , 3F
07/26 14:22, 3F
推
07/26 14:33, , 4F
07/26 14:33, 4F
→
07/26 14:33, , 5F
07/26 14:33, 5F
→
07/26 14:34, , 6F
07/26 14:34, 6F
推
07/26 17:09, , 7F
07/26 17:09, 7F
推
07/26 17:17, , 8F
07/26 17:17, 8F
→
07/26 17:18, , 9F
07/26 17:18, 9F
推
07/26 17:59, , 10F
07/26 17:59, 10F
推
07/27 01:11, , 11F
07/27 01:11, 11F
→
07/27 01:13, , 12F
07/27 01:13, 12F
→
07/27 01:14, , 13F
07/27 01:14, 13F
→
07/27 01:14, , 14F
07/27 01:14, 14F
→
07/27 01:15, , 15F
07/27 01:15, 15F
→
07/27 01:16, , 16F
07/27 01:16, 16F
→
07/27 01:17, , 17F
07/27 01:17, 17F
→
07/27 09:23, , 18F
07/27 09:23, 18F
推
07/27 11:14, , 19F
07/27 11:14, 19F
推
07/27 11:31, , 20F
07/27 11:31, 20F
→
07/27 11:33, , 21F
07/27 11:33, 21F
→
07/27 11:35, , 22F
07/27 11:35, 22F
推
07/27 12:31, , 23F
07/27 12:31, 23F
→
07/27 12:32, , 24F
07/27 12:32, 24F
→
07/27 12:33, , 25F
07/27 12:33, 25F
→
07/27 12:34, , 26F
07/27 12:34, 26F
→
07/27 12:35, , 27F
07/27 12:35, 27F
→
07/27 12:35, , 28F
07/27 12:35, 28F
推
07/27 13:25, , 29F
07/27 13:25, 29F
推
07/28 08:24, , 30F
07/28 08:24, 30F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
問題
11
30