fork download
  1. // 環境:
  2. // .net frame work 2.0 ベース & SlimDX January 2012 SDK
  3. //
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Windows.Forms;
  7. using SlimDX.Windows;
  8. using SlimDX.Direct3D9;
  9.  
  10. namespace TestSlimDx
  11. {
  12. static class Program
  13. {
  14. /// <summary>
  15. /// アプリケーションのメイン エントリ ポイントです。
  16. /// </summary>
  17. [STAThread]
  18. static void Main()
  19. {
  20. Application.EnableVisualStyles();
  21. Application.SetCompatibleTextRenderingDefault(false);
  22. //Application.Run(new Form1());
  23. Application.Run(new TestRender());
  24. }
  25. }
  26.  
  27. class TestRender : RenderForm
  28. {
  29. private Direct3D d3d;
  30. private Device dev;
  31.  
  32. public TestRender()
  33. {
  34. this.Load += new EventHandler(TestRender_Load);
  35. this.Paint += new PaintEventHandler(TestRender_Paint);
  36. }
  37.  
  38. private void log(String s)
  39. {
  40. System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ms") + ": " + s);
  41. }
  42.  
  43. void TestRender_Load(object sender, EventArgs e)
  44. {
  45. this.Width = 800;
  46. this.Height = 600;
  47.  
  48. d3d = new Direct3D();
  49. dev = null;
  50.  
  51.  
  52. // アダプタモード
  53. log("** GET DISP.MODE **");
  54. DisplayMode dm = d3d.GetAdapterDisplayMode(0);
  55. if (dm == null)
  56. {
  57. log("** ADAPTER FAILED **");
  58. return;
  59. }
  60.  
  61. // 挙動の初期パラメタ
  62. PresentParameters pp = new PresentParameters();
  63.  
  64. pp.DeviceWindowHandle = this.Handle;
  65. pp.Windowed = true;
  66.  
  67. pp.BackBufferCount = 1;
  68. pp.BackBufferWidth = this.Width;
  69. pp.BackBufferHeight = this.Height;
  70. pp.BackBufferFormat = dm.Format;
  71. pp.SwapEffect = SwapEffect.Flip;
  72.  
  73. pp.EnableAutoDepthStencil = true;
  74. pp.AutoDepthStencilFormat = Format.D16;
  75.  
  76. pp.FullScreenRefreshRateInHertz = 0;
  77. pp.PresentationInterval = PresentInterval.Immediate; // 漢らしく
  78.  
  79. pp.Multisample = MultisampleType.None;
  80. pp.MultisampleQuality = 0;
  81.  
  82. // デバイス生成 TODO: 果たして NULL 返すのか?
  83. log("** CREATE DEVICE **");
  84. Capabilities cap = null;
  85. if ((cap = d3d.GetDeviceCaps(0, DeviceType.Hardware)) != null)
  86. {
  87. log("** CAP [HW] ** ");
  88. dev = new Device(d3d, 0, cap.DeviceType, this.Handle, CreateFlags.HardwareVertexProcessing, pp);
  89. }
  90. else if (
  91. (cap = d3d.GetDeviceCaps(0, DeviceType.Reference)) != null
  92. || (cap = d3d.GetDeviceCaps(0, DeviceType.Software)) != null
  93. ) {
  94. log("** CAP [RF or SW] ** ");
  95. dev = new Device(d3d, 0, cap.DeviceType, this.Handle, CreateFlags.SoftwareVertexProcessing, pp);
  96. }
  97.  
  98. if (dev == null)
  99. {
  100. log("** FATAL ERROR **");
  101. return;
  102. }
  103.  
  104. this.Show();
  105. }
  106.  
  107. void TestRender_Paint(object sender, PaintEventArgs e)
  108. {
  109. if (dev == null)
  110. {
  111. log("** DEVICE LOST **");
  112. return;
  113. }
  114.  
  115. dev.BeginScene();
  116.  
  117. dev.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0x00000000, 1, 0);
  118.  
  119. dev.EndScene();
  120. dev.Present();
  121. }
  122.  
  123. }
  124. }
  125.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty