Archived

This topic is now archived and is closed to further replies.

level10boy

File Position Pointer Madness

Recommended Posts

I have recently rewritten my 8bit bitmap file loading module that I''m using for a 2D DirectX sprite engine. The original functions worked fine using 16bit windows file I/O functions such as OpenFile and _lread but when I rewrote the loading function to use C++''s fstream classes and C''s (fopen and fread) the function would no longer work correctly. I traced the problem and found that the file position pointer was behaving erratically. The BITMAPFILEHEADER and BITMAPINFOHEADER load fine but on the third invoke of fread, to read the palette data, being an 8bit .bmp file, the file position pointer seems to jump when reading palette entry 220. I discovered this by printing the position of the file pointer after every read using ftell. After reading 219 RGBQUAD structures with the third invoke of fread, the file position pointer jumps to 4240 instead of 1078 for 256 entries. Does anyone out there know why this is happening? A similar scenario occurs also when using istream::read. Thankz, level10boy

Share this post


Link to post
Share on other sites
You''re probably not opening the stream in binary mode. Add ios::binary to the mode paramater when you open the stream.

-Mike

Share this post


Link to post
Share on other sites