c++ - Can't read DDS image header on Linux -
i use nvidia nv_dds utility load dds image files use in opengl program. works on windows fails on linux (ubuntu 12.10).initially thought problem nv_dds found fread() reads header bytes wrong offset on linux (gcc 4.7)
this block reads dds file marker , dds header:
// open file file *fp = fopen(filename.c_str(),"rb"); if (fp == null) { return false; } // read in file marker, make sure dds file char filecode[4]; fread(filecode, 1, 4, fp); if (strncmp(filecode, "dds ", 4) != 0) { fclose(fp); return false; } // read in dds header dds_header ddsh; fread(&ddsh, 1,sizeof(dds_header) , fp); when through contents of dds_header instance can see couple of real values assigned wrong properties , rest junk.
then, if comment out "dds" marker check fread() :
// open file file *fp = fopen(filename.c_str(), "rb"); if (fp == null) { return false; } // read in file marker, make sure dds file /* comment out test char filecode[4]; fread(filecode, 1, 4, fp); if (strncmp(filecode, "dds ", 4) != 0) { fclose(fp); return false; } */ // read in dds header dds_header ddsh; fread(&ddsh, sizeof( dds_header ),1 , fp);//sizeof( dds_header ) then image width value imageheight property of dds_header.the rest of properties still junk.
all doesn't happen when test on windows machine. possible fread() works differently on linux gcc on windows msvc compiler?
with gcc longs 4 bytes when compiled 32 bits , 8 bytes 64bits. use can use option -m32 or -m64 explicit target 32 or 64 bits.
Comments
Post a Comment