// 環境:
// .net frame work 2.0 ベース & SlimDX January 2012 SDK
//
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using SlimDX.Windows;
using SlimDX.Direct3D9;
namespace TestSlimDx
{
static class Program
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
Application.Run(new TestRender());
}
}
class TestRender : RenderForm
{
private Direct3D d3d;
private Device dev;
public TestRender()
{
this.Load += new EventHandler(TestRender_Load);
this.Paint += new PaintEventHandler(TestRender_Paint);
}
private
void log(String s
) {
System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ms") + ": " + s);
}
void TestRender_Load(object sender, EventArgs e)
{
this.Width = 800;
this.Height = 600;
d3d = new Direct3D();
dev = null;
// アダプタモード
log("** GET DISP.MODE **"); DisplayMode dm = d3d.GetAdapterDisplayMode(0);
if (dm == null)
{
log("** ADAPTER FAILED **"); return;
}
// 挙動の初期パラメタ
PresentParameters pp = new PresentParameters();
pp.DeviceWindowHandle = this.Handle;
pp.Windowed = true;
pp.BackBufferCount = 1;
pp.BackBufferWidth = this.Width;
pp.BackBufferHeight = this.Height;
pp.BackBufferFormat = dm.Format;
pp.SwapEffect = SwapEffect.Flip;
pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = Format.D16;
pp.FullScreenRefreshRateInHertz = 0;
pp.PresentationInterval = PresentInterval.Immediate; // 漢らしく
pp.Multisample = MultisampleType.None;
pp.MultisampleQuality = 0;
// デバイス生成 TODO: 果たして NULL 返すのか?
log("** CREATE DEVICE **"); Capabilities cap = null;
if ((cap = d3d.GetDeviceCaps(0, DeviceType.Hardware)) != null)
{
dev = new Device(d3d, 0, cap.DeviceType, this.Handle, CreateFlags.HardwareVertexProcessing, pp);
}
else if (
(cap = d3d.GetDeviceCaps(0, DeviceType.Reference)) != null
|| (cap = d3d.GetDeviceCaps(0, DeviceType.Software)) != null
) {
log("** CAP [RF or SW] ** "); dev = new Device(d3d, 0, cap.DeviceType, this.Handle, CreateFlags.SoftwareVertexProcessing, pp);
}
if (dev == null)
{
log("** FATAL ERROR **"); return;
}
this.Show();
}
void TestRender_Paint(object sender, PaintEventArgs e)
{
if (dev == null)
{
log("** DEVICE LOST **"); return;
}
dev.BeginScene();
dev.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0x00000000, 1, 0);
dev.EndScene();
dev.Present();
}
}
}