public override void DrawEllipse(PBrush c, float width, RectangleF rect) { const int DETAIL = 50; float x = (rect.Left + rect.Right) / 2f; float y = (rect.Top + rect.Bottom) / 2f; float rx = (rect.Right - rect.Left) / 2f; float ry = (rect.Bottom - rect.Top) / 2f; float w = 1 - width * 2f / (rx + ry); if (c != null) { GL.Color(c.GetColor()); } GL.Begin(PrimitiveType.QUADS); double lA = 0; for (int i = 1; i <= DETAIL; i++) { double a = i * Math.PI * 2.0 / DETAIL; float sin1 = (float)Math.Sin(lA); float cos1 = (float)Math.Cos(lA); float sin2 = (float)Math.Sin(a); float cos2 = (float)Math.Cos(a); float[] ptsx = new float[] { cos1, cos1 *w, cos2 *w, cos2 }; float[] ptsy = new float[] { sin1, sin1 *w, sin2 *w, sin2 }; NativeGL.nglVertex2fTrans(4, ptsx, ptsy, x, y, rx, ry); lA = a; } GL.End(); }
public override void SetRenderTarget(RenderBitmap bmp) { if (bmp == null || !(bmp is RenderBitmap3)) { NativeGL.nglBindFramebuffer(0); } else { ((RenderBitmap3)bmp).FBO.Bind(); } }
public override void FillEllipse(PBrush c, RectangleF rect) { float x = (rect.Left + rect.Right) / 2f; float y = (rect.Top + rect.Bottom) / 2f; float rx = (rect.Right - rect.Left) / 2f; float ry = (rect.Bottom - rect.Top) / 2f; if (c != null) { GL.Color(c.GetColor()); } GL.Begin(PrimitiveType.TRIANGLES); NativeGL.nglVertex2fTrans(pEllipseX.Length, pEllipseX, pEllipseY, x, y, rx, ry); GL.End(); }
public override void Init() { ctx.InitAsync(); ctx.MakeCurrent(); NativeGL.nglInit(); Opengl32.glBlendFunc(GLConsts.GL_SRC_ALPHA, GLConsts.GL_ONE_MINUS_SRC_ALPHA); Opengl32.glEnable(GLConsts.GL_BLEND); int eSize = 32; ellipse = new gdi.Bitmap(eSize, eSize); var g = gdi.Graphics.FromImage(ellipse); g.Clear(gdi.Color.Transparent); g.SmoothingMode = gdi2d.SmoothingMode.HighQuality; g.FillEllipse(gdi.Brushes.White, new RectangleF(1, 1, eSize - 2, eSize - 2)); texEllipse = Kritzel.GLRenderer.Util.LoadTexture(ellipse); int eDet = 16; pEllipseX = new float[3 * eDet]; pEllipseY = new float[3 * eDet]; float l_x = 1, l_y = 0; for (int i = 0; i < eDet; i++) { float arg = (i + 1) / (float)eDet * 2 * (float)Math.PI; float x = (float)Math.Cos(arg); float y = (float)Math.Sin(arg); pEllipseX[i * 3] = l_x; pEllipseY[i * 3] = l_y; pEllipseX[i * 3 + 1] = 0; pEllipseY[i * 3 + 1] = 0; l_x = x; l_y = y; pEllipseX[i * 3 + 2] = x; pEllipseY[i * 3 + 2] = y; } }
public override void Circle(float x, float y, float r) { NativeGL.nglVertex2fTrans(pEllipseX.Length, pEllipseX, pEllipseY, x, y, r, r); }