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(); } }
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(); } }
private void DisposeContext() { if (_ctx != null) { _ctx.Unbind(); _ctx.Dispose(); _ctx = null; } }
public void Release() { if (CurrentContext == this && !_context.IsDisposed && _context.IsCurrent) { CurrentContext = null; _context.MakeCurrent(null); ContextChanged?.Invoke(false); } }
public void Release() { if (CurrentlyEnabled == this && !CurrentlyEnabled._context.IsDisposed && _context.IsCurrent) { CurrentlyEnabled = null; _context.MakeCurrent(null); //if (ContextChanged != null) // ContextChanged(false); } }
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()); } }
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); }
public new void Capture() { if (InvokeRequired) { Invoke(new Action(Capture)); return; } if (_ctx == null) { _ctx = new TKContext(this); } _ctx.Capture(); }
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); }
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); }
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); }
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); }
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); }
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); }
internal virtual void OnInit(TKContext ctx) { }
internal protected virtual void OnRender(TKContext ctx, PaintEventArgs e) { GL.Clear(OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit | OpenTK.Graphics.OpenGL.ClearBufferMask.DepthBufferBit); }