public override void DrawLine(Vector2Df Start, Vector2Df End) { if (m_LineImageCache == null) { //m_LineImageCache = new BufferedImage(4, 1, BufferedImage.PixelType.INT_ARGB); //renderer.FillRect(1, 0, 1, 1); m_LineImageCache = new BufferedImage(4, 4, BufferedImage.PixelType.INT_ARGB); Renderer2D renderer = m_LineImageCache.GetRenderer2D; renderer.Color.AlphaI = 0; renderer.FillRect(0, 0, 4, 4); renderer.Color.AlphaI = 255; renderer.FillRect(1, 2, 1, 2); #if false // Fill in the rest of the pixels for testing renderer.Color.RedI = 0; renderer.FillRect(0, 0, 4, 1); renderer.FillRect(3, 0, 1, 4); renderer.Color.BlueI = 0; renderer.FillRect(0, 1, 1, 3); renderer.FillRect(0, 1, 3, 1); renderer.FillRect(2, 1, 1, 3); #endif } ImageGLDisplayListPlugin GLBuffer = ImageGLDisplayListPlugin.GetImageGLDisplayListPlugin(m_LineImageCache); Gl.glEnable(Gl.GL_TEXTURE_2D); Gl.glEnable(Gl.GL_BLEND); Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glColor4f(m_Color.RedF, m_Color.GreenF, m_Color.BlueF, m_Color.AlphaF); Vector2Df Normal = (End - Start); Vector2Df PerpendicularNormal = Normal.GetPerpendicularNormal(); float Width = 1; Vector2Df OffsetPos = PerpendicularNormal * Width; Vector2Df OffsetNeg = PerpendicularNormal * -(Width + 1); PushOrthoProjection(); Gl.glBindTexture(Gl.GL_TEXTURE_2D, GLBuffer.GLTextureHandle); Gl.glBegin(Gl.GL_QUADS); #if true Gl.glTexCoord2d(0, .75); Gl.glVertex2f(Start.x + OffsetPos.x, Start.y + OffsetPos.y); Gl.glTexCoord2d(0, 1); Gl.glVertex2f(End.x + OffsetPos.x, End.y + OffsetPos.y); Gl.glTexCoord2d(.75, 1); Gl.glVertex2f(End.x + OffsetNeg.x, End.y + OffsetNeg.y); Gl.glTexCoord2d(.75, .5); Gl.glVertex2f(Start.x + OffsetNeg.x, Start.y + OffsetNeg.y); #else // draw the main line (without the tips) Gl.glTexCoord2d(0, .75); Gl.glVertex2f(Start.x + OffsetPos.x + Normal.x, Start.y + OffsetPos.y + Normal.y); Gl.glTexCoord2d(0, 1); Gl.glVertex2f(End.x + OffsetPos.x - Normal.x, End.y + OffsetPos.y - Normal.y); Gl.glTexCoord2d(.75, 1); Gl.glVertex2f(End.x + OffsetNeg.x - Normal.x, End.y + OffsetNeg.y - Normal.y); Gl.glTexCoord2d(.75, .5); Gl.glVertex2f(Start.x + OffsetNeg.x + Normal.x, Start.y + OffsetNeg.y + Normal.y); // draw the ending tip anti-aliased Gl.glTexCoord2d(0, 1); Gl.glVertex2f(End.x + OffsetPos.x - Normal.x, End.y + OffsetPos.y - Normal.y); Gl.glTexCoord2d(0, .25); Gl.glVertex2f(End.x + OffsetPos.x, End.y + OffsetPos.y); Gl.glTexCoord2d(.75, .25); Gl.glVertex2f(End.x + OffsetNeg.x, End.y + OffsetNeg.y); Gl.glTexCoord2d(.75, 1); Gl.glVertex2f(End.x + OffsetNeg.x - Normal.x, End.y + OffsetNeg.y - Normal.y); // draw the starting tip anti-aliased Gl.glTexCoord2d(0, .25); Gl.glVertex2f(Start.x + OffsetPos.x, Start.y + OffsetPos.y); Gl.glTexCoord2d(0, 1); Gl.glVertex2f(Start.x + OffsetPos.x + Normal.x, Start.y + OffsetPos.y + Normal.y); Gl.glTexCoord2d(.75, 1); Gl.glVertex2f(Start.x + OffsetNeg.x + Normal.x, Start.y + OffsetNeg.y + Normal.y); Gl.glTexCoord2d(.75, .25); Gl.glVertex2f(Start.x + OffsetNeg.x, Start.y + OffsetNeg.y); #endif Gl.glColor4f(1, 1, 1, 1); Gl.glEnd(); PopOrthoProjection(); }
public void DrawLine(IVector <T> Start, IVector <T> End, bool DoAA) { if (Start == End) { return; } Gl.glPushAttrib(Gl.GL_ALL_ATTRIB_BITS); CheckLineImageCache(); ImageGLDisplayListPlugin <T> GLBuffer = ImageGLDisplayListPlugin <T> .GetImageGLDisplayListPlugin(m_LineImageCache); Gl.glEnable(Gl.GL_BLEND); Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glColor4f(0, 0, 0, 1); IVector <T> Normal = (End.Subtract(Start)); Normal = Normal.Normalize(); IVector <T> PerpendicularNormal = Normal.GetPerpendicular(); float Width = 40; if (DoAA) { Width--; } IVector <T> OffsetPos = PerpendicularNormal.Multiply(Width); IVector <T> OffsetNeg = PerpendicularNormal.Multiply(-(Width + 1)); RendererOpenGL <T> .PushOrthoProjection(); Gl.glDisable(Gl.GL_TEXTURE_2D); IVector <T> StartLeft = Start.Add(OffsetPos); IVector <T> StartRight = Start.Add(OffsetNeg); IVector <T> EndLeft = End.Add(OffsetPos); IVector <T> EndRight = End.Add(OffsetNeg); Gl.glBegin(Gl.GL_QUADS); { Gl.glVertex2d(StartLeft[0].ToDouble(), StartLeft[1].ToDouble()); Gl.glVertex2d(EndLeft[0].ToDouble(), EndLeft[1].ToDouble()); Gl.glVertex2d(EndRight[0].ToDouble(), EndRight[1].ToDouble()); Gl.glVertex2d(StartRight[0].ToDouble(), StartRight[1].ToDouble()); } Gl.glEnd(); if (DoAA) { double EdgeWith = 2; //IVector<DoubleComponent> StartLeftAA = StartLeft + PerpendicularNormal * EdgeWith - Normal * EdgeWith; //IVector<DoubleComponent> StartRightAA = StartRight - PerpendicularNormal * EdgeWith - Normal * EdgeWith; //IVector<DoubleComponent> EndLeftAA = EndLeft + PerpendicularNormal * EdgeWith + Normal * EdgeWith; //IVector<DoubleComponent> EndRightAA = EndRight - PerpendicularNormal * EdgeWith + Normal * EdgeWith; IVector <T> StartLeftAA = StartLeft .Add(PerpendicularNormal) .Multiply(EdgeWith) .Subtract(Normal) .Multiply(EdgeWith); IVector <T> StartRightAA = StartRight .Subtract(PerpendicularNormal) .Multiply(EdgeWith) .Subtract(Normal) .Multiply(EdgeWith); IVector <T> EndLeftAA = EndLeft .Add(PerpendicularNormal) .Multiply(EdgeWith) .Add(Normal) .Multiply(EdgeWith); IVector <T> EndRightAA = EndRight .Subtract(PerpendicularNormal) .Multiply(EdgeWith) .Add(Normal) .Multiply(EdgeWith); Gl.glEnable(Gl.GL_TEXTURE_2D); Gl.glBindTexture(Gl.GL_TEXTURE_2D, GLBuffer.GLTextureHandle); Gl.glBegin(Gl.GL_QUADS); { // left edge Gl.glTexCoord2d(0, 0); Gl.glVertex2d(StartLeft[0].ToDouble(), StartLeft[1].ToDouble()); Gl.glVertex2d(EndLeft[0].ToDouble(), EndLeft[1].ToDouble()); Gl.glTexCoord2d(1, 0); Gl.glVertex2d(EndLeftAA[0].ToDouble(), EndLeftAA[1].ToDouble()); Gl.glVertex2d(StartLeftAA[0].ToDouble(), StartLeftAA[1].ToDouble()); // right edge Gl.glTexCoord2d(0, 0); Gl.glVertex2d(StartRight[0].ToDouble(), StartRight[1].ToDouble()); Gl.glVertex2d(EndRight[0].ToDouble(), EndRight[1].ToDouble()); Gl.glTexCoord2d(1, 0); Gl.glVertex2d(EndRightAA[0].ToDouble(), EndRightAA[1].ToDouble()); Gl.glVertex2d(StartRightAA[0].ToDouble(), StartRightAA[1].ToDouble()); // start edge EdgeWith = 20; Gl.glTexCoord2d(0, 0); Gl.glVertex2d(StartLeft[0].ToDouble(), StartLeft[1].ToDouble()); Gl.glVertex2d(StartRight[0].ToDouble(), StartRight[1].ToDouble()); Gl.glTexCoord2d(1, 0); Gl.glVertex2d(StartRightAA[0].ToDouble(), StartRightAA[1].ToDouble()); Gl.glVertex2d(StartLeftAA[0].ToDouble(), StartLeftAA[1].ToDouble()); // end edge Gl.glTexCoord2d(0, 0); Gl.glVertex2d(EndLeft[0].ToDouble(), EndLeft[1].ToDouble()); Gl.glVertex2d(EndRight[0].ToDouble(), EndRight[1].ToDouble()); Gl.glTexCoord2d(1, 0); Gl.glVertex2d(EndRightAA[0].ToDouble(), EndRightAA[1].ToDouble()); Gl.glVertex2d(EndLeftAA[0].ToDouble(), EndLeftAA[1].ToDouble()); } Gl.glEnd(); } RendererOpenGL <T> .PopOrthoProjection(); Gl.glPopAttrib(); }