Render camera in EditorWindow

I’m making an Editor extension that needs its own rendering window, usable in both unity free and pro.

I have tried both Handles.DrawCamera and Camera.Render
But both produce the result like in the picture below(the depth is wrong).
However Camera.Render works as expected in the Game view window.

Anyone that has been doing something similiar?

The GUI code looks like this

void OnGUI()
    {
        GUILayout.Label("hello world");
        if (cam != null)
        {
            float height = this.position.height;
            cam.pixelRect = new Rect(10, 0, this.position.width - 25, height - 50);
            Handles.DrawCamera(cam.pixelRect, cam, DrawCameraMode.Normal); 
        }
    }

Maybe using DrawCameraMode.Textured helps, as suggested here: Rendering a camera to an Editor Window - Unity Answers