The reasons I'm using DirectX are to keep blit load off the CPU and to achieve VSync. I've chosen to code to DirectX9 so that I can support windows XP. I could have also looked into OpenGL, but since I was already using SlimDX for DirectInput, I figured DirectX might as well come along for the ride.
Here's what I did, along with the uncertainties I hit along the way in comments.
Code: Select all
/////////////////////////////////////////
// Initialize direct3d 9
this.direct3D = new Direct3D();
var presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard; // I've no idea if any of these is better than any other.
presentParams.DeviceWindowHandle = this.Handle;
// I calculated the maximum size by enumerating all the devices on the system
// (i.e. all the monitors). I don't understand if this was a bad idea. Would I
// be able to change all this on the window resize without issue? Would that
// be more standard practice? I was assuming this trick would allow me to
// resize more quickly. "Full Screen" in 4DO is really just a maximized window.
presentParams.BackBufferWidth = maxSize.Width;
presentParams.BackBufferHeight = maxSize.Height;
// I have seen someone post a 4DO crash report on this line. I believe this will
// throw an error if their machine doesn't support hardware acceleration. Ultimately
// I worry there must be a better way of determining this without having a big
// try/catch around everything. Is there a way to query system capabilities?
this.device = new Device(this.direct3D, 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, presentParams);
this.device.SetRenderState(RenderState.Lighting, false);
// I had a heck of a time finding a pixel format that wouldn't just crash here.
// Additionally, certain video cards did not "correctly" support this texture
// when it wasn't a power-of-two. I have forced the textures to power-of-two
// to attempt to support these scenarios. Is this normal?
this.texture = new Texture(this.device, textureWidth, textureHeight, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
var desc = this.texture.GetLevelDescription(0);
Later, I end up creating a triangle strip (with 2 triangles) to draw the bitmap to the device. I'm not sure if what I'm doing is overkill. I'm very curious to know if there's some other, more obvious mechanism for what I'm trying to do.