Technical Issue with C++ Code Using Panda3D

Hello

I am currently working on translating some Panda3D examples from Python to C++ and faced a technical issue that I need some help with.

I am trying to load a model and apply a texture to it ; but my C++ code doesn’t working as expected. The model loads fine, but the texture does not appear.

Below are relevant part of my code:

#include “pandaFramework.h”
#include “pandaSystem.h”

PandaFramework framework;

int main(int argc, char *argv) {
framework.open_framework(argc, argv);
framework.set_window_title(“My Panda3D Window”);

WindowFramework *window = framework.open_window();
if (window != nullptr) {
    NodePath model = window->load_model(framework.get_models(), "models/panda");
    model.reparent_to(window->get_render());

    // Attempt to apply texture
    PT(Texture) texture = TexturePool::load_texture("models/maps/panda_texture.png");
    if (texture != nullptr) {
        model.set_texture(texture);
    } else {
        std::cerr << "Failed to load texture" << std::endl;
    }

    window->get_camera_group().set_pos(0, -10, 0);
}

framework.main_loop();
framework.close_framework();
return 0;

}

The model appears correctly, but without the texture. The console outputs “Failed to load texture”, indicating that the texture loading part is failing. I have verified that the path to the texture is correct.

I have referred Panda3D C++ API documentation and the TexturePool-class-salesforce cpq documentation but haven’t been able to resolve the issue.

Could anyone suggest any debugging steps?

Thank you in advance!

Best regards,
nathaniel

Let me ask: Is this intended to draw from the default model-directory, or from a directory of your own named “models”?

I ask because, looking at my own default model-directory, I see the panda-model–but I don’t see a texture named “panda_texture.png”. The closest that I have seems to be “panda-model.jpg”.

Does it work when you specify an absolute path to the texture, from the filesystem root?

If so, there could be a problem related to path resolution. Panda resolves assets relative to the model-path, and by default, the directory of the binary is on the model-path. If it should be resolved relative to something else, you should add that location to the model-path in a Config.prc setting.

Hello

Thank you, Thaumaturge and rdb, for your responses.

I mistakenly assumed “panda_texture.png” was in the default model directory. I checked again and found “panda-model.jpg” instead. I will use that texture.

I tried specifying an absolute path, and it worked. I will adjust my paths accordingly and also look into updating the Config.prc settings as you suggested.

Thanks again for the help!

Best regards,
nathaniel

1 Like