Created
July 12, 2013 13:04
-
-
Save AngryAnt/5984299 to your computer and use it in GitHub Desktop.
Example code for "OnRenderTextureGUI" blog post on AngryAnt.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void OnGUI () | |
{ | |
BeginRenderTextureGUI (m_TargetTexture); | |
GUILayout.Box ("This box goes on a render texture!"); | |
EndRenderTextureGUI (); | |
} | |
RenderTexture m_PreviousActiveTexture = null; | |
protected void BeginRenderTextureGUI (RenderTexture targetTexture) | |
{ | |
if (Event.current.type == EventType.Repaint) | |
{ | |
m_PreviousActiveTexture = RenderTexture.active; | |
if (targetTexture != null) | |
{ | |
RenderTexture.active = targetTexture; | |
GL.Clear (false, true, new Color (0.0f, 0.0f, 0.0f, 0.0f)); | |
} | |
} | |
} | |
protected void EndRenderTextureGUI () | |
{ | |
if (Event.current.type == EventType.Repaint) | |
{ | |
RenderTexture.active = m_PreviousActiveTexture; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment