Reputation: 163
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);
}
}
Upvotes: 1
Views: 997
Reputation:
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.
Upvotes: 2