/// <summary> /// Begins using the <see cref="Brush"/> to paint a geometry. Must be followed by a call to the <see cref="Brush.EndUse"/> method /// </summary> /// <param name="drawing">The <see cref="Drawing"/> to render</param> public override void BeginUse(Drawing drawing) { Color color; if (this.Opacity != 1) { color = Color.FromArgb((int)(this.Color.A * this.Opacity), this.Color.R, this.Color.G, this.Color.B); } else { color = this.Color; } GL.Color4(color); }
/// <summary> /// Begins using the <see cref="Brush"/> to paint a geometry. Must be followed by a call to the <see cref="Brush.EndUse"/> method /// </summary> /// <param name="drawing">The <see cref="Drawing"/> to render</param> public override void BeginUse(Drawing drawing) { Rectangle bounds; //Sets the drawing as the active drawing this._ActiveDrawing = drawing; //Make sure that the texture exists if (this.Texture == null) { return; } //Load the texture if it hasn't already been done this.Texture.Load(); //Gets the bounds of the geometry bounds = drawing.Bounds; //Clears the buffer //GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); //Sets the color, that is white with its alpha multiplied by the brush's opacity GL.Color4(Color.FromArgb((byte)(255 * this.Opacity), 255, 255, 255)); //Clears the stencil GL.ClearStencil(0); //Sets the stencil mask to 1 GL.StencilMask(1); //Enables stencil test GL.Enable(EnableCap.StencilTest); //Sets the stencil function to draw the mask GL.StencilFunc(StencilFunction.Always, 1, 1); //Sets the stencil operation to draw the mask GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace); }
/// <summary> /// Ends using the <see cref="Brush"/> /// </summary> public override void EndUse() { //Sets the stencil function to draw the masked geometry GL.StencilFunc(StencilFunction.Equal, 1, 1); //Sets the stencil operation to draw the masked geometry GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep); //Enable 2D texturing GL.Enable(EnableCap.Texture2D); //Binds the TextureId GL.BindTexture(TextureTarget.Texture2D, this.Texture.Id); //Begins rendering the texture GL.Begin(PrimitiveType.Quads); //Top left texture coordinate and vertex GL.TexCoord2(0, 0); GL.Vertex2(this._ActiveDrawing.Bounds.Left, this._ActiveDrawing.Bounds.Top); //Top right texture coordinate and vertex GL.TexCoord2(1, 0); GL.Vertex2(this._ActiveDrawing.Bounds.Right, this._ActiveDrawing.Bounds.Top); //Bottom right texture coordinate and vertex GL.TexCoord2(1, 1); GL.Vertex2(this._ActiveDrawing.Bounds.Right, this._ActiveDrawing.Bounds.Bottom); //Bottom left texture coordinate and vertex GL.TexCoord2(0, 1); GL.Vertex2(this._ActiveDrawing.Bounds.Left, this._ActiveDrawing.Bounds.Bottom); //Ends rendering the texture GL.End(); //Unbinds the texture GL.BindTexture(TextureTarget.Texture2D, 0); //Disable 2D texturing GL.Disable(EnableCap.Texture2D); //Disable the stencil test GL.Disable(EnableCap.StencilTest); //Clears the active drawing this._ActiveDrawing = null; }
/// <summary> /// Begins using the <see cref="Brush"/> to render the specified <see cref="Drawing"/>. Must be followed by a call to the <see cref="Brush.EndUse"/> method /// </summary> /// <param name="drawing">The <see cref="Drawing"/> to render</param> public abstract void BeginUse(Drawing drawing);