When I draw a diagonal line in a DC buffer, it gets drawn differently
between Windows and Linux (GTK3):
- In Windows the line is jagged, with sharply defined pixels.
- In Linux, the line is dithered, with diffused pixel colors around it.
See attached example.
That's called "anti-aliasing". The answer is, it depends. wx simply
calls the underlying graphics APIs. GDI on Windows does not do
anti-aliasing. The graphics library on OSX does. On Windows, you can
use wx.GCDC instead of of wx.PaintDC; that uses GDI+ to do drawing,
which does support anti-aliasing.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Thanks for the quick reply!
I wasn’t aware of the different APIs.
I actually do NOT want anti-aliasing for drawings, but do for fonts.
My Windows program, using the DC API, provides just that.
I’m now porting the program to Linux, and wish to keep the “no anti-aliasing” look.
Is there a way to disable anti-aliasing on Linux, through the DC API?
I actually do NOT want anti-aliasing for drawings, but do for fonts.
My Windows program, using the DC API, provides just that.
I'm now porting the program to Linux, and wish to keep the "no
anti-aliasing" look.
Is there a way to disable anti-aliasing on Linux, through the DC API?
It's more than just different APIs. I ran your test on my Ubuntu 16.04
system. I ran it on the console, I ran it over a network to Xming on my
Windows box, and I ran it in a VNC server, and in all three cases, the
line was not anti-aliased. I'm not exactly sure who is doing the
anti-aliasing in your case.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Thanks for trying, and I think I figured it out.
When using DC, rendering is based on OS defaults: Windows 7 no anti-aliasing, Fedora anti-aliasing.
But GCDC makes it possible to use 2 simultaneous APIs, DC and GraphicsContext.
GCDC’s API is DC’s API.
But, GCDC provides access to its GraphicsContext object via GetGraphicsContext(), which lets me control anti-aliasing.
Now I’m able to control anti-aliasing both on Windows 7 and Fedora 24 via that function, while still drawing using the DC API as before.
See attached code. Command line argument: 0 no anti-aliasing, 1 anti-aliasing
I just ran my code on Ubuntu 16.04 LTS (which uses GTK2).
Indeed, by default there is no anti-aliasing to the drawn line, but the text is anti-aliased.
On Fedora 24 (which uses GTK3) anti-aliasing is enabled by default for both, line and text.
At least now I’m able to control whether anti-aliasing is active, using the same code on all 3 platforms (Windows, Ubuntu, Fedora).
Thanks Tim for pointing me in the right direction!