Franco Cortes
Franco Cortes

Reputation: 35

Direct2D Coordinate erro

I was doing a test program with direct2d to show lines, however I noticed a little detail and that is that when I tell direct2d to draw a dotted line (100,200) and (500,200), direct2d really isn't drawing the beginning of the line at the point (100,200), but it draws it one pixel less, that is, it coordinates at the coordinate (100,99). Does anyone know why this is? I checked this detail using direct2d without antialiasing mode and showing in the debug output the mouse coordinates.

Upvotes: 0

Views: 135

Answers (1)

Strive Sun
Strive Sun

Reputation: 6289

This is caused by Direct2D's own design.

To be precise, the coordinates of the line are from (99.5, 199.5) - (500.5, 200.5).

And @Rick Brewster's answer has explained these.

When you give it a pixel coordinate such as (100, 120), that refers to the top and left corner of the pixel element that spans from pixel coordinates (100, 120) to (101, 121) (top/left are inclusive, right/bottom are exclusive). Since it's a straight horizontal line you are effectively getting a filled rectangle from (99.5, 119.5) - (300.5, 120.5).

So if you want to draw a line from that covers the pixels (100, 200) to (500, 200), you can use aliased rendering or use half-pixel offsets.

Upvotes: 2

Related Questions