public void Draw(Graphics2DGL core, params object[] parameters) { //int x, int y, int w, int h, Pixel color if (parameters.Length != 5) { throw new Graphics2DGLException(core, "[Primitives] Circle - must have 5 parameters set!"); } var x = (int)parameters[0]; var y = (int)parameters[1]; var w = (int)parameters[2]; var h = (int)parameters[3]; var color = (Pixel)parameters[4]; if (w < 0) { w *= -1; x -= w; } core.DrawLine(x, y, x + w, y, color); core.DrawLine(x + w - 1, y, x + w - 1, y + h, color); core.DrawLine(x, y + h - 1, x + w, y + h - 1, color); core.DrawLine(x, y, x, y + h, color); }
public void Draw(Graphics2DGL core, params object[] parameters) { if (parameters.Length != 4) { throw new Graphics2DGLException(core, "[Primitives] Circle - must have 4 parameters set!"); } var x0 = (int)parameters[0]; var y0 = (int)parameters[1]; var r = (int)parameters[2]; var color = (Pixel)parameters[3]; x0 += r - 1; y0 += r - 1; var x = r - 1; var y = 0; var dx = 1; var dy = 1; var err = dx - (r << 1); while (x >= y) { core.Draw(x0 + x, y0 + y, color); core.Draw(x0 + y, y0 + x, color); core.Draw(x0 - y, y0 + x, color); core.Draw(x0 - x, y0 + y, color); core.Draw(x0 - x, y0 - y, color); core.Draw(x0 - y, y0 - x, color); core.Draw(x0 + y, y0 - x, color); core.Draw(x0 + x, y0 - y, color); if (err <= 0) { y++; err += dy; dy += 2; } if (err > 0) { x--; dx += 2; err += dx - (r << 1); } } }
public void Fill(Graphics2DGL core, params object[] parameters) { if (parameters.Length != 7) { throw new Graphics2DGLException(core, "[Primitives] Triangle - must have 7 parameters set!"); } var x1 = (int)parameters[0]; var y1 = (int)parameters[1]; var x2 = (int)parameters[2]; var y2 = (int)parameters[3]; var x3 = (int)parameters[4]; var y3 = (int)parameters[5]; var color = (Pixel)parameters[6]; var minX = Math.Min(Math.Min(x1, x2), x3); var maxX = Math.Max(Math.Max(x1, x2), x3); var minY = Math.Min(Math.Min(y1, y2), y3); var maxY = Math.Max(Math.Max(y1, y2), y3); for (var x = minX; x < maxX; x++) { for (var y = minY; y < maxY; y++) { float d1, d2, d3; bool hasNeg, hasPos; d1 = core.Sign(x, y, x1, y1, x2, y2); d2 = core.Sign(x, y, x2, y2, x3, y3); d3 = core.Sign(x, y, x3, y3, x1, y1); hasNeg = d1 < 0 || d2 < 0 || d3 < 0; hasPos = d1 > 0 || d2 > 0 || d3 > 0; if (!(hasNeg && hasPos)) { core.Draw(x, y, color); } } } }
public void Draw(Graphics2DGL core, params object[] parameters) { //int x1, int y1, int x2, int y2, int x3, int y3, Pixel color if (parameters.Length != 7) { throw new Graphics2DGLException(core, "[Primitives] Triangle - must have 7 parameters set!"); } var x1 = (int)parameters[0]; var y1 = (int)parameters[1]; var x2 = (int)parameters[2]; var y2 = (int)parameters[3]; var x3 = (int)parameters[4]; var y3 = (int)parameters[5]; var color = (Pixel)parameters[6]; core.DrawLine(x1, y1, x2, y2, color); core.DrawLine(x2, y2, x3, y3, color); core.DrawLine(x1, y1, x3, y3, color); }
public void Fill(Graphics2DGL core, params object[] parameters) { if (parameters.Length != 5) { throw new Graphics2DGLException(core, "[Primitives] Circle - must have 5 parameters set!"); } var x = (int)parameters[0]; var y = (int)parameters[1]; var w = (int)parameters[2]; var h = (int)parameters[3]; var color = (Pixel)parameters[4]; for (var i = 0; i < w; i++) { for (var j = 0; j < h; j++) { core.Draw(x + i, y + j, color); } } }
public void Fill(Graphics2DGL core, params object[] parameters) { if (parameters.Length != 4) { throw new Graphics2DGLException(core, "[Primitives] Circle - must have 4 parameters set!"); } var x = (int)parameters[0]; var y = (int)parameters[1]; var r = (int)parameters[2]; var color = (Pixel)parameters[3]; for (var i = 0; i < r * 2; i++) { for (var j = 0; j < r * 2; j++) { var dist = Math.Sqrt((r - i) * (r - i) + (r - j) * (r - j)); if (dist < r) { core.Draw(x - 1 + i, y - 1 + j, color); } } } }
public Graphics2DGLException(Graphics2DGL gfx, string errorMsg, Exception innerEx) { graphics = gfx; ErrorMsg = errorMsg; innerException = innerEx; }
public Graphics2DGLException(Graphics2DGL gfx, string errorMsg) : this(gfx, errorMsg, null) { }
public Graphics2DGLException(Graphics2DGL gfx, Exception innerEx) : this(gfx, string.Empty, innerEx) { }
public Graphics2DGLException(Graphics2DGL gfx) : this(gfx, string.Empty, null) { }
public override void Initialize(params object[] parameters) { Log("Initialize..."); if (parameters.Length >= 2) { if (parameters[0] is HydraGL) { engineControl = (HydraGL)parameters[0]; } else { throw new ArgumentException("Must be a HydraGL!", "parameters[0]"); } if (parameters[1] is int) { MaxFPS = (int)parameters[1]; } else { throw new ArgumentException("Must be an integer!", "parameters[1]"); } if (parameters.Length >= 3) { if (parameters[2] is bool) { IsVerbose = (bool)parameters[2]; } else { throw new ArgumentException("Must be a boolean!", "parameters[2]"); } } else { IsVerbose = false; } Width = engineControl.Width; Height = engineControl.Height; HalfHeight = Height / 2; HalfWidth = Width / 2; background = new Sprite(Width, Height); graphics = new Graphics2DGL(Width, Height); background.Clear(Pixel.BLACK); t1 = t2 = DateTime.Now; startTime = DateTime.Now; GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.MultisampleSgis); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); BaseShaderID = CreateProgram(vertexShader, fragmentShader); pixelGraphics = new RendererGL(this, graphics.DrawTarget, BaseShaderID); engineControl.Paint += EngineControl_Paint; engineControl.Resize += EngineControl_Resize; Application.Idle += Application_Idle; EngineControl_Resize(engineControl, EventArgs.Empty); engineControl.MakeCurrent(); } else { throw new ArgumentOutOfRangeException("parameters", "Has to be at least 2 parameters!"); } }
protected virtual void Draw(Graphics2DGL graphics) { #if VERBOSELOG Log("GLEngine -> Draw"); #endif }