I tried to draw a line between two vertices with D3D11. I have some experiences in D3D9 and D3D11, but it seems to be a problem in D3D11 to draw a line, which starts in one given pixel and ends in an other.
What I did:
I added 0.5f to the pixel coordinates of each vertex to fit the texel-/pixel coordinate system (I read the Microsoft pages to the differeces between D3D9 and D3D11 coordinate systems):
f32 fOff = 0.5f; ColoredVertex newVertices[2] = { { D3DXVECTOR3(fStartX + fOff, fStartY + fOff,0), vecColorRGB }, { D3DXVECTOR3(fEndX + fOff, fEndY + fOff,0), vecColorRGB } };
Generated a ortho projection matrix to fit the render target:
D3DXMatrixOrthoOffCenterLH(&MatrixOrthoProj,0.0f,(f32)uRTWidth,0.0f,(f32)uRTHeight,0.0f,1.0f); D3DXMatrixTranspose(&cbConstant.m_matOrthoProjection,&MatrixOrthoProj);
Set RasterizerState, BlendState, Viewport, ...
Problem: The Line seems to be one pixel to short. It starts in the given pixel coordinate an fits it perfect. The direction of the line looks correct, but the pixel where I want the line to end is still not colored. It looks like the line is just one pixel to short...
Is the any tutorial explaining this problem or does anybody have the same problem? As I remember it wasn't as difficult in D3D9.
Please ask if you need further information.
Thanks, Stefan
EDIT: found the rasterization rules for d3d10 (should be the same for d3d11): http://msdn.microsoft.com/en-us/library/cc627092%28v=vs.85%29.aspx#Line_1
I hope this will help me understanding...
According to the rasterisation rules (link in the question above) I might have found a solution that should work:
This is needed to tell the rasterizer that the last pixel of the line should be drawn.
f32 fXStartOff = 0.5f;
f32 fYStartOff = 0.5f;
f32 fXEndOff = 1.0f;
f32 fYEndOff = 1.0f;
ColoredVertex newVertices[2] =
{
{ D3DXVECTOR3((f32)fStartX + fXStartOff, (f32)fStartY + fYStartOff,0), vecColorRGB },
{ D3DXVECTOR3((f32)fEndX + fXEndOff , (f32)fEndY + fYEndOff,0), vecColorRGB }
};
If you know a better solution, please let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With