packages/Windows API Code Pack 1.1/source/Samples/DirectX/CS/Direct3D10/Tutorials/D3D10Tutorial02_WinFormsControl/TutorialWindow.cs
/// <summary>
/// Create Direct3D device and swap chain
/// </summary>
Create Direct3D device and swap chain
Create Direct3D device and swap chain
protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
            swapChain = device.SwapChain;
            SetViews();
            using (FileStream effectStream = File.OpenRead("Tutorial02.fxo"))
            {
                effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream));
            }
            technique = effect.GetTechniqueByName("Render");
            InputElementDescription[] layout = 
            {
                new InputElementDescription()
                {
                    SemanticName = "POSITION",
                    SemanticIndex = 0,
                    Format = Format.R32G32B32Float,
                    InputSlot = 0,
                    AlignedByteOffset = 0,
                    InputSlotClass = InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };
            PassDescription passDesc = technique.GetPassByIndex(0).Description;
            vertexLayout = device.CreateInputLayout(
                layout,
                passDesc.InputAssemblerInputSignature,
                passDesc.InputAssemblerInputSignatureSize);
            device.IA.InputLayout = vertexLayout;
            SimpleVertexArray vertex = new SimpleVertexArray();
            BufferDescription bd = new BufferDescription()
            {
                Usage = Usage.Default,
                ByteWidth = (uint)Marshal.SizeOf(vertex),
                BindingOptions = BindingOptions.VertexBuffer,
                CpuAccessOptions = CpuAccessOptions.None,
                MiscellaneousResourceOptions = MiscellaneousResourceOptions.None
            };
            IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex));
            Marshal.StructureToPtr(vertex, vertexData, false);
            SubresourceData InitData = new SubresourceData()
            {
                SystemMemory = vertexData,
                SystemMemoryPitch = 0,
                SystemMemorySlicePitch = 0
            };
            vertexBuffer = device.CreateBuffer(bd, InitData);
            uint stride = (uint)Marshal.SizeOf(typeof(Vector3F));
            uint offset = 0;
            device.IA.SetVertexBuffers(0, new Collection<D3DBuffer>()
                {
                    vertexBuffer
                },
                new uint[] { stride }, new uint[] { offset });
            device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList;
            Marshal.FreeCoTaskMem(vertexData);
        }
protected void InitDevice ( ) { device = D3DDevice . CreateDeviceAndSwapChain ( directControl . Handle ) ; swapChain = device . SwapChain ; SetViews ( ) ; using ( FileStream effectStream = File . OpenRead ( " " ) ) { effect = device . CreateEffectFromCompiledBinary ( new BinaryReader ( effectStream ) ) ; } technique = effect . GetTechniqueByName ( " " ) ; InputElementDescription [ ] layout = { new InputElementDescription ( ) { SemanticName = " " , SemanticIndex = 0 , Format = Format . R32G32B32Float , InputSlot = 0 , AlignedByteOffset = 0 , InputSlotClass = InputClassification . PerVertexData , InstanceDataStepRate = 0 } } ; PassDescription passDesc = technique . GetPassByIndex ( 0 ) . Description ; vertexLayout = device . CreateInputLayout ( layout , passDesc . InputAssemblerInputSignature , passDesc . InputAssemblerInputSignatureSize ) ; device . IA . InputLayout = vertexLayout ; SimpleVertexArray vertex = new SimpleVertexArray ( ) ; BufferDescription bd = new BufferDescription ( ) { Usage = Usage . Default , ByteWidth = ( uint ) Marshal . SizeOf ( vertex ) , BindingOptions = BindingOptions . VertexBuffer , CpuAccessOptions = CpuAccessOptions . None , MiscellaneousResourceOptions = MiscellaneousResourceOptions . None } ; IntPtr vertexData = Marshal . AllocCoTaskMem ( Marshal . SizeOf ( vertex ) ) ; Marshal . StructureToPtr ( vertex , vertexData , false ) ; SubresourceData InitData = new SubresourceData ( ) { SystemMemory = vertexData , SystemMemoryPitch = 0 , SystemMemorySlicePitch = 0 } ; vertexBuffer = device . CreateBuffer ( bd , InitData ) ; uint stride = ( uint ) Marshal . SizeOf ( typeof ( Vector3F ) ) ; uint offset = 0 ; device . IA . SetVertexBuffers ( 0 , new Collection < D3DBuffer > ( ) { vertexBuffer } , new uint [ ] { stride } , new uint [ ] { offset } ) ; device . IA . PrimitiveTopology = PrimitiveTopology . TriangleList ; Marshal . FreeCoTaskMem ( vertexData ) ; }
Create Direct3D device and swap chain
Create Direct3D device and swap chain
// Create the effect // Obtain the technique // Define the input layout //D3DBuffer buffer = null; // Set vertex buffer // Set primitive topology