将OpenTK.glcontrol的大小设置为全屏-C#

时间:2018-10-08 07:37:02

标签: c# opengl viewport screen-resolution opentk

在我的表单中,我正在使用opentk的glcontrol传递视频帧。它运作良好。现在,我想将glcontrol的宽度和高度设置为全屏。我该如何实现?拖动glcontrol进行表单设计时,其大小将显示为783、420。实际上,在运行应用程序时会显示此大小。如何将其更改为全屏显示?更改视口的值似乎对此没有影响。是什么原因?

 public void Render()
    {
        GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); // use the visible framebuffer
        GL.ClearColor(0.5f, 0.5f, 0.55f, 0.0f);
        GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

        GL.Viewport(new Rectangle(0, 0, 1920, 1080));
        //GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);

        GL.MatrixMode(MatrixMode.Projection);
        GL.PushMatrix();
        GL.LoadIdentity();
        //GL.Ortho(0, 1920, 0, 1080, 0, 1);

        GL.MatrixMode(MatrixMode.Modelview);
        GL.PushMatrix();
        GL.LoadIdentity();

        GL.Disable(EnableCap.Lighting);

        GL.Enable(EnableCap.Texture2D);

        GL.ActiveTexture(TextureUnit.Texture0);

        if (videoFrame != null)
            lock (videoFrame)
            {
                if (videoTexture != -1)
                GL.DeleteTextures(1, ref videoTexture);
                videoTexture = LoadTexture(videoFrame);
                GL.BindTexture(TextureTarget.Texture2D, videoTexture);
                videoFrame.Dispose();
                videoFrame = null;
            }
        GC.Collect();

        //GL.Begin(PrimitiveType.Quads);

        //GL.TexCoord2(0, 1);
        //GL.Vertex3(0, 0, 0);

        //GL.TexCoord2(1, 1);
        //GL.Vertex3(1920, 0, 0);

        //GL.TexCoord2(1, 0);
        //GL.Vertex3(1920, 1080, 0);

        //GL.TexCoord2(0, 0);
        //GL.Vertex3(0, 1080, 0);

        //GL.End();

        RunShaders();
        GL.Disable(EnableCap.Texture2D);
        GL.PopMatrix();
        GL.MatrixMode(MatrixMode.Projection);
        GL.PopMatrix();
        GL.MatrixMode(MatrixMode.Modelview);

        ErrorCode ec = GL.GetError();
        if (ec != 0)
            System.Console.WriteLine(ec.ToString());
        Console.Read();
        glControl.SwapBuffers();
    }

0 个答案:

没有答案