Recent

Author Topic: Redraw an OpenGL canvas not from main thread.  (Read 4511 times)

Coxy

  • New Member
  • *
  • Posts: 32
Redraw an OpenGL canvas not from main thread.
« on: May 20, 2020, 10:52:38 am »
First off this is being run in a MS Windows environment.

Is it possible to redraw an OpenGL canvas from a thread that is not the main one.

If I have timer running not in the main thread and BGLVirtualScreen1.DoOnPaint is called I get exception 'OpenGL context has not been created yet'.

All examples I've seen run on main thread using event loop, either a timer or OnIdleEvent, which is fine for screen savers and simple games, but event loop is no good if consistent time intervals are required i.e. for smooth animation.

OnIdleEvent seems to be locked to refresh rate of screen, mine being 60Hz, and is not user definable. As an aside you can get amazing frame rates by running your application via remote desktop on your local network, I've seen 1000+.

Anyway if anyone can point me in the right direction or let me know it's not possible using this interface to OpenGL I'ed be extremely grateful.


circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: Redraw an OpenGL canvas not from main thread.
« Reply #1 on: July 04, 2020, 11:24:34 pm »
Hii Coxy

You can use the property BGLVirtualScreen1.RedrawOnIdle to make it redraw itself at the highest possible frame rate.

The OnElapse event tells you how much time has elapsed. You can use SmoothedElapse property to get an estimation for very small elapse values.

From there you can compute either the exact positions using a floating time value or determining how many grains of time to advance.

Regards
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018