Jump to content
  • Advertisement

Archived

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

soconne

C++ Builder BMP Loading Problem!!!!!!!

This topic is 5446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m having huge problems trying to load a simple texture map into C++ Builder. Here''s my code for loading the BMP file. BITMAPINFOHEADER biHeader; BITMAPFILEHEADER header; unsigned char *data; unsigned char color; FILE *pfile; pfile = fopen(filename, "rb"); if(pfile == NULL) return 0; fread(&header, sizeof(BITMAPFILEHEADER), 1, pfile); if(header.bfType != BITMAP_ID) { fclose(pfile); return 0; } fread(&biHeader, sizeof(BITMAPINFOHEADER), 1, pfile); fseek(pfile, header.bfOffBits, SEEK_SET); data = new unsigned char[biHeader.biSizeImage]; fread(data, 1, biHeader.biSizeImage, pfile); int index; for(index=0; index < (int)biHeader.biSizeImage; index+=3) { color = data[index]; data[index] = data[index+2]; data[index+2] = color; } fclose(pfile); This works perfectly fine in Visual C++, but in Borland C++ Builder if I check the values of biHeader.biWidth, biHeader.biHeight, and/or biHeader.biSizeImage they all have either 0 or really "high" values, like 88083838 or something along those lines. I have the images in the current directory of the project so that''s not the issue, and I check to make sure it loads, but for some reason this code doesn''t grab the information correctly. I even tried outputing the contents of data to a file and it turned up blank! I know texture mapping is working because I constructed my own texture map manually and loaded it and it displayed fine, but with this code all I get is a white triangle. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
fread''ing structures isn''t a good idea, as different platforms or different compilers (even different compiler options) can screw it up. (because of any internal padding)

Share this post


Link to post
Share on other sites
the SizeImage param is usually 0 ;( so u''ll have to recalculate it ( = with * height * numBytesPerPixel).

watch for the padding if u dont use 2^n sized textures.

Share this post


Link to post
Share on other sites
As was previousley suggested, the problem may be with fread''ing the whole struct.

Try fread''ing each member of the struct seperatley.

Also, if I remember correctly BMP''s have scan-line padding, if necessary... You should read it a line at a time and skip the padding...

I have found that a hex editor/dumper is amazingly handy when trying to figure out why image loading code isn''t working.

Tony

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!