lid6j86's picture

viewport issues

I'm trying to change the viewport size when the form itself resizes with the following:

protected override void OnClientSizeChanged(EventArgs e)
        {
            base.OnClientSizeChanged(e);
            GLGFX.Viewport(0, 0, this.ClientSize.Width, this.ClientSize.Height);
 
        }

but it keeps giving me an error:

NullReferenceException was unhandled: Object reference not set to an instance of an object.

any help?

here is the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Xml;
using System.Text;
using System.Windows.Forms;
using OpenTK.Graphics.OpenGL;
using GLGFX = OpenTK.Graphics.OpenGL.GL;
 
 
namespace Test1
{
    public partial class Form1 : Form
    {
        FastLoop _fastLoop;
        bool _fullscreen = false;
 
 
 
        public Form1()
        {
            _fastLoop = new FastLoop(GameLoop);
            InitializeComponent();
 
 
 
            if (_fullscreen)
            {
                FormBorderStyle = FormBorderStyle.None;
                WindowState = FormWindowState.Maximized;
            }
        }
 
        void GameLoop(double elapsedTime)
        {
 
            GLGFX.ClearColor(0.0f,0.0f,0.0f,1.0f);
            GLGFX.Clear(ClearBufferMask.ColorBufferBit);
            GLGFX.PointSize(5.0f);
            GLGFX.Rotate(100 * elapsedTime, 0, 1, 0);
            GLGFX.Begin(BeginMode.Triangles);
            {
                GLGFX.Color4(1.0f, 0.0f, 0.0f, 1.0f);
                GLGFX.Vertex3(-0.5, 0, 0);
                GLGFX.Color4(0.0f, 1.0f, 0.0f, 1.0f);
                GLGFX.Vertex3(0.5, 0, 0);
                GLGFX.Color4(0.0f, 0.0f, 1.0f, 1.0f);
                GLGFX.Vertex3(0, 0.5, 0);
 
            }
            GLGFX.End();
            glControl1.SwapBuffers();
            GLGFX.Finish();
            glControl1.Refresh();
 
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
        protected override void OnClientSizeChanged(EventArgs e)
        {
            base.OnClientSizeChanged(e);
            GLGFX.Viewport(0, 0, this.ClientSize.Width, this.ClientSize.Height);
 
        }
    }
}

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lid6j86's picture

nevermind, finally fixed it! I just had to add glcontrol1.MakeCurrent(),i guess it didn't know what i was trying to point it to