ID3D11DeviceContext* d3dContext = nullptr; ID3D11Device* device = nullptr; // Create the Direct3D device and device context HRESULT hr = D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_DEBUG, nullptr, 0, D3D11_SDK_VERSION, &device, nullptr, &d3dContext ); // Set the device context as active for rendering d3dContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
// Define a vertex buffer for a triangle struct Vertex { float x, y, z; }; Vertex vertices[] = { { -0.5f, -0.5f, 0.0f }, { 0.5f, -0.5f, 0.0f }, { 0.0f, 0.5f, 0.0f } }; D3D11_BUFFER_DESC bufferDesc = {}; bufferDesc.Usage = D3D11_USAGE_DEFAULT; bufferDesc.ByteWidth = sizeof(Vertex) * 3; bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; D3D11_SUBRESOURCE_DATA initData = {}; initData.pSysMem = vertices; ID3D11Buffer* vertexBuffer; d3dContext->CreateBuffer(&bufferDesc, &initData, &vertexBuffer); // Set the vertex buffer as active UINT stride = sizeof(Vertex); UINT offset = 0; d3dContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); // Draw the triangle d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); d3dContext->Draw(3, 0);This example shows how to create a vertex buffer and draw a simple triangle on the screen. Package/Library: DirectX Graphics SDK