1

I am currently trying to create a multiplatform application (targets are Windows and Android via ndk). So the problem is in textures (as in topic of this post). It works great on windows, but in Android FreeImage_GetFileType returns FIF_UNKNOWN, despite the fact that I can read part of .png file manually from same file path (only PNG file magic, beceause then it contains some null bytes). I use them this way (only part connected to this issue):

Texture::Texture(std::string fpath)
:Resource(fpath)            //Resource makes fpath=/storage/emulated/0/+...+/+fpath (via reference)
{
    std::ifstream file(fpath);
    if(!file){           //this isnt fired both on android and windows (so it can find this file)
        std::cout << "[error]: couldn't open " << fpath << "\n";
        #ifdef ANDROID
        LOGI("[error]: couldn't open %s", fpath.c_str());
        #endif // ANDROID
    }

    std::string textureStr = std::string((std::istreambuf_iterator<char>(file)),
    std::istreambuf_iterator<char>());
    #ifdef ANDROID      /*this also works nice, prints 
    /storage/emulated/0/external_sd/Android/data/package/textures/textureUV.png
    and �PNG
    */
    LOGI("loading image: %s as %s", fpath.c_str(), textureStr.c_str());
    #else
    std::cout << "loading image " << fpath << ", " << textureStr.c_str() << "\n";
    #endif // ANDROID
    file.close();
    batchId = textureCounter;

    glGenTextures(1, &id);
    bind(GL_TEXTURE_2D);

    FREE_IMAGE_FORMAT format = FreeImage_GetFileType(fpath.c_str(), 0);
    if(format == FIF_UNKNOWN) {     //this one is triggered on Android only
        #ifdef ANDROID
        LOGI("Failed to read format %s", fpath.c_str());
        #endif // ANDROID
        std::cout << "Failed to read format @ " << fpath.c_str() << "\n";
    }
    if(format == FIF_UNKNOWN)       //this one is triggered on Android only too 
        format = FreeImage_GetFIFFromFilename(fpath.c_str());
    if(format == FIF_UNKNOWN) {    //and this one is triggered on Android only too 
        #ifdef ANDROID
        LOGI("Failed to read format v2 %s", fpath.c_str());
        #endif // ANDROID
        std::cout << "Failed to read format v2 @ " << fpath.c_str() << "\n";
    }

So, why is it working on Windows but not on Android? By the way, I have read/write access in AndroidManifest, and the textures are placed in assets folder and then extracted to sd card using AAsetManager from java (it is all before native code gets executed). I can also see thaht textures are stored correctly using adb shell cat /storage/emulated/0/external_sd/Android/data/package/textures/textureUV.png which prints the png file.

And I have to add that I have built FreeImage from source to static library. I made some changes (mosly about arm/neon stuff). But I have even tried some others people build of this library (from Linderdaum engine) with same effect (not working images type detection).

user7428910
  • 61
  • 1
  • 7

0 Answers0