Scaling a renderTexture?

I’m trying to rescale a renderTexture so it fits the right half of the screen using this script:

var textureToDisplay : Texture;

function Start () {
	textureToDisplay = RenderTexture(Screen.width/2,Screen.height,0);
	camera.targetTexture = textureToDisplay;
}

function OnGUI () {
	GUI.Label (Rect (Screen.width/2, 0, textureToDisplay.width, textureToDisplay.height), textureToDisplay);
}

But I’m getting this error:

Error assigning 2D rectangle texture to 2D texture property '_MainTex': Dimensions must match
UnityEngine.GUI:Label(Rect, Texture)

Any suggestions on how to get this to work?

I don’t think you can make renderTextures like that unless it’s a power of two (at least I always get the “dimensions must match” error with non-power-of-two textures).

–Eric

Thanks Eric, that’s what I was afraid of. This is related to the “stop motion” effect I’m trying to achieve(and posted in another thread). Unfortunately the only what I’ve found to make a camera display at a slower FPS is through a renderTexture, and renderTextures won’t scale properly for my GUI… unless some particularly bright Unity guru has a better idea :wink:

You could disable the camera until a certain time has passed, then enable it, Clear(), Render(), and disable again. But would this clear the screen when the camera was disabled?

Yeah, that’s what happens. This isn’t a critical issue, so I may dump this idea if I can’t find another way. But it sure would add to the realism if I can make it work…

You could create a mesh that is a power of 2 size, draw the texture on the mesh so that the surface is painted with the texture and move the mesh until it fills enough of the screen area that you are satisfied. Obviously won’t be part of the GUI, but if its just to display on, then this might work. Never tried this, just guessing.