Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Created July 12, 2013 13:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngryAnt/5984299 to your computer and use it in GitHub Desktop.
Save AngryAnt/5984299 to your computer and use it in GitHub Desktop.
Example code for "OnRenderTextureGUI" blog post on AngryAnt.com
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