2015-07-11 85 views
0

我想写一个宽度可变的一般D3D11线画。它的工作原理,但只有当线约45度。然后就像图片中显示的那样“分手”。忽略模型和三角形....D3D线画分成三角形 - 几乎 - 作品,但需要提示

Screenshot

首先,呼叫试图绘制线条,非常基本的:

g_UILineShader.SetActive(); 
for (float x = 0; x < 800; x = x + 10) 
{ 
    g_UILineShader.DrawUILine(pd3dDevice, x, 0, 800-x, 600, 3, XMFLOAT4(1.0f, 1.0f, 0.0f, 1.0f)); 
} 
g_UILineShader.Render(pd3dDevice); 

少不了为三角形列表渲染代码:

HRESULT Render(ID3D11Device * pd3dDevice) 
{ 
    auto devcon = DXUTGetD3D11DeviceContext(); 

    // Copy all of the vertices in the array to the vertex buffer 

    D3D11_MAPPED_SUBRESOURCE ms; 
    devcon->Map(_pVertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);  // map the buffer 
    memcpy(ms.pData, &_vertices[0], _vertices.size() * sizeof(UILineVertex)); // copy the data 
    devcon->Unmap(_pVertexBuffer, NULL);          // unmap the buffer 

    // Set the vertex buffer on the device context 
    UINT stride = sizeof(UILineVertex); 
    UINT offset = 0; 
    ID3D11Buffer * pBuffer = _pVertexBuffer; 
    devcon->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset); 

    // Select which primtive type we are using 
    devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 

    // Draw the vertex buffer to the back buffer 
    devcon->Draw(_vertices.size(), 0); 

    // Once rendered we can discard all of the vertex data 
    _vertices.clear(); 
    return S_OK; 
} 

任何人都可以发现一个错误或根本的误解吗?如果有更好的方法在屏幕空间中绘制允许不同角度和厚度的线条,我宁愿不重新发明轮子,但还没有碰到过。

着色器看起来很好,只是将屏幕空间坐标除以屏幕尺寸,使其进入X和Y尺寸的-1,+ 1空间。我不认为法线是重要的,或者他们可以吗?

任何帮助,将不胜感激!

回答

0

为了防止有人碰到类似的东西,它变成了我的光栅器状态;剔除模式与我缠绕三角形的方式相反。 “Yay​​”用于VS2013图形调试器。