D3D11: How to draw a simple pixel aligned line?

后端 未结 3 1288
醉梦人生
醉梦人生 2021-01-05 07:50

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

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-05 08:29

    According to the rasterisation rules (link in the question above) I might have found a solution that should work:

    1. sort the vertices StartX < EndX and StartY < EndY
    2. add (0.5/0.5) to the start vertex (as i did before) to move the vertex to the center of the pixel
    3. add (1.0/1.0) to the end vertex to move the vertex to the lower right corner

    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.

提交回复
热议问题