Archive 17/01/2023.

How to set a Material for a BorderImage?

majhong

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>();
        pImgFrame->SetPosition(0,0);
        pImgFrame->SetSize(640,360);

2 set a material
pImgFrame->SetMaterial(outputMaterial);

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

Leith

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_);
            splashUI->SetName("Splash");
            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);
            ui->GetRoot()->AddChild(splashUI);

Not the best example in the world, granted…

majhong

i want to display a web camera in a borderimage!

the outputMaterial have convert a yuv420p to rgb32 format!

Dave82

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

Pencheff

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

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

video_box_->SetMaterial(outputMaterial);
Texture* pTexture= video_box_->GetTexture();

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

so the SetFullImageRect or SetImageRect do not work!

majhong

thanks !
it is ok

    video_box_->SetMaterial(outputMaterial);
    Texture*  pTexture=outputMaterial->GetTexture(TU_DIFFUSE);
    video_box_->SetTexture(pTexture);
    video_box_->SetFullImageRect();
Pencheff

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.