How can I show a Texture2D image in IconComponent() using setImageTexture()?

how can I show a Texture2D image in IconComponent() using setImageTexture()?

I want to use this code …


1 Like

I did it, but nothing changed.

Container window = new Container();

ViewPort vpt = GMath.renTex("RenderToTexture", 640, 640, 45, 1, 1000, 1);
        ViewPort vp = renderManager.createPreView("RenderToTexture", vpt.getCamera());

        vp.setClearFlags(true, true, true);
        Spatial renderToTexScene;

        //Move and rotate the camera that will render to the texture
        vp.getCamera().setLocation(new Vector3f(0, 100, 10));
        vp.getCamera().lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

        //Get the texture we are rendering to
        Texture2D renderTexture = (Texture2D) vp.getOutputFrameBuffer().getColorBuffer().getTexture();

IconComponent ico = new IconComponent("Interface/hud/cam_preview.png");

So it’s still just showing the cam_preview image?

Not sure why that would be. The code is pretty straight forward:

1 Like

that’s right , but I solved that.

I have some other problems:
1-back ground image not scaling by container resize using setpreferredWidth().

2- init an IconComponent() without a preview texture , I mean just using setImageTexture() … .

That’s because you are using IconComponent which forces its size to stay the same.

Don’t use IconComponent if you don’t want to display icons.

Use QuadBackgroundComponent if you want it to resize with the container and to have a texture on init.

1 Like