Posted Sunday, 10 July, 2011 - 13:05 by the Fiddler
Yes, this is possible.
In v1.0, input is always handled in the main thread. You can only move your OpenGL calls to a different thread, by calling window.Context.MakeCurrent(null) on the main thread and window.MakeCurrent() on the new thread (where window can be either a GameWindow or a GLControl). Check out the "GameWindow Threaded" sample in the example browser.
In v1.1, you can poll input from any thread using the thread-safe APIs in OpenTK.Input.
Posted Sunday, 10 July, 2011 - 14:39 by the Fiddler
Check out the relevant documentation. The "GameWindow States" sample also uses polled input.
The concept is very simple:
poll the device you wish, from any thread
compare the results with the previous ones to see if anything has changed
store the results and wait for next frame
Mouse input, for instance:
usingOpenTK.Input;
MouseState current, previous;
void UpdateMouse(){
current = Mouse.GetState();
if(current != previous){// Mouse state has changedint xdelta = current.X - previous.X;
int ydelta = current.Y - previous.Y;
int zdelta = current.Wheel - previous.Wheel;
}
previous = current;
}
Polled input can also handle multiple mice, keyboards, etc: just use GetState(int) to poll a specific device and check the "IsConnected" property before using it.
Comments
Re: Processing Inputs in one thread and doing rendering in ...
Yes, this is possible.
In v1.0, input is always handled in the main thread. You can only move your OpenGL calls to a different thread, by calling
window.Context.MakeCurrent(null)on the main thread andwindow.MakeCurrent()on the new thread (where window can be either a GameWindow or a GLControl). Check out the "GameWindow Threaded" sample in the example browser.In v1.1, you can poll input from any thread using the thread-safe APIs in
OpenTK.Input.Re: Processing Inputs in one thread and doing rendering in ...
Is there example of input polling somewhere?
Re: Processing Inputs in one thread and doing rendering in ...
Check out the relevant documentation. The "GameWindow States" sample also uses polled input.
The concept is very simple:
Mouse input, for instance:
Polled input can also handle multiple mice, keyboards, etc: just use
GetState(int)to poll a specific device and check the "IsConnected" property before using it.