c# - OpenTK 使用视口
问题描述
我想将视口与 OpenTK 一起使用,这样我就可以在 3D 查看区域周围为 2D UI 创建面板。目前,我只有一个非常简单的程序,只是试图初始化我的视口。这是我的基本游戏课程。我所做的就是运行它。目前,由于添加了关于两个视口的行,我得到一个空引用错误,但我真的不明白为什么。如果不在 OnLoad 中,我应该在其他地方创建视口吗?
编辑
我将代码更改为如下所示,但仍然遇到相同的问题 - onLoad 中不再有任何对视口的引用:
protected override void OnRenderFrame(FrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
//First, try to create 2 viewports
//GL.Enable(GL_SCISSOR_TEST);
GL.Viewport(windowSetup.height / 2, 0, windowSetup.width / 2, windowSetup.height / 2);
//GL.LoadIdentity();
GL.Scissor(windowSetup.height / 2, 0, windowSetup.width / 2, windowSetup.height / 2);
//Bind shader
Shader.Use();
//Bind VOA
GL.BindVertexArray(VertexArrayObject);
GL.DrawElements(PrimitiveType.Triangles, rectIndices.Length, DrawElementsType.UnsignedInt, 0);
Context.SwapBuffers();
//Try viewport 2
GL.Viewport(0, windowSetup.height , windowSetup.width / 2, windowSetup.height / 2);
GL.Scissor(0, windowSetup.height , windowSetup.width / 2, windowSetup.height / 2);
Shader.Use();
GL.BindVertexArray(VertexArrayObject);
GL.DrawElements(PrimitiveType.Triangles, rectIndices.Length, DrawElementsType.UnsignedInt, 0);
Context.SwapBuffers();
base.OnRenderFrame(e);
}
解决方案
推荐阅读
- vb.net - 如何用表单数据替换word文档模板
- css - 去除背景中间,只保留边框
- listview - 用户单击按钮时很难加载 ListView
- ironpython - 如何在 Spotfire 页面上获取视觉对象的大小和位置?
- c++ - C++ ifdef 阻塞会导致 ABI 兼容性问题吗?
- javascript - 用javascript隐藏测验按钮
- java - JPA Criteria API - 使用 CriteriaBuilder.treat() 方法向下转换
- python - 水平堆叠的独特 100% 条形图 plotly python
- python - 无法加载 python3 包(即使使用 virtualenv)
- excel - 引用 VBA GetOpenFilename(Excel 宏)