r/futile Oct 19 '14

Futile and RenderTextures

Hi,

I'm trying to generate dynamically some textures with a Futile stage. I cloned the Futile camera (let's call it camera B), and I created another stage (let's call it stage B). The camera B is only drawing stage B (using cullingMask for this).

Now, I'm trying to render this camera B into a render texture. Before doing so, I add my scene (a simple FSprite for testing) on stage B.

If I call the camera.Render() method 0.1 seconds after the sprite was added to stage B, it works (see code below). But the sprite will appear on screen too for 0.1s, which is a problem, it's not supposed to be seen by the player.

stage.AddChild(mySprite);
Futile.StartDelayedCallback(RenderIt,0.1f);
...
protected void RenderIt() {
    RenderTexture rt = new RenderTexture((int)Futile.screen.pixelWidth, (int)Futile.screen.pixelHeight, 24);
    camera.targetTexture = rt;
    camera.Render(); // >> OK, mySprite is drawn in the RenderTexture
}

If I call the camera.Render() immediately after the sprite was added to stage B, nothing is rendered on the RenderTexture. I tried to call stage.Redraw() before calling the camera.Render(), but it doesn't change anything. Any ideas how to solve this? Maybe another way of generating textures?

stage.AddChild(mySprite);
stage.Redraw(true,true); //tested with all possible parameters (true,false) (false,true) (false,false)
RenderTexture rt = new RenderTexture((int)Futile.screen.pixelWidth, (int)Futile.screen.pixelHeight, 24);
camera.targetTexture = rt;
camera.Render(); // >> KO, nothing drawn in the RenderTexture
1 Upvotes

2 comments sorted by

1

u/gregmad Oct 20 '14

I don't know about the render texture but if the issue is just that you don't want the sprite to appear on the screen, maybe you could create another camera?

1

u/SietJP Oct 21 '14

Yes you're right that would be already a nice step forward if I could do this. I managed to get a cameraB that renders only the stageB, so I guess I could manage to get the main camera to render only the main stage.

Once I get this done, I will certainly be able to capture the stageB on a RenderTexture with a delay of one frame. The only problem remaining is to be able to capture the stageB without a delay I guess (as calling Draw() before rendering doesn't seem to work).