public void DrawGeometry(GLGeometry geo, GLBrush brush, float lineWidth = 1.0f) { GL.PushMatrix(); if (lineWidth == 1.0f) { AddHalfPixelOffset(); } GL.Enable(EnableCap.LineSmooth); GL.Color4(brush.Color0); #if FAMISTUDIO_LINUX if (!supportsLineWidth && lineWidth > 1) { var pts = new float[geo.Points.Length * 2 + (geo.Closed ? 2 : 0)]; for (int i = 0; i < geo.Points.GetLength(0); i++) { pts[i * 2 + 0] = geo.Points[i, 0]; pts[i * 2 + 1] = geo.Points[i, 1]; } if (geo.Closed) { pts[geo.Points.Length * 2 + 0] = geo.Points[0, 0]; pts[geo.Points.Length * 2 + 1] = geo.Points[0, 1]; } DrawThickLineAsPolygon(pts, brush, lineWidth); } else #endif { GL.LineWidth(lineWidth); GL.EnableClientState(ArrayCap.VertexArray); GL.VertexPointer(2, VertexPointerType.Float, 0, geo.Points); GL.DrawArrays(geo.Closed ? BeginMode.LineLoop : BeginMode.LineStrip, 0, geo.Points.GetLength(0)); GL.DisableClientState(ArrayCap.VertexArray); } GL.Disable(EnableCap.LineSmooth); GL.PopMatrix(); }
public void FillGeometry(GLGeometry geo, GLBrush brush, bool smooth = false) { if (!brush.IsGradient) { if (smooth) { GL.Enable(EnableCap.PolygonSmooth); } GL.Color4(brush.Color0); GL.EnableClientState(ArrayCap.VertexArray); GL.VertexPointer(2, VertexPointerType.Float, 0, geo.Points); GL.DrawArrays(BeginMode.TriangleFan, 0, geo.Points.GetLength(0)); GL.DisableClientState(ArrayCap.VertexArray); if (smooth) { GL.Disable(EnableCap.PolygonSmooth); } } else { Debug.Assert(brush.GradientSizeX == 0.0f); GL.Begin(BeginMode.TriangleFan); for (int i = 0; i < geo.Points.GetLength(0); i++) { float lerp = geo.Points[i, 1] / (float)brush.GradientSizeY; byte r = (byte)(brush.Color0.R * (1.0f - lerp) + (brush.Color1.R * lerp)); byte g = (byte)(brush.Color0.G * (1.0f - lerp) + (brush.Color1.G * lerp)); byte b = (byte)(brush.Color0.B * (1.0f - lerp) + (brush.Color1.B * lerp)); byte a = (byte)(brush.Color0.A * (1.0f - lerp) + (brush.Color1.A * lerp)); GL.Color4(r, g, b, a); GL.Vertex2(geo.Points[i, 0], geo.Points[i, 1]); } GL.End(); } }
public void FillAndDrawGeometry(GLGeometry geo, GLBrush fillBrush, GLBrush lineBrush, float lineWidth = 1.0f) { FillGeometry(geo, fillBrush); DrawGeometry(geo, lineBrush, lineWidth); }