DirectX11 / DXTK - 如何绘制简单的线条?

时间:2014-10-27 19:26:17

标签: c++ directx directx-11

我刚刚开始使用DirectX,我无法弄清楚如何绘制一条简单的线条。我尝试了以下但它似乎没有工作:

创建设备和交换链:

D3D11CreateDeviceAndSwapChain(
    nullptr,                            
    D3D_DRIVER_TYPE_HARDWARE,           
    nullptr,                            
    D3D11_CREATE_DEVICE_SINGLETHREADED, 
    nullptr,                            
    0,                                  
    D3D11_SDK_VERSION,
    &swapChainDesc,
    &this->SwapChain,
    &this->Device,
    nullptr,
    &this->DeviceContext);

BasicEffect和PrimitiveBatch的初始化:

// PrimitiveBatch
this->Batch.reset(new PrimitiveBatch<VertexPositionColor>(this->DeviceContext));

// BasicEffect
this->Effect.reset(new BasicEffect(this->Device));
this->Effect->SetVertexColorEnabled(true);

void const* shaderByteCode;
size_t byteCodeLength;

this->Effect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength);

// Set InputLayout
this->Device->CreateInputLayout(
    VertexPositionColor::InputElements,
    VertexPositionColor::InputElementCount,
    shaderByteCode,
    byteCodeLength,
    &this->InputLayout);

this->Effect->SetProjection(DirectX::XMMatrixOrthographicOffCenterRH(0.f, 800.f, 600.f, 0.f, 0.f, 1.f));
this->Effect->SetWorld(DirectX::XMMatrixIdentity());
this->Effect->SetView(DirectX::XMMatrixIdentity());

绘制测试功能:

this->Effect->Apply(this->DeviceContext);
this->DeviceContext->IASetInputLayout(this->InputLayout);

this->Batch->Begin();

const XMVECTORF32 s1 = { 10.f, 50.f, 1.f };
const XMVECTORF32 s2 = { 20.f, 200.f, 1.f };

VertexPositionColor v1(s1, Colors::Green);
VertexPositionColor v2(s2, Colors::Green);

this->Batch->DrawLine(v1, v2);

this->Batch->End();

调用DrawLine的地方:

this->DeviceContext->ClearRenderTargetView(this->RenderTargetView, Colors::Black);

// Trying to DrawLine
this->DrawLine(); // <- where Batch->DrawLine is executed**

this->SwapChain->Present(0, 0);

我按照这个例子 - &gt; https://directxtk.codeplex.com/wikipage?title=PrimitiveBatch&referringTitle=Home但我没有足够的经验知道我还需要绘制这条线。

0 个答案:

没有答案