首页 > 解决方案 > 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);
        }

标签: c#openglopentk

解决方案


推荐阅读