I’m having some problems using RenderTexture in the editor and on the device (ios). I am trying to get a screenshot from only a camera. In the editor, the image gets messed up and on the device i get a black texture and this error:
OpenGLES error 0x0502 in /Users/…/GlesHelper.mm:262
Here is the code:
yield return new WaitForEndOfFrame(); // this also captures gui, remove if you don't wanna capture gui
RenderTexture rt = new RenderTexture(Screen.width, Screen.height , 24 , RenderTextureFormat.ARGB32);
rt.useMipMap = false;
rt.antiAliasing =1;
RenderTexture.active = rt;
Camera.main.targetTexture = rt;
Texture2D shot = new Texture2D(Screen.width,Screen.height,TextureFormat.ARGB32,false);
Camera.main.Render();
shot.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0,false);
shot.Apply();
Camera.main.targetTexture = null;
RenderTexture.active = null;
Destroy(rt);
GameObject.Find("PlaneTest").renderer.material.mainTexture = shot;
The code is called on a press event.
What am i doing wrong?