Proper Use of TextureStage::set_color()?

I’ve been trying to change the colour of a multitexture on a model during runtime by calling the set_color method on the stage by assigning a button to get colour values to set. Example:

void CharacterGen::enter() {
  layer1 = new TextureStage("layer1");

void CharacterGen::make_ui_elements() {
  apply_button = new PGButton("ApplyButton");

  apply_np = m_a->window->get_aspect_2d().attach_new_node(apply_button);
  apply_np.set_pos(0, 0, -0.3);

                            "button press",

void CharacterGen::set_model() {
  player_char = m_a->window->load_model(

  tex1 = TexturePool::get_global_ptr()->load_texture("../media/textures/cookie_cutter.png", 0, false);

  player_char.set_texture(layer1, tex1);


void CharacterGen::apply_color(const Event *e, void* data) {
  CharacterGen* chargen=(CharacterGen*) data;

                               chargen->slider1->get_value() / 255,
                               chargen->slider2->get_value() / 255,
                               chargen->slider3->get_value() / 255,
//where layer1 is of type TextureStage*, sliders PGSliderBar* etc

I removed some code because I thought it was unrelated, but essentially I call that apply_color() function after the model is made and the TextureStage/Texture is applied with a button. However, I noticed that the colour does not change! It stays black or whatever I initialise it at. Further, if I add some code to apply_color() and tell it to redo “player_char.set_texture(layer1, tex1);”, it works! Buuuut I notice that for every new colour input to the TextureStage that it leaks memory for some reason.

I’m not sure if I’m trying to use it in the wrong way, but the manual suggests that it should work (though doesn’t exactly specify if it works at runtime or not). Am I doing something wrong or is this a bug?

Hi, welcome to the forums! :slight_smile:

It should work. You should be able to change the color on an active texture stage without needing to do anything else. A quick test on my end confirms this.

Which version of Panda are you using? Are you perchance enabling the shader generator using set_shader_auto()? The shader generator previously was unable to deal with runtime changes of some settings, but this issue is no longer present in recent development builds.

I’m using the latest stable (1.9.4) and yeah, I had set_shader_auto() somewhere. I never would have figured out that had something to do with it. Thanks for the speedy reply!

Great. I would encourage you to try out development builds of Panda3D, which have this issue resolved.