Hot Door CORE Forum

Full Version: OpenGL within CustomWidget.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. I have a question regarding custom widget. Specifically, regarding rendering with OpenGL into it. I am getting a platform widget and use it to initialize context, to render into it later. Then I set up timer to render animation with 30 fps. And this is where my question rises. While I render at 30 fps, real fps is somewhere around 10, resulting in laggy animation. However, if I move my mouse around custom widget frame during animation, it gives me 30 fps. I can only assume that while I render at 30 fps, system window refreshes at much slower rate. And that moving mouse into widget triggers some callbacks that force window to refresh\redraw. Is there some way to force this system callback after my rendering function? I have tried redraw() and update() to no result, so I assume they do not trigger system refresh.
(09-01-2015, 02:48 AM)Gaxx Wrote: [ -> ]While I render at 30 fps, real fps is somewhere around 10, resulting in laggy animation. However, if I move my mouse around custom widget frame during animation, it gives me 30 fps. I can only assume that while I render at 30 fps, system window refreshes at much slower rate. And that moving mouse into widget triggers some callbacks that force window to refresh\redraw.

Interesting. We certainly don't do anything to limit the frame rate of widgets, so it must be the OS giving a lower priority to widgets that the user is not interacting with.

(09-01-2015, 02:48 AM)Gaxx Wrote: [ -> ]Is there some way to force this system callback after my rendering function? I have tried redraw() and update() to no result, so I assume they do not trigger system refresh.

On Mac, calling Widget::update() and CustomWidget::redraw() both result in our using the [NSView setNeedsDisplay:] method. This essentially flags the underlying NSView object as needing to be drawn again, which happens at the convenience of the OS. I believe you can force an NSView object to draw immediately by using the [NSView display] method, but you should double-check.

On Windows, calling Widget::update() and CustomWidget::redraw() both result in our using the InvalidateRgn() function. Again, this essentially flags the underlying HWND object as needing to be drawn, which happens at the convenience of the OS. I believe you can force a HWND object to draw immediately by using the RedrawWindow() method, but you should double-check.

Off the top of my head, these are some ways you can force the widget to draw at your behest. Use the Widget::platformWidget() method to get the underlying NSView or HWND, and try forcing it to redraw to perhaps achieve 30fps.