- Home /
Is it possible to render a GUI.Label into a Texture ?
Hi
Here is the thing, I love to map word-wrapped texts on planes. It's what i do. Anytime I can do it, here I am mapping word-wrapped texts over all the planes I can find. Guess what, sometimes I even do it on cubes.
And I'd love to know how to do it with Unity.
I've been kindly advised to use a GUI.Label. Which is great because it seems to be the best way to simply format dynamic texts.
Now it's easy to capture a GUI.Text or a GUI.Texture into the Target Texture of my Camera but I have no success with a GUI.Label. Do I have to assign it to a GUI.Layer ? I couldn't find how.
thanks for your help.
Here is ho I'm creating my GUI.label
using UnityEngine; using System.Collections;
public class CreateGuiLabel : MonoBehaviour { private string myString; void Start () {
myString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
}
public GUISkin gSkin;
void OnGUI ()
{
if (gSkin)
GUI.skin = gSkin;
else
Debug.Log ("ConfigureMenuGUI : GUI skin object missing!");
GUI.Label (new Rect (0, 0, 200, 400), myString, "Content Text");
}
}
I have tried it by all means, I published something in Peinados con trenzas and it has been impossible.
Answer by jonas-echterhoff · Jun 07, 2010 at 11:14 AM
It may require some tweaking to get right, but you should be able to get this to work, by setting RenderTexture.active to your target texture in your OnGUI call (and setting it back later).
Hi, I'm starting to have my GUI.label or part of it into a texture. $$anonymous$$y results are really unreliable though. For example if I do set the RenderTexture.active to my targetTexture on the first frame of my OnGUI call I end up having weird bits of unity interface in my texture. I guess this is beco$$anonymous$$g overcomplicated. Is there any plug-in of some sort that would give a little more options to the 3DText ? :(
I just found this on the forum - a sweet and simple little script that word-wrap 3Dtext: http://forum.unity3d.com/viewtopic.php?p=330943#330943
Are you restoring the RenderTexture to it's previous value after your GUI.Label call?
yes, almost there. I'm really trying to figure out the proper work flow. Here is what I do : First I create a 512x512 renderTexture to which I give the beautiful name of "capturedGUI" then in the onGUI I store RenderTexture.active in a temp RenderTexture called "oldRndT" -next line- RenderTexture.active = capturedGUI; -next line- I create my GUI.Label and finally RenderTexture.active = "oldRndT". So I do capture the GUI.label but the problem is that the position and aspect ratio of the GUI.Label into my capturedGUI texture is based on my Game Window size and aspect ratio.
I don't know how to create my GUI.Label based on the capturedGUI RenderTexture size and aspect ratio. I even tried with a second camera which had a normalized viewport rect of 512x512. I feel like these guys who are lost in a snow storm in the mountains for days and who are about to give up just a few meters from a shelter they can't see... mm.. ok .. maybe I don't ...