@@ -236,12 +236,19 @@ public void Update(float deltaSeconds)
236236 private void SetPerFrameImGuiData ( float deltaSeconds )
237237 {
238238 var io = ImGuiNET . ImGui . GetIO ( ) ;
239+ var size = _view . Size ;
240+ var framebufferSize = _view . FramebufferSize ;
241+
242+ // Update here since Resize isn't raised on all platforms
243+ _windowWidth = size . X ;
244+ _windowHeight = size . Y ;
245+
239246 io . DisplaySize = new Vector2 ( _windowWidth , _windowHeight ) ;
240247
241248 if ( _windowWidth > 0 && _windowHeight > 0 )
242249 {
243- io . DisplayFramebufferScale = new Vector2 ( _view . FramebufferSize . X / _windowWidth ,
244- _view . FramebufferSize . Y / _windowHeight ) ;
250+ io . DisplayFramebufferScale = new Vector2 ( ( float ) framebufferSize . X / _windowWidth ,
251+ ( float ) framebufferSize . Y / _windowHeight ) ;
245252 }
246253
247254 io . DeltaTime = deltaSeconds ; // DeltaTime is in seconds.
@@ -427,6 +434,9 @@ private unsafe void SetupRenderState(ImDrawDataPtr drawDataPtr, int framebufferW
427434 _gl . PolygonMode ( GLEnum . FrontAndBack , GLEnum . Fill ) ;
428435#endif
429436
437+ // Setup viewport, orthographic projection matrix
438+ _gl . Viewport ( 0 , 0 , ( uint ) framebufferWidth , ( uint ) framebufferHeight ) ;
439+
430440 float L = drawDataPtr . DisplayPos . X ;
431441 float R = drawDataPtr . DisplayPos . X + drawDataPtr . DisplaySize . X ;
432442 float T = drawDataPtr . DisplayPos . Y ;
@@ -488,6 +498,8 @@ private unsafe void RenderImDrawData(ImDrawDataPtr drawDataPtr)
488498 _gl . GetInteger ( GLEnum . PolygonMode , lastPolygonMode ) ;
489499#endif
490500
501+ Span < int > lastViewport = stackalloc int [ 4 ] ;
502+ _gl . GetInteger ( GLEnum . Viewport , lastViewport ) ;
491503 Span < int > lastScissorBox = stackalloc int [ 4 ] ;
492504 _gl . GetInteger ( GLEnum . ScissorBox , lastScissorBox ) ;
493505
@@ -637,6 +649,7 @@ private unsafe void RenderImDrawData(ImDrawDataPtr drawDataPtr)
637649 _gl . PolygonMode ( GLEnum . FrontAndBack , ( GLEnum ) lastPolygonMode [ 0 ] ) ;
638650#endif
639651
652+ _gl . Viewport ( lastViewport [ 0 ] , lastViewport [ 1 ] , ( uint ) lastViewport [ 2 ] , ( uint ) lastViewport [ 3 ] ) ;
640653 _gl . Scissor ( lastScissorBox [ 0 ] , lastScissorBox [ 1 ] , ( uint ) lastScissorBox [ 2 ] , ( uint ) lastScissorBox [ 3 ] ) ;
641654 }
642655
0 commit comments