/// <summary> /// This needs to be updated to use the same approach as Draw(Rectangle, Rectangle) /// </summary> /// <param name="srcRects"></param> /// <param name="destRects"></param> public override void DrawRects(RectangleF[] srcRects, RectangleF[] destRects, int start, int length) { PositionColorNormalTexture[] verts = new PositionColorNormalTexture[srcRects.Length * 4]; short[] indices = new short[srcRects.Length * 6]; int startIndex = 0; int indexIndex = 0; for (int i = start; i < start + length; i++) { AddRectToVB(verts, startIndex, srcRects[i], destRects[i]); indices[indexIndex] = (short)startIndex; indices[indexIndex + 1] = (short)(startIndex + 1); indices[indexIndex + 2] = (short)(startIndex + 2); indices[indexIndex + 3] = (short)(startIndex + 2); indices[indexIndex + 4] = (short)(startIndex + 1); indices[indexIndex + 5] = (short)(startIndex + 3); startIndex += 4; indexIndex += 6; } mDevice.DrawBuffer.CacheDrawIndexedTriangles(verts, indices, mTexture.Value, true); //mDevice.SetDeviceStateTexture(mTexture.Value); //mDevice.AlphaBlend = true; //mDevice.VertexFormat = CustomVertex.TransformedColoredTextured.Format; ////mDevice.Device.DrawUserPrimitives(PrimitiveType.TriangleList, 2 * srcRects.Length, verts); //mDevice.Device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, indexIndex, // srcRects.Length * 2, indices, true, verts); }
private void AddRectToVB(PositionColorNormalTexture[] verts, int startIndex, RectangleF srcRect, RectangleF destRect) { // find center PointF centerpt = Origin.CalcF(DisplayAlignment, DisplaySize); float left = destRect.Left - 0.5f; float top = destRect.Top - 0.5f; float right = destRect.Right - 0.5f; // +(float)Math.Floor(destRect.Width / (float)srcRect.Width); float bottom = destRect.Bottom - 0.5f; // +(float)Math.Floor(destRect.Height / (float)srcRect.Height); PointF[] corners = new PointF[4] { new PointF(left, top), new PointF(right, top), new PointF(left, bottom), new PointF(right, bottom) }; PointF[] uv = new PointF[4] { new PointF(mSrcRect.Left + srcRect.Left, mSrcRect.Top + srcRect.Top), new PointF(mSrcRect.Left + srcRect.Right, mSrcRect.Top + srcRect.Top), new PointF(mSrcRect.Left + srcRect.Left, mSrcRect.Top + srcRect.Bottom), new PointF(mSrcRect.Left + srcRect.Right, mSrcRect.Top + srcRect.Bottom) }; TranslatePointInPlace(ref corners, centerpt); for (int i = 0; i < 4; i++) { verts[startIndex + i] = new PositionColorNormalTexture( corners[i].X, corners[i].Y, 0.0F, Color.ToArgb(), uv[i].X / (float)mTextureSize.Width, uv[i].Y / (float)mTextureSize.Height, 0, 0, -1); } }