protected override void OnOpenGLDraw(object sender, RenderEventArgs args) { base.OnOpenGLDraw(sender, args); GL.Clear(0, 0.6f, 1, 1); GL.OrthoProj(Control.Width, Control.Height); using (SpriteBatch.BeginScope()) { foreach (var rect in rects /*maxRectsBinPack.usedRectangles*/) { i++; SpriteBatch.Rect(rect.x, rect.y, rect.width, rect.height, colors[i % colors.Length]); } } }
protected override void OnOpenGLDraw(object sender, RenderEventArgs args) { fbo.Bind(); GL.Clear(0, 1, 1, 1); GL.Viewport(0, 0, 500, 500); GL.OrthoProj(500, 500); //using (SpriteBatch.BeginScope()) //{ //SpriteBatch.Rect(0, 0, 200, 200, Color.Red); // SpriteBatch.Fan(points.Reverse().ToArray(), color); //} //byte[] pixels = new byte[4]; //GL.ReadPixels(1, 1, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, pixels); GL.Disable(GL_CULL_FACE); GL.Enable(GL_DEPTH_TEST); GL.Enable(GL_BLEND); GL.BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); GL.BlendEquation(GL_FUNC_ADD_EXT); GL.DrawText(0, 0, 1, 1, 1, "Segoe UI Light", 80, "Hello Doods"); FrameBuffer.Unbind(GL); GL.Clear(0, 0.6f, 1, 1); GL.Viewport(0, 0, Control.Width, Control.Height); GL.OrthoProj(Control.Width, Control.Height); using (SpriteBatch.BeginScope()) { SpriteBatch.Rect(200, 100, 300, 300, fbo.Texture, Color.White); SpriteBatch.Rect(10, 10, 50, 50, Color.Green); //SpriteBatch.Fan(points.Reverse().ToArray(), color); } }
protected override void OnOpenGLDraw(object sender, RenderEventArgs args) { GL.Clear(0, 0.6f, 1, 1); GL.OrthoProj(Control.Width, Control.Height); //using (SpriteBatch.BeginScope()) //{ // for (var i = 0; i < spaces.Count; ++i) // { // var space = spaces[i]; // SpriteBatch.Rect(space.x, space.y, space.z, space.w, Color.Red); // } //} using (SpriteBatch.BeginScope()) { for (var i = 0; i < rects.Count; ++i) { var rect = rects[i]; SpriteBatch.Rect(rect.x, rect.y, rect.z, rect.w, TestColor); } } var collission = DetectCollission(rects); if (collission.Happened) { using (SpriteBatch.BeginScope()) { var rectA = rects[collission.A]; var rectB = rects[collission.B]; SpriteBatch.Rect(rectA.x, rectA.y, rectA.z, rectA.w, Color.Green); SpriteBatch.Rect(rectB.x, rectB.y, rectB.z, rectB.w, Color.DarkBlue); } } }
protected virtual void OnRedraw(OpenGL gl) { gl.ClearColor(1, 1, 1, 1); gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl.MatrixMode(GL_PROJECTION); gl.LoadIdentity(); gl.Ortho(0, Width, Height, 0, -1, 1); gl.MatrixMode(GL_MODELVIEW); gl.LoadIdentity(); using (spriteBatch.BeginScope()) { float borderThickness = 1; var iLoCol = 0; var iHiCol = 0; var iLoRow = 0; var iHiRow = 0; //DrawColumns(borderThickness, ref iLoCol, ref iHiCol); //DrawRows(borderThickness, ref iLoRow, ref iHiRow); //for (var iCol = iLoCol; iCol < iHiCol; iCol++) // for (var iRow = iLoRow; iRow < iHiRow; iRow++) // { // var offsetX = Columns[iCol]._OffsetX; // var offsetY = Rows[iRow]._OffsetY; // spriteBatch.Text((float)Math.Round(offsetX - (float)HOffset + 15), (float)Math.Round(offsetY - (float)VOffset), names[(iCol + iRow) % names.Length], font, TextColor, .5f, .5f); // } //for (var iCol = iLoCol; iCol < iHiCol; iCol++) // for (var iRow = iLoRow; iRow < iHiRow; iRow++) // { // var offsetX = Columns[iCol]._OffsetX; // var offsetY = Rows[iRow]._OffsetY; // spriteBatch.Rect(offsetX - (float)HOffset + 3, offsetY - (float)VOffset + 3, 9, 9, colors[(iCol + iRow) % colors.Length]); // spriteBatch.Rect(offsetX - (float)HOffset + 2, offsetY - (float)VOffset + 2, 11, 11, BorderColor, -.1f); // } //spriteBatch.Triangle( // new vec2(-1.0f, -1.0f), // new vec2(1.0f, -1.0f), // new vec2(1.0f, 1.0f), // Color.Chocolate, 1.0f); var n = .39f; //var rects = new[] { new vec2(32, 146), new vec2(71, 24), new vec2(55, 132), new vec2(77, 38), new vec2(43, 79) }; // reverse, longer into y //for (var i = 0; i < rects.Length; ++i) //{ // ref var rect = ref rects[i]; // if (rect.x > rect.y) // { // var oldX = rect.x; // rect.x = rect.y; // rect.y = rect.x; // } //} var maxHeight = rectSizes.Max(z => z.y); var sumWidth = rectSizes.Sum(z => z.x); Array.Sort(rectSizes, new Comparison <vec2>((a, b) => (int)(b.x * b.y - a.x * a.y))); var spaces = new List <vec4>(); spaces.Add(new vec4(rectSizes[0].x, 0, 9999f, 9999f)); spaces.Add(new vec4(0, rectSizes[0].y, 9999f, 9999f)); var rects = new List <vec4> { new vec4(0, 0, rectSizes[0].x, rectSizes[0].y) }; var width = Math.Max(rectSizes[0].x, rectSizes[0].y); for (var i = 1; i < rectSizes.Length; ++i) { // go through all rectangles and place them somewhere var rectSize = rectSizes[i]; var spaceFoundIndex = -1; vec4 foundSpace = new vec4(0, 0, 9999f, 9999f); for (var iSpace = 0; iSpace < spaces.Count; ++iSpace) { var space = spaces[iSpace]; if (space.z >= rectSize.x && space.w >= rectSize.y) { // would fit if (spaceFoundIndex == -1) { spaceFoundIndex = iSpace; foundSpace = space; } else { if (space.x + rectSize.x < width && space.y + rectSize.y < width) { //if (space.x + rectSize.x + space.y + rectSize.y < foundSpace.x + rectSize.x + foundSpace.y + rectSize.y) //{ spaceFoundIndex = iSpace; foundSpace = space; //} } } } } if (spaceFoundIndex == -1) { throw new Exception("not found"); } var newSpace0 = new vec4(foundSpace.x + rectSize.x, foundSpace.y, 9999f, 9999f); spaces[spaceFoundIndex] = newSpace0; spaces.Add(new vec4(foundSpace.x, foundSpace.y + rectSize.y, 9999f, 9999f)); var newRect = new vec4(foundSpace.x, foundSpace.y, rectSize.x, rectSize.y); rects.Add(newRect); width = Math.Max(width, Math.Max(newRect.x + newRect.z, newRect.y + newRect.w)); for (var iSpace = 0; iSpace < spaces.Count; ++iSpace) { var space = spaces[iSpace]; var hitTestX = HitTests.HitTest(newRect.x, newRect.x + newRect.z, space.x, space.x + space.z); var hitTestY = HitTests.HitTest(newRect.y, newRect.y + newRect.w, space.y, space.y + space.w); if (hitTestX != HitTestResult.Apart && hitTestY != HitTestResult.Apart) { if (hitTestX == HitTestResult.B_Contains_A) { space.z = newRect.x - space.x; continue; } if (hitTestY == HitTestResult.B_Contains_A) { space.w = newRect.y - space.y; continue; } if (hitTestX == HitTestResult.A_Intersects_B) { space.z = space.z - (newRect.x + newRect.z) - space.x; space.x = newRect.x + newRect.z; continue; } if (hitTestY == HitTestResult.A_Intersects_B) { space.w = space.w - (newRect.y + newRect.w) - space.y; space.y = newRect.y + newRect.w; continue; } } } } Validate(rects); for (var i = 0; i < rects.Count; ++i) { var rect = rects[i]; spriteBatch.Rect(rect.x, rect.y, rect.z, rect.w, colors[i % colors.Length]); } //for(var i = 0; i < rectSizes.Length; ++i) //{ // var rectSize = rectSizes[i]; // spriteBatch.Rect( // x, 0f, rectSize.x, rectSize.y, colors[i % colors.Length]); // x += rectSize.x; //} //spriteBatch.Quad( // new vec2(-n, -n), // new vec2(n, -n), // new vec2(n, n), // new vec2(-n, n), // // _texture, // Color.Red); //spriteBatch.Rect( // 100, 105, // 1000.0f, 1200.0f, //Color.Black); //spriteBatch.Rect( // 100, 105, // 1300.0f, 1200.0f, // _texture, // Color.Gainsboro); //for (var x = 0f; x < 1000f; x += 10) // for (var y = 0f; y < 1000f; y += 10) // { // spriteBatch.Rect( // x + _rotation % 100, y, // 9, 9, // Color.PaleVioletRed); // } //spriteBatch.Text((float)HOffset, (float)VOffset, "Hello World!!!", font, TextColor, 1f, 1f); } }