• Advertisement
Sign in to follow this  

[SlimDX] Slow drawing with Direct2D?

This topic is 2930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I'm new to the whole Direct2D stuff. How can I speedup the drawing with Direct2D? I'm only drawing some rectangles and one text. On 2560x1600, it takes about 150ms. What I'm doing wrong?
private DateTime mStartTime;
private DateTime mEndTime;

SlimDX.DirectWrite.TextFormat textFormat = new SlimDX.DirectWrite.TextFormat(new SlimDX.DirectWrite.Factory(), "Segoe UI", SlimDX.DirectWrite.FontWeight.Normal, SlimDX.DirectWrite.FontStyle.Normal, SlimDX.DirectWrite.FontStretch.Normal, 32.0f, "DE_de");

private void button1_Click(System.Object sender, System.EventArgs e)
    System.Windows.Forms.Form f = this;
    WindowRenderTargetProperties wrtp = new WindowRenderTargetProperties();
    wrtp.Handle = f.Handle;
    wrtp.PixelSize = f.ClientSize;
    WindowRenderTarget renderTarget = new WindowRenderTarget(new SlimDX.Direct2D.Factory(), wrtp);
    SlimDX.Color4 c4;
    c4 = Color.LightSlateGray;
    SlimDX.Direct2D.SolidColorBrush brush1 = new SolidColorBrush(renderTarget, c4);
    c4 = Color.CornflowerBlue;
    SlimDX.Direct2D.SolidColorBrush brush2 = new SolidColorBrush(renderTarget, c4);
    RectangleF rect = new RectangleF(100.0f, 100.0f, 200.0f, 50.0f);

    this.mStartTime = DateTime.Now;

    if (!renderTarget.IsOccluded)
        renderTarget.Transform = Matrix3x2.Identity;
        c4 = Color.White;

        PointF startPoint = PointF.Empty;
        PointF endPoint = new PointF(renderTarget.Size.Width, renderTarget.Size.Height);

        while (startPoint.X < renderTarget.Size.Width)
            endPoint.X = startPoint.X;
            renderTarget.DrawLine(brush1, startPoint, endPoint, 0.5f);
            startPoint.X = startPoint.X + 10.0f;

        startPoint = PointF.Empty;
        endPoint.X = renderTarget.Size.Width;
        endPoint.Y = 0.0f;

        while (startPoint.Y < renderTarget.Size.Height)
            endPoint.Y = startPoint.Y;
            renderTarget.DrawLine(brush1, startPoint, endPoint, 0.5f);
            startPoint.Y = startPoint.Y + 10.0f;

        renderTarget.DrawText("Hello World", textFormat, rect, brush1);

        RectangleF rect1 = new RectangleF(renderTarget.Size.Width / 2.0f - 50.0f, renderTarget.Size.Height / 2.0f - 50.0f, 100.0f, 100.0f);
        RectangleF rect2 = new RectangleF(renderTarget.Size.Width / 2.0f - 100.0f, renderTarget.Size.Height / 2.0f - 100.0f, 200.0f, 200.0f);

        renderTarget.FillRectangle(brush1, rect1);
        renderTarget.FillRectangle(brush2, rect2);


    this.mEndTime = DateTime.Now;
    this.Text = string.Format("{0}", this.mEndTime.Subtract(this.mStartTime).TotalMilliseconds);


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement