Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将我的游戏窗口设置为全屏将使其扩展到桌面分辨率_C#_Opengl_Fullscreen_Opentk - Fatal编程技术网

C# 将我的游戏窗口设置为全屏将使其扩展到桌面分辨率

C# 将我的游戏窗口设置为全屏将使其扩展到桌面分辨率,c#,opengl,fullscreen,opentk,C#,Opengl,Fullscreen,Opentk,将我的GameWindow设置为全屏会使它变长,如何使用黑条将其设置为全屏而不丢失原始的窗口分辨率 这是我的代码: 使用系统; 使用System.Collections.Generic; 使用系统文本; 使用OpenTK; 使用OpenTK.Graphics; 使用OpenTK.Graphics.OpenGL; 使用OpenTK.Windowing.Common; 使用OpenTK.Windowing.GraphicsLibraryFramework; 使用OpenTK.Windowing.De

将我的GameWindow设置为全屏会使它变长,如何使用黑条将其设置为全屏而不丢失原始的窗口分辨率

这是我的代码:

使用系统;
使用System.Collections.Generic;
使用系统文本;
使用OpenTK;
使用OpenTK.Graphics;
使用OpenTK.Graphics.OpenGL;
使用OpenTK.Windowing.Common;
使用OpenTK.Windowing.GraphicsLibraryFramework;
使用OpenTK.Windowing.Desktop;
使用系统图;
名称空间在线游戏
{
公共类游戏:GameWindow
{
公共游戏(GameWindowsSettings GameWindowsSettings,NativeWindowsSettings NativeWindowsSettings)
:基本(游戏窗口设置、本地窗口设置)
{
WindowState=WindowState.全屏显示;
}
受保护的覆盖无效OnUpdate帧(FrameEventArgs e)
{
if(KeyboardState.IsKeyDown(Keys.Escape))
{
Close();
}
基础.更新帧(e);
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.ClearColor(颜色:矢车菊蓝);
这个。SwapBuffers();
}
}
}

使用
GL.Viewport
将视口矩形设置为窗口的子区域。“复制”操作如
GL.Clear
不受视口矩形的影响。因此,您还需要设置一个

您需要知道窗口的当前大小(
current\u w
current\u h
)和窗口的原始大小(
original\u w
original\u h
)。计算当前窗口的纵横比(
current\u aspect
)和原始窗口的纵横比(
original\u aspect
):

double current\u aspect=(双)current\u w/current\u h;
双重原始相位=(双重)原始相位w/原始相位h;
计算子区域并设置视口和剪刀矩形:

intw=(int)(当前方面*原始方面/当前方面);
int x=(当前w-w)/2;
GL.剪刀(x,0,w,该尺寸为Y);
总图视口(x,0,w,this.Size.Y);

用黑色清除整个窗口。然后限制视口矩形并启用剪刀测试。
注意:必须在
GL.clear
指令之前设置清除颜色(
GL.ClearColor

受保护的覆盖无效OnUpdate帧(FrameEventArgs e)
{
if(KeyboardState.IsKeyDown(Keys.Escape))
{
Close();
}
基础.更新帧(e);
int-original_w=。。。;
int原始_h=。。。;
int current_w=这个.Size.X;
int current_h=此.Size.Y;
双电流相位=(双)电流w/电流h;
双重原始相位=(双重)原始相位w/原始相位h;
GL.禁用(启用剪式测试);
总图视口(0,0,当前w,当前h);
GL.ClearColor(0.0f、0.0f、0.0f、0.0f);
GL.Clear(ClearBufferMask.ColorBufferBit);
总账启用(启用CAP.剪刀测试);
if(当前方面>原始方面)
{
int w=(int)(当前w*原始方面/当前方面);
int x=(当前w-w)/2;
GL.剪刀(x,0,w,该尺寸为Y);
总图视口(x,0,w,this.Size.Y);
}
其他的
{
inth=(int)(当前方面*当前方面/原始方面);
int y=(当前_h-h)/2;
GL.剪刀(0,y,此尺寸X,h);
总图视口(0,y,此.Size.X,h);
}
GL.ClearColor(颜色:矢车菊蓝);
GL.Clear(ClearBufferMask.ColorBufferBit);
// [...]    
这个。SwapBuffers();
}

是的,我尝试了更多的代码