dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
753 stars 300 forks source link

WPF: animation freezes (see Teapot sample) if mouse is moving over window #144

Open alariq opened 6 years ago

alariq commented 6 years ago

Not sure if SharpGL related, but this happens. Any way to fix this?

libritium commented 5 years ago

Hi! The problem is that the priority of the Dispatcher that's responsible for the drawing is not set in the constructor of the control under 'timer = new DispatcherTimer()' in OpenGLControl.xaml.cs, The default constructor put the DispatcherPriority.Background in the priority which is lower than DispatcherPriority.Input (mouse movement). Simply change the initialization of the DispatcherTimer timer in the constructor of the control and put the priority manually. (There's a constructor that get a priority) rebuild and use the rebuilt version.

alariq commented 5 years ago

Not relevant anymore but thanks anyway, maybe will be helpful for others

JamesLear92 commented 5 years ago

I agree that the issue is the dispatchtimer as Librium said, but if I'm using this library from nuget, and not from this source, I don't have access to change the dispatch timer.

Is it possible instead to use System.Timers.Timer, and then use: Application.Current.Dispatcher.BeginInvoke( this._dispatcherPriority, new Action(() => { put rendering action here }));

Then expose the _dispatcherPriority field via a public property of the usercontrol?

DarkDestry commented 4 years ago

In case anyone has this issue still and doesnt want to rebuild the source, you can overwrite the private field using reflection

var prop = openGLControl.GetType().GetField("timer",
    System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
prop.SetValue(openGLControl, new DispatcherTimer(DispatcherPriority.Render));