-1

I am using this code to load FBX (note: specific for FBX), the textures unable to load successfully

for (unsigned int i = 0; i < mat->GetTextureCount(type); i++) {
      aiString str;
      mat->GetTexture(type, i, &str);
      if (auto texture_inside = scene->GetEmbeddedTexture(str.C_Str())) {
        unsigned char *image_data = nullptr;
        int width, height, nrComponents;
        if (texture_inside->mHeight == 0) {
          image_data = stbi_load_from_memory(
              reinterpret_cast<unsigned char *>(texture_inside->pcData),
              texture_inside->mWidth, &width, &height, &nrComponents, 0);
        } else {
          image_data = stbi_load_from_memory(
              reinterpret_cast<unsigned char *>(texture_inside->pcData),
              texture_inside->mWidth * texture_inside->mHeight, &width, &height,
              &nrComponents, 0);
        }

        if (image_data) {
          GLenum format;
          if (nrComponents == 1)
            format = GL_RED;
          else if (nrComponents == 3)
            format = GL_RGB;
          else if (nrComponents == 4)
            format = GL_RGBA;

          unsigned int t_id;
          glGenTextures(1, &t_id);
          glBindTexture(GL_TEXTURE_2D, t_id);
          glTexImage2D(GL_TEXTURE_2D, 0, format, texture_inside->mWidth,
                       texture_inside->mHeight, 0, format, GL_UNSIGNED_BYTE,
                       image_data);
          glGenerateMipmap(GL_TEXTURE_2D);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

          glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                          GL_LINEAR_MIPMAP_LINEAR);
          glBindTexture(GL_TEXTURE_2D, 0);

          delete image_data;

          AnimTexture texture;
          texture.id = t_id;
          texture.type_name = typeName;
          texture.file_path = str.C_Str();
          textures.push_back(texture);
        }
        LOG(INFO) << "loading texture from embeded: " << str.C_Str();
      }
}

then I got error message like this:

UNSUPPORTED (log once): POSSIBLE ISSUE: unit 0 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable

My question is:

  1. How to load FBX embedded texture in a correct workable way?
  2. what did I miss here caused above errors possibly?

currently I only got wrong black dark texture.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Nicholas Jela
  • 2,540
  • 7
  • 24
  • 40

1 Answers1

0

This is a common question in the assimp-project. You can find an example how to load embedded textures here: How to deal with embedded textures

In short:

  1. Get the data from the embedded texture
  2. Encode it with a image-converter
  3. Put it into your texture on the GPU
KimKulling
  • 2,654
  • 1
  • 15
  • 26