using UnityEngine;
using System.Collections;
public class PoplCameraTrns : MonoBehaviour
{
public Material mat;
private RenderTexture poplTexture = null;
void Start ()
{
Camera cam = GetComponent<Camera> ();
poplTexture = new RenderTexture (GInterfaceSettings.getI.pplCamSize, GInterfaceSettings.getI.pplCamSize, 32, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
cam.targetTexture = poplTexture;
}
void OnGUI ()
{
if (poplTexture != null) {
//Draw texture on GUI
int x = Screen.width - GInterfaceSettings.getI.pplCamGUISize - 16;
int y = Screen.height - GInterfaceSettings.getI.pplCamGUISize - 16;
GUI.DrawTexture (new Rect (x, y, GInterfaceSettings.getI.pplCamGUISize, GInterfaceSettings.getI.pplCamGUISize), poplTexture, ScaleMode.ScaleAndCrop, true);
GUI.DrawTexture (new Rect (x, y, GInterfaceSettings.getI.pplCamGUISize, GInterfaceSettings.getI.pplCamGUISize), GameInterface.getI.PoplCameraRamka, ScaleMode.ScaleAndCrop, true);
}
}
void OnPostRender ()
{
if (poplTexture != null) {
Vector2 v1 = new Vector2 (0f, 0f);
Vector2 v2 = new Vector2 (poplTexture.width, 0f);
Vector2 v3 = new Vector2 (poplTexture.width, poplTexture.height);
Vector2 v4 = new Vector2 (0f, poplTexture.height);
GL.PushMatrix ();
GL.LoadPixelMatrix ();
mat.SetPass (0);
GL.Begin (GL.QUADS);
GL.Color (new Color (1f, 1f, 1f, 1f));
GL.TexCoord (new Vector2 (0, 0));
GL.Vertex (v1);
GL.TexCoord (new Vector2 (1f, 0));
GL.Vertex (v2);
GL.TexCoord (new Vector2 (1f, 1f));
GL.Vertex (v3);
GL.TexCoord (new Vector2 (0, 1f));
GL.Vertex (v4);
GL.End ();
GL.PopMatrix ();
}
}
void OnDestroy ()
{
if (poplTexture != null)
Destroy (poplTexture);
}
}