Completed code to initialise Direct3D.