0

我正在使用 OpenTk GameWindow。我一直在为我的项目添加图形设置。但我无法弄清楚如何在运行时正确更改分辨率或进入或退出全屏模式。

有人可以解释在游戏运行时更改分辨率和/或全屏状态的正确程序吗?

使用WindowState = WindowState.Fullscreen;WindowState = WindowState.Fullscreen;工作,但他们修改查看区域并设置 GL.Viewport 并不能解决它。

我目前正在更改显示器分辨率DisplayDevice.GetDisplay(DisplayIndex.Default).ChangeResolution

4

2 回答 2

3

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

于 2011-05-30T20:58:22.503 回答
0

查看 GameWindow 构造函数。他们中的大多数以宽度和高度作为他们的第一个参数。全屏是通过 GameWindowFlags 参数设置的。

于 2011-05-02T19:01:04.790 回答