Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Why do GL calls draw on the whole window when my IMGUIContainer is inside a TwoPaneSplitView?

Discussion in 'UI Toolkit' started by vicenziano, Apr 6, 2023.

  1. vicenziano

    vicenziano

    Joined:
    Sep 11, 2018
    Posts:
    4
    Hello!

    I'm trying to draw a rectangle with GL inside of a TwoPanelSplitView, but my window ends up completely black when I use GL.Clear, rather than just the area inside the panel. What am I doing wrong?

    Thanks!

    Code for reference:

    Code (CSharp):
    1.         private void HandleDrawing()
    2.         {
    3.             if (Event.current.type is EventType.Repaint)
    4.             {
    5.                 _width = position.width;
    6.                 _height = position.height;
    7.                 _shader = Shader.Find("Hidden/Internal-Colored");
    8.      
    9.                 _mat = new Material(_shader)
    10.                 {
    11.                     hideFlags = HideFlags.HideAndDontSave
    12.                 };
    13.  
    14.                 _mat.SetPass(0);
    15.                 GL.PushMatrix();
    16.      
    17.                 GL.Clear(true, true, Color.black);
    18.  
    19.                 GL.PopMatrix();
    20.                 Handles.EndGUI();
    21.             }
    22.         }
    23.  
    24.         private void Update()
    25.         {
    26.             Repaint();
    27.         }
    28.  
    29.         public void CreateGUI()
    30.         {
    31.             // Each editor window contains a root VisualElement object
    32.             VisualElement root = rootVisualElement;
    33.          
    34.             // Separate the window into variables and plot
    35.             var splitView = new TwoPaneSplitView(0, 200, TwoPaneSplitViewOrientation.Horizontal);
    36.             splitView.usageHints = UsageHints.GroupTransform;
    37.             root.Add(splitView);
    38.          
    39.             // Panels from the splitview
    40.             var leftPane = new VisualElement();
    41.             splitView.Add(leftPane);
    42.             var rightPane = new VisualElement();
    43.             rightPane.usageHints = UsageHints.GroupTransform;
    44.             splitView.Add(rightPane);
    45.          
    46.             // Add a GameObject to expose possible variables
    47.             var gameObjectField = new ObjectField("Object to analyze");
    48.             leftPane.Add(gameObjectField);
    49.  
    50.             var glContent = new IMGUIContainer(HandleDrawing);
    51.             glContent.usageHints = UsageHints.DynamicColor;
    52.          
    53.             rightPane.Add(glContent);
    54.         }
     
    Last edited: Apr 6, 2023
  2. vicenziano

    vicenziano

    Joined:
    Sep 11, 2018
    Posts:
    4
    Nevermind, I could solve this by drawing a rectangle with Vertexes instead of Using GL.Clear :)