Render into ImGui viewport

I am trying to render V3d_View into an ImGui viewport:

m_FBO = Handle(OpenGl_FrameBuffer)::DownCast(myView->View()->FBOCreate(theWidth, theHeight));
m_FBO->ColorTexture()->Sampler()->Parameters()->SetFilter(Graphic3d_TOTF_BILINEAR);
myView->View()->SetFBO(m_FBO);

It successfully renders the view into a view port, however, the grid marker position doesn't match my mouse cursor position, as shown in Fig1.

The marker position is always on the right side of my cursor, and the more left I move my mouse, the larger the gap is.

So initially, I thought this had to do with my UpdateMousePosition callback. The position it takes in is the GLFW mouse position, hence it's relative to the whole window rather than that viewport. So I did some recalculation and passed in the correct position, now I get the opposite, as shown in Fig2.

The marker position is always on the left side of my cursor, and the more right I move my mouse, the larger the gap is.

Am I doing something wrong here?

Attachments: 
gkv311 n's picture

Assigned FBO will be used for rendering, but methods like AIS_InteractiveContext::MoveTo() would expect mouse coordinates within Aspect_Window dimensions. Make sure that your window class implementation returns same dimensions as your FBO object.