2015-07-20 176 views
1

我想繪製使用D3D9的位圖..我在這裏得到的代碼,它的工作。它確實吸引了我的盒子和圖像,但是當我只畫框時,我得到了60左右的fps。當我取消註釋繪製位圖的代碼時,我在5-30之間獲得了fps,並且它非常滯後。我的代碼有什麼問題?使用D3D9繪製紋理

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); 
    } 
} 
+0

您不應該從每個文件的每個幀讀取紋理。在循環之前做一次。 –

回答

1

您是否嘗試過在渲染循環之外分配位圖?根據位圖的大小,它可能會減慢速度。您在循環的每次迭代中爲該位圖分配並重新分配空間。

將其分配移到循環外部,然後在渲染循環中渲染它(即一個分配)。

+0

非常感謝你,我把'Drawing.DrawTexture(新的Bitmap(「test.jpg」));'循環外,我再次fps 60左右。想知道爲什麼我沒有找到自己。我猜這是不好的主意,在早上三點進行編碼。 – Vacko