void cRender::DrawLine(Vec2 start, Vec2 end, DWORD color)
{
if (this->m_pDeviceContext == NULL)
return;
UINT viewportNumber = 1;
D3D11_VIEWPORT vp;
this->m_pDeviceContext->RSGetViewports(&viewportNumber, &vp);
float xx0 = 2.0f * (start.x - 0.5f) / vp.Width - 1.0f;
float yy0 = 1.0f - 2.0f * (start.y - 0.5f) / vp.Height;
float xx1 = 2.0f * (end.x - 0.5f) / vp.Width - 1.0f;
float yy1 = 1.0f - 2.0f * (end.y - 0.5f) / vp.Height;
COLOR_VERTEX* v = NULL;
D3D11_MAPPED_SUBRESOURCE mapData;
if (FAILED(this->m_pDeviceContext->Map(this->m_pVertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &mapData)))
return;
v = (COLOR_VERTEX*)mapData.pData;
v[0] = COLOR_VERTEX{ D3DXVECTOR3(xx0, yy0, 0), D3DXCOLOR(color) };//
v[1] = COLOR_VERTEX{ D3DXVECTOR3(xx1, yy1, 0), D3DXCOLOR(color) };//
this->m_pDeviceContext->Unmap(this->m_pVertexBuffer, NULL);
UINT Stride = sizeof(COLOR_VERTEX);
UINT Offset = 0;
this->m_pDeviceContext->IASetVertexBuffers(0, 1, &this->m_pVertexBuffer, &Stride, &Offset);
this->m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP);
this->m_pDeviceContext->IASetInputLayout(this->m_pInputLayout);
this->m_pDeviceContext->VSSetShader(this->m_pVertexShader, 0, 0);
this->m_pDeviceContext->PSSetShader(this->m_pPixelShader, 0, 0);
this->m_pDeviceContext->GSSetShader(NULL, 0, 0);
this->m_pDeviceContext->Draw(2, 0);
}