How to set a Material for a BorderImage?

I found that BorderImage has a member function SetMaterial
void SetMaterial (Material *material)
//Set material for custom rendering.

I got an incorrect display (probably a small part of the texture) when i had set a material for it.

the material is a video frame (yuv420p piexl format) refferd to Theora video playback (Theora video playback)

the follow is my code:
1 create a BorderImage

        UIElement* root = GetSubsystem<UI>()->GetRoot();
        BorderImage* pImgFrame=root->CreateChild<BorderImage>();

2 set a material

It is ok to assign the outputMaterial to a cube or a plane.

What is your use case for changing the material?
If you’re just trying to display an image, this may help:

            // Set up a UI Element to display the SplashScreen Image
            ResourceCache* cache = GetSubsystem<ResourceCache>();
            UI* ui = GetSubsystem<UI>();
            splashUI = new BorderImage(context_);
            Texture2D* texture = cache->GetResource<Texture2D>("Textures/LogoLarge.png");
            splashUI->SetTexture(texture); // Set texture
            splashUI->SetSize(texture->GetWidth(), texture->GetHeight());
            splashUI->SetAlignment(HA_CENTER, VA_CENTER);

Not the best example in the world, granted…

1 Like

i want to display a web camera in a borderimage!

the outputMaterial have convert a yuv420p to rgb32 format!

Call SetFullImageRect() on your borderimage. But if you need a 2d render surface just use a sprite2d.


Or BorderImage::SetImageRect() with the width and height of the video texture:

video_view_->SetImageRect(IntRect(0, 0, video_width, video_height));
1 Like

Texture* pTexture= video_box_->GetTexture();

i got a nullprt for GetTexture when i set the outputMaterial.

so the SetFullImageRect or SetImageRect do not work!

thanks !
it is ok

    Texture*  pTexture=outputMaterial->GetTexture(TU_DIFFUSE);

I was just about to mention that you explicitly need to set the BorderImage texture even if the material already has one, since BorderImage needs a valid texture to calculate UV when you use Set****Rect() methods.