Ejemplo n.º 1
0
        public static void DrawLine(glRenderTarget target, 
            Vector2 A, Vector2 B, glColor color)
        {
            int x0 = (int)A.X;
            int y0 = (int)A.Y;
            int x1 = (int)B.X;
            int y1 = (int)B.Y;

            var dx = Math.Abs(x1 - x0);
            var dy = Math.Abs(y1 - y0);
            var sx = (x0 < x1) ? 1 : -1;
            var sy = (y0 < y1) ? 1 : -1;
            var err = dx - dy;
            int scanline_offset = y0 * target.Width;

            while (true)
            {
                if (x0 >= 0 && y0 >= 0
                    && x0 < target.Width
                    && y0 < target.Height)
                {
                    target.Data[x0 + scanline_offset] = color;
                }

                if ((x0 == x1) && (y0 == y1))
                    break;
                var e2 = 2 * err;
                if (e2 > -dy)
                {
                    err -= dy;
                    x0 += sx;
                }
                if (e2 < dx)
                {
                    err += dx;
                    y0 += sy;
                    scanline_offset = y0 * target.Width;
                }
            }
        }
Ejemplo n.º 2
0
 public void SetPixel(int x, int y, int z, glColor value)
 {
     CheckDisposed();
     CheckUnLocked();
     Data[x + Width * (y + Height * z)] = value;
 }