protected override void OnPaint(PaintEventArgs e) { if (_updateCounter > 0) { return; } if (_ctx == null) { base.OnPaint(e); } else if (Monitor.TryEnter(_ctx)) { try { //Direct OpenGL calls to this panel Capture(); OnRender(e); //Display newly rendered back buffer _ctx.Swap(); //Check for errors ErrorCode code = GL.GetError(); if (code != ErrorCode.NoError) { this.Reset(); //Stops the red X of death in its tracks } } finally { Monitor.Exit(_ctx); } } }
protected override void OnPaint(PaintEventArgs e) { if (_updateCounter > 0) { return; } if (_ctx == null) { base.OnPaint(e); } else if (Monitor.TryEnter(_ctx)) { try { //Direct OpenGL calls to this panel Capture(); //Render background image if (BackgroundImage != null) { RenderBackground(); } else if (_updateImage && _bgImage != null) { _bgImage.Delete(); _bgImage = null; _updateImage = false; } if (_bgColorChanged) { Vector3 v = (Vector3)BackColor; GL.ClearColor(v._x, v._y, v._z, 0.0f); _bgColorChanged = false; } //Set projection if (_projectionChanged) { OnResized(); _projectionChanged = false; } //Apply camera if (_camera != null) fixed(Matrix *p = &_camera._matrix) { GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix((float *)p); } //Render 3D scene OnRender(_ctx, e); //Render selection overlay and/or text overlays if ((_selecting && !_forceNoSelection) || _text.Count != 0) { GL.Color4(Color.White); GL.PushAttrib(AttribMask.AllAttribBits); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.Lighting); GL.Disable(EnableCap.CullFace); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); Matrix p = Matrix.OrthographicMatrix(0, Width, 0, Height, -1, 1); GL.LoadMatrix((float *)&p); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); if (_text.Count != 0 && _textEnabled) { _text.Draw(); } if (_selecting && !_forceNoSelection) { RenderSelection(); } GL.PopAttrib(); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); } GL.Finish(); _ctx.Swap(); ErrorCode code = GL.GetError(); if (code != ErrorCode.NoError) { this.Reset(); //Stops the red X of death in its tracks } } finally { Monitor.Exit(_ctx); } } //Clear text values //This will be filled until the next render _text.Clear(); }