Reputation: 1626
I've read the online docs about DirectX rasterization rules but I still can't understand why doesn't this code produce anything visible on the screen?
target->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
target->DrawLine(D2D1::Point2F(0.f, 0.f), D2D1::Point2F(10.f, 0.f), redBrush, 1.f);
Of course, if I change y from 0.0f to 1.0f for both line points I get a visible horizontal line at the top-left side of the Window client area but I would like to understand what principles are involved here. I couldn't figure them out from available documentation.
Upvotes: 3
Views: 1177
Reputation: 27460
You should draw your line "in the middle of the pixel":
target->DrawLine(D2D1::Point2F(0.0f, 0.5f), D2D1::Point2F(10.f, 0.5f), redBrush, 1.f);
Otherwise, if you don't use antialiasing, your line can be drawn on either side 0/0...10/0 line. In your case it gets drawn outside of window canvas.
Note that pixel on screen is actually a rectangle with coordinates D2D1::Point2F(0.0f, 0.0f)
to D2D1::Point2F(1.0f, 1.0f)
.
And D2D1::Point2F(0.5f, 0.5f)
is the center of that rectangle. If you draw 1x1 rectangle around that coordinate it will cover the pixel exactly.
Upvotes: 2