Example #1
0
        public void Capture()
        {
            try
            {
                bool notThis = CurrentlyEnabled != this && CurrentlyEnabled != null && CurrentlyEnabled._context.IsCurrent;

                if (notThis)
                {
                    CurrentlyEnabled.Release();
                }

                CurrentlyEnabled = this;
                if (!_context.IsCurrent)
                {
                    _context.MakeCurrent(WindowInfo);
                }

                if (ContextChanged != null && notThis)
                {
                    ContextChanged(true);
                }
            }
            catch //(Exception x)
            {
                //MessageBox.Show(x.ToString());
                Reset();
            }
        }
Example #2
0
        public void Capture(bool force = false)
        {
            try
            {
                //Only proceed if this window is not already current
                if (force || CurrentContext != this)
                {
                    //Release the current context if it exists
                    CurrentContext?.Release();

                    //Make this context the current one
                    CurrentContext = this;
                    if (!_context.IsCurrent)
                    {
                        _context.MakeCurrent(WindowInfo);
                    }

                    ContextChanged?.Invoke(true);
                }
            }
            catch //(Exception x)
            {
                //MessageBox.Show(x.ToString());
                Reset();
            }
        }
Example #3
0
 private void DisposeContext()
 {
     if (_ctx != null)
     {
         _ctx.Unbind();
         _ctx.Dispose();
         _ctx = null;
     }
 }
Example #4
0
        public void Release()
        {
            if (CurrentContext == this && !_context.IsDisposed && _context.IsCurrent)
            {
                CurrentContext = null;
                _context.MakeCurrent(null);

                ContextChanged?.Invoke(false);
            }
        }
Example #5
0
        public void Release()
        {
            if (CurrentlyEnabled == this && !CurrentlyEnabled._context.IsDisposed && _context.IsCurrent)
            {
                CurrentlyEnabled = null;
                _context.MakeCurrent(null);

                //if (ContextChanged != null)
                //    ContextChanged(false);
            }
        }
Example #6
0
 public void Bind(int index, int program, TKContext ctx)
 {
     if (program != -1 && ctx != null && ctx._shadersEnabled)
     {
         index = index.Clamp(0, 7);
         GL.ActiveTexture(TextureUnit.Texture0 + index);
         GL.BindTexture(TextureTarget.Texture2D, Initialize());
         GL.Uniform1(GL.GetUniformLocation(program, "Texture" + index), index);
     }
     else
     {
         GL.BindTexture(TextureTarget.Texture2D, Initialize());
     }
 }
Example #7
0
        private static GLDisplayList CreateLine(TKContext ctx)
        {
            GLDisplayList list = new GLDisplayList();

            GL.Begin(BeginMode.Lines);

            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.Vertex3(2.0f, 0.0f, 0.0f);

            GL.End();

            list.End();
            return(list);
        }
Example #8
0
        public new void Capture()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(Capture));
                return;
            }

            if (_ctx == null)
            {
                _ctx = new TKContext(this);
            }

            _ctx.Capture();
        }
Example #9
0
        protected override void OnLoad(EventArgs e)
        {
            _ctx = new TKContext(this);

            Capture();

            Vector3 v = (Vector3)BackColor;

            GL.ClearColor(v._x, v._y, v._z, 0.0f);
            GL.ClearDepth(1.0);

            OnInit(_ctx);

            _ctx.ContextChanged += OnContextChanged;
            _ctx.ResetOccured   += OnReset;

            base.OnLoad(e);
        }
Example #10
0
        public static GLDisplayList CreateSphere(TKContext ctx)
        {
            //IntPtr quad = Glu.NewQuadric();
            //Glu.QuadricDrawStyle(quad, QuadricDrawStyle.Fill);
            //Glu.QuadricOrientation(quad, QuadricOrientation.Outside);

            GLDisplayList dl = new GLDisplayList();

            dl.Begin();

            DrawSphere(new Vector3(), 1.0f, 40);
            //Glu.Sphere(quad, 1.0f, 40, 40);
            dl.End();

            //Glu.DeleteQuadric(quad);

            return(dl);
        }
Example #11
0
        protected override void OnLoad(EventArgs e)
        {
            _ctx  = new TKContext(this);
            _text = new ScreenTextHandler(this);

            Vector3 v = (Vector3)BackColor;

            GL.ClearColor(v._x, v._y, v._z, 0.0f);
            GL.ClearDepth(1.0f);

            Capture();

            OnInit(_ctx);

            _ctx.ContextChanged += ContextChanged;

            base.OnLoad(e);
        }
Example #12
0
        private static GLDisplayList CreateRing(TKContext ctx)
        {
            GLDisplayList list = new GLDisplayList();

            list.Begin();

            GL.Begin(BeginMode.LineLoop);

            float angle = 0.0f;

            for (int i = 0; i < 360; i++, angle = i * Maths._deg2radf)
            {
                GL.Vertex2(Math.Cos(angle), Math.Sin(angle));
            }

            GL.End();

            list.End();
            return(list);
        }
Example #13
0
        private static GLDisplayList CreateCube(TKContext ctx)
        {
            GLDisplayList list = new GLDisplayList();

            list.Begin();

            GL.Begin(BeginMode.QuadStrip);

            Vector3 p1 = new Vector3(0);
            Vector3 p2 = new Vector3(0.99f);

            GL.Vertex3(p1._x, p1._y, p1._z);
            GL.Vertex3(p1._x, p2._y, p1._z);
            GL.Vertex3(p2._x, p1._y, p1._z);
            GL.Vertex3(p2._x, p2._y, p1._z);
            GL.Vertex3(p2._x, p1._y, p2._z);
            GL.Vertex3(p2._x, p2._y, p2._z);
            GL.Vertex3(p1._x, p1._y, p2._z);
            GL.Vertex3(p1._x, p2._y, p2._z);
            GL.Vertex3(p1._x, p1._y, p1._z);
            GL.Vertex3(p1._x, p2._y, p1._z);

            GL.End();

            GL.Begin(BeginMode.Quads);

            GL.Vertex3(p1._x, p2._y, p1._z);
            GL.Vertex3(p1._x, p2._y, p2._z);
            GL.Vertex3(p2._x, p2._y, p2._z);
            GL.Vertex3(p2._x, p2._y, p1._z);

            GL.Vertex3(p1._x, p1._y, p1._z);
            GL.Vertex3(p1._x, p1._y, p2._z);
            GL.Vertex3(p2._x, p1._y, p2._z);
            GL.Vertex3(p2._x, p1._y, p1._z);

            GL.End();

            list.End();
            return(list);
        }
Example #14
0
        private static GLDisplayList CreateCircle(TKContext ctx)
        {
            GLDisplayList list = new GLDisplayList();

            list.Begin();

            GL.Begin(BeginMode.TriangleFan);

            GL.Vertex3(0.0f, 0.0f, 0.0f);

            float angle = 0.0f;

            for (int i = 0; i < 361; i++, angle = i * Maths._deg2radf)
            {
                GL.Vertex2(Math.Cos(angle), Math.Sin(angle));
            }

            GL.End();

            list.End();
            return(list);
        }
Example #15
0
 internal virtual void OnInit(TKContext ctx)
 {
 }
Example #16
0
 internal protected virtual void OnRender(TKContext ctx, PaintEventArgs e)
 {
     GL.Clear(OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit | OpenTK.Graphics.OpenGL.ClearBufferMask.DepthBufferBit);
 }