如何在OpenTK中更改视口分辨率 [英] How to change the viewport resolution in OpenTK

查看:222
本文介绍了如何在OpenTK中更改视口分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenTk GameWindow.我一直在向项目添加图形设置.但是我不知道如何在运行时正确更改分辨率或进入或退出全屏模式.

I am using the OpenTk GameWindow. I have been adding graphics settings to my project. But I cannot figure out how to correctly change the resolution or go in or out of fullscreen mode in runtime.

有人可以请您解释在运行游戏时更改分辨率和/或全屏状态的正确步骤.

Can someone please explain the correct procedure to changing the resolution and/or fullscreen state in while the game is running.

使用WindowState = WindowState.Fullscreen;WindowState = WindowState.Fullscreen;可以工作,但是它们修改了查看区域并设置了GL.Viewport不能修复它.

Using WindowState = WindowState.Fullscreen; and WindowState = WindowState.Fullscreen; work, but they modify the viewing area and setting GL.Viewport doesn't fix it.

我当前正在使用DisplayDevice.GetDisplay(DisplayIndex.Default).ChangeResolution

推荐答案

如果您未处于全屏模式,则可以通过简单地调用GameWindow对象上的Size属性来调整窗口的大小.您已经了解WindowState属性.

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.

您需要做的主要事情是覆盖GameWindow类中的OnResize方法.调整游戏窗口大小(包括将其设置为全屏模式)时,将自动调用此方法.从那里,您可以重新初始化视口.

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.

例如,在我当前正在测试的项目中,每当我调整窗口大小或移入/移出全屏模式时,以下代码都会正确调整视图端口的大小.尽管我在移至全屏模式时不使用分辨率切换,但我想它也可以很好地工作.在下面的示例中,yoursizehere为640x640,并使用GL.Ortho方法缩放以适合GameWindow.ClientSize. (我是OpenTK(和OpenGL)的新手,所以我仍然有很多东西要学习,但是下面的内容对我有用)

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);
}

上面的示例是针对2D视图端口的,这是我目前正在尝试的端口...在二维方面难以掌握OpenGL概念,更不用说三个了!

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!

希望这会有所帮助

这篇关于如何在OpenTK中更改视口分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆