1

i want to draw bitmap using D3D9.. I got code here and it works out. It does draw me box and image, but when i draw only box i got fps around 60. When i uncomment that code for drawing bitmap i got fps between 5-30 and it's very lagging. What's wrong with my code ?

private void D3D9Render()
{
    do
    {
        Drawing.Device.Clear(D3D9.ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1.0f, 0);
        Drawing.Device.BeginScene();
        Drawing.DrawText("Fps : " + Fps.CalculateFrameRate().ToString(), Drawing.Width - 72, 220, Color.White);

        Drawing.DrawBox(v.X, v.Y, 90, 7);
    /*
            Drawing.DrawTexture(new Bitmap("test.jpg"));
            Drawing.Sprite.Begin(D3D9.SpriteFlags.None);
            Drawing.Sprite.Draw(Drawing.Texture, Drawing.TextureSize,
            new Vector3(0, 0, 0),
            new Vector3(v.X-65, v.Y-55, v.Z), Color.White);
            Drawing.Sprite.End();
    */
        Drawing.Device.EndScene();
        Drawing.Device.Present();

    } while (true);

}


public static void DrawTexture(Bitmap image)
{
    Texture = new Texture(Device, image, Usage.None, Pool.Managed);

    using (Surface surface = Texture.GetSurfaceLevel(0))
    {
        SurfaceDescription surfaceDescription = surface.Description;
        TextureSize = new Rectangle(0, 0,
                          surfaceDescription.Width,
                          surfaceDescription.Height);
    }
}
1
  • You should not read a texture from a file each frame. Do it once before the loop. Commented Jul 20, 2015 at 23:43

1 Answer 1

2

Have you tried allocating your bitmap outside of your render loop? Depending on the size of the bitmap, it could really slow things down. You're allocating and re-allocating space for that bitmap each iteration of the loop.

Move its allocation outside of the loop and then render it (that one allocation) in your render loop.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah thank you very much, i put Drawing.DrawTexture(new Bitmap("test.jpg")); out of loop and i have again fps around 60. Wondering why i didnt find that out by myself. I guess that's not good idea do coding at 3 o clock in the morning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.