private void InitializeGraphics() { try { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; presentParams.BackBufferFormat = Format.Unknown; presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true; // Store the default adapter int adapterOrdinal = D3D.Manager.Adapters.Default.Adapter; CreateFlags flags = CreateFlags.SoftwareVertexProcessing; // Check to see if we can use a pure hardware device D3D.Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware); // Do we support hardware vertex processing? if (caps.DeviceCaps.SupportsHardwareTransformAndLight) { // Replace the software vertex processing flags = CreateFlags.HardwareVertexProcessing; } // Do we support a pure device? if (caps.DeviceCaps.SupportsPureDevice) { flags |= CreateFlags.PureDevice; } device = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams); device.DeviceReset += new System.EventHandler(this.OnResetDevice); OnResetDevice(device, null); tileSheet = TextureLoader.FromFile(device, MediaUtilities.FindFile("donuts.bmp"), 1024, 1024, 1, 0, Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked ((int)0xff000000))); tileSet = new TileSet(tileSheet, 0, 0, 6, 5, 32, 32); tilePosition = new Rectangle(tileSet.XOrigin, tileSet.YOrigin, tileSet.ExtentX * 2, tileSet.ExtentY * 2); //set up DirectInput keyboard device... kbd = new DI.Device(SystemGuid.Keyboard); kbd.SetCooperativeLevel(this, DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive); kbd.Acquire(); //Set up DirectSound device and buffers snd = new DS.Device(); snd.SetCooperativeLevel(this, DS.CooperativeLevel.Normal); bounce = new DS.SecondaryBuffer(MediaUtilities.FindFile("bounce.wav"), snd); hrt.Start(); } catch (DirectXException) { // Catch any errors and return a failure } }
private void InitializeGraphics() { try { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; presentParams.BackBufferFormat = Format.Unknown; presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true; // Store the default adapter int adapterOrdinal = Manager.Adapters.Default.Adapter; CreateFlags flags = CreateFlags.SoftwareVertexProcessing; // Check to see if we can use a pure hardware device Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware); // Do we support hardware vertex processing? if (caps.DeviceCaps.SupportsHardwareTransformAndLight) { // Replace the software vertex processing flags = CreateFlags.HardwareVertexProcessing; } // Do we support a pure device? if (caps.DeviceCaps.SupportsPureDevice) { flags |= CreateFlags.PureDevice; } device = new Device(0, DeviceType.Hardware, this, flags, presentParams); device.DeviceReset += new System.EventHandler(this.OnResetDevice); OnResetDevice(device, null); tileSheet = TextureLoader.FromFile(device, MediaUtilities.FindFile("donuts.bmp"), 1024, 1024, 1, 0, Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked ((int)0xff000000))); //Uncomment these lines to see the spite border areas // donutTexture = TextureLoader.FromFile(device, MediaUtilities.FindFile("donuts.bmp"), 1024, 1024, // 1, 0,Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, 0); tileSet = new TileSet(tileSheet, 0, 0, 6, 5, 32, 32); tilePosition = new Rectangle(tileSet.XOrigin, tileSet.YOrigin, tileSet.ExtentX * 2, tileSet.ExtentY * 2); hrt.Start(); } catch (DirectXException) { // Catch any errors and return a failure } }