Drawing to render texture in EditorWindow

Hello.

I’m trying to make visual editor for my GLUe Framework (Unity Asset Store - The Best Assets for Game Making),
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.

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.