If you're not in full screen mode, you can resize the window by simply calling the Size
property on the GameWindow
object. You already know about the WindowState
propery.
The main thing you need to do is override the OnResize
method in your GameWindow
class. This is automatically called when your game window is resized, including setting it into full screen mode. From there, you can re-initialize your viewport.
For example, in the project I'm currently testing with, the following code correctly resizes the view port whenever I resize the window or move in/out of full screen mode. Although I don't make use of resolution switching when moving to full screen mode, I would imagine it would work perfectly well for that too. In the below example yoursizehere
is 640x640 and is scaled using the GL.Ortho method to fit the GameWindow.ClientSize
. (I'm a novice at OpenTK (and OpenGL for that matter) so I still have a ton to learn myself - but the below works for me)
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
GL.Viewport(this.ClientRectangle);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0, yoursizehere.Width, yoursizehere.Height, 0, -1, 0);
}
The above example is for a 2D view port which is what I'm currently experimenting in... having enough troubles getting to grasp with OpenGL concepts in two dimensions let alone three!
Hope this helps