Problem with a simple render to texture

Hello, I’m new to Panda3D and I’m trying to make a simple render to texture to see if Panda3D will be useful for my application.
However I have some problems with the snippet of code in the manual.

I get the first tutorial with the panda and his environment and i’m trying to render the environment on a texture and the panda on the render window.
I haven’t even try to use my texture for now.

PT(GraphicsOutput) mybuffer;
    PT(Texture) mytexture;
    PT(Camera) mycamera;
    NodePath mycameraNP;
    NodePath myscene;
    
    // Open a new window framework and set the title
    framework.open_framework(argc, argv);
    framework.set_window_title("My Panda3D Window");
    
    // Open the window
    WindowFramework *window = framework.open_window();
    camera = window->get_camera_group(); // Get the camera and store it

    mybuffer = window->get_graphics_output()->make_texture_buffer("My Buffer", 512, 512);
    mytexture = mybuffer->get_texture();
    mybuffer->set_sort(-100);
    mycamera = new Camera("my camera");
    mycameraNP = window->get_render().attach_new_node(mycamera);
    myscene = NodePath("My Scene");
    mycamera->set_scene(myscene);

    // Load the environment model
    NodePath environ = window->load_model(framework.get_models(), "models/environment");
    environ.reparent_to(myscene);
    environ.set_scale(0.25 , 0.25, 0.25);
    environ.set_pos(-8, 42, 0);
 
    // Load our panda
    NodePath pandaActor = window->load_model(framework.get_models(), "panda-model");
    pandaActor.set_scale(0.005);
    pandaActor.reparent_to(window->get_render());
 
    // Add our task do the main loop, then rest in peace.
    taskMgr->add(new GenericAsyncTask("Spins the camera", &SpinCameraTask, (void*) NULL));
    framework.main_loop();
    framework.close_framework();
    return (0);

Here is my code which is based on the first tutorial.
I tried to make the RTT using some python script to see how it was made in python but it doesn’t work. If someone has an idea it would be great.

Thanks

Zwart

In what way does this code fail?

David

Well I enabled the show-buffers #t but I have nothing else than my main window when I run my program.
I thought, I would, at least get another window like in the samples which would display my scene.
I may have made something wrong but I can’t find any examples of RTT in C++.

If you have any clues or ideas.

Thanks

Zwart

The show-buffers config variable is implemented in Python, so it’s not surprising that nothing will happen when you set it for a C++ program.

In order to test whether your offscreen buffer works, you will have to apply mytexture to a card, and parent that card into your scene, for instance to render2d. This is basically what the show-buffers implementation would have done anyway.

David

Ok thanks I’ll try that

Ok I’ve found my problem.
There were nothing rendererd in my buffer because I forgot to add this :

DisplayRegion *region = mybuffer->make_display_region();
region->set_camera(mycameraNP);
region->set_active(true);

and the card works great thanks for the help.