jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
234 stars 40 forks source link

Drawing lines and rectangles #107

Open FraserElectronics opened 1 year ago

FraserElectronics commented 1 year ago

I would like to draw a one pixel width rectangle on my D2DControl surface using DrawRectangle with the default stroke width of 1. However, the rectangle is two pixels wide on my monitor and seems to be a blend of the foreground and background colours.

5

The line should be Red i.e. R:255,G:0,B:0 but you can see it is not. Two questions:

  1. How to I get a single pixel line (is this related to DPI as per my previous issues)?
  2. How to not blend the pen colour with the background colour?

Andy

drewnoakes commented 1 year ago

This Stack Overflow question might be helpful: https://stackoverflow.com/questions/10763762/pixels-in-direct2d

FraserElectronics commented 1 year ago

Yes, I suspected that this might be the case - thanks for the link 👍

Andy

jingwood commented 1 year ago

There are two issues in this case.

First, you have to configure your .NET application to allow the high DPI support accoding to this document.

Second, the current D2DControl can't calculate and set a correct DPI value for high DPI supported .NET application (a bug from d2dlib).

You can add a normal .NET control on your winform, and compare the rendering quality between normal .NET control and d2dlib as below. high-dpi-support-winform

FraserElectronics commented 1 year ago

@jingwood Are you saying that even if I configure my application to support high DPI I will still have a problem because of a bug in d2dlib?

Andy

FraserElectronics commented 1 year ago

Actually, I can answer that as I have followed the steps you link and it has made no change to the rendering on the D2DControl :-(

Andy

jingwood commented 1 year ago

Are you saying that even if I configure my application to support high DPI I will still have a problem because of a bug in d2dlib?

Yes, but it's another problem.

For the antialias, could you please post an image that shows how the normal .NET control is rendered like my above?

FraserElectronics commented 1 year ago

Do you mean something like this?

6

Andy

FraserElectronics commented 1 year ago

This is what it looks like if I remove all the suggestions from the link you mentioned.

7

Andy