- Home /
Drawing to render texture in EditorWindow
Hello.
I'm trying to make visual editor for my GLUe Framework (https://www.assetstore.unity3d.com/#/content/6265), so i need to display some meshes via GL and Graphics in the editor window.
When i using:
public void OnGUI()
{
GL.PushMatrix();
GL.LoadPixelMatrix(0, Screen.width, 0, Screen.height);
// Draw my stuff
GL.PopMatrix();
}
everything works fine, but when i add render texture:
public void OnGUI()
{
GL.PushMatrix();
GL.LoadPixelMatrix(0, Screen.width, 0, Screen.height);
// Draw my stuff
GL.PushMatrix();
RenderTexture rt = RenderTexture.active;
RenderTexture.active = mytexture;
GL.LoadPixelMatrix(0, mytexture.width, 0, mytexture.height);
// Draw stuff to render texture
RenderTexture.active = rt;
GL.PopMatrix();
// Assign render texture to material
// Assign material to polygon and draw it
GL.PopMatrix();
}
RT contents stretches not like other stuff. It look like GL matrix is not restored properly after last Pop. Has anyone encountered such thing before?
PS: In run-time both things work fine (although, i use OnPostRender() instead of OnGUI() ).
UPD: The trouble is exactly with render texture - when i remove "RenderTexture.active = mytexture;", the rest of form is drawn without stretching.
Answer by etiainen · Jan 22, 2013 at 02:55 AM
Found the solution: Just add GL.Viewport(0, Screen.width, 0, Screen.height) or GL.Viewport(0, mytexture.width, 0, mytexture.height) after each GL.LoadPixelMatrix, and everything fixes.
Your answer
![](https://koobas.hobune.stream/wayback/20220613091323im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I draw curves in a custom editor window? 1 Answer
GL.Quads not correctly displaying color. It's all black 0 Answers
Rendering with GL.Begin to a RenderTexture does not update it continuously (2019.2) 0 Answers
Rendering a Camera in an Editor window displays its RenderTexture automatically? 1 Answer
OnInspectorGUI Custom Drawing? 1 Answer