Is it possible to draw nonantialiased lines with Juce and how? Maybe with some tweaks/hacks in the library code?
For god’s sake, why??? Are you too young to remember how crappy the UIs looked in the 1990s?
No, I remember that, but sometimes they are really useful. I need it to draw envelopes in my app and I definitely more like to see nonantialiased envelopes instead of aliased. You can take a look at Native Instruments’ synths’ envelopes (FM7 and Absynth for example), which are often nonantialiased, to get what I mean. This would be also more CPU friendly to draw many of them simultaneously, right?
The CPU difference would be unmeasurably small, that’s certainly not an excuse. (And I bet the only reason NI use aliased lines is because whatever VSTGUI or whatever toolkit they’re using doesn’t provide anything better!)
Personally, I’d draw an envelope as a solid block (sort of like the top half of a waveform display), using Graphics::drawVerticalLine to give their height sub-pixel accuracy - then even very shallow gradients will look perfect.
Maybe I’ll have some cases in future where solid envelopes will fit perfectly, but currently I need just simple line-based envelopes with no antialiasing, which sometimes make them look just bad. For example, draw a long horizontal line with only a single pixel difference in y-coordinates for the start and end point. The antialiased line looks amorphous and obviously worse here than usual. This is only a single example. Sometimes you draw an envelope with great precise, tracking every pixel of it and with simple sharp lines this is easier and more comfortable.
So, is it possible to have nonantialiased lines with Juce or not?
Of course it’s possible, but you’ll need to write your own bresenham function to do it.
So, I can’t just somehow turn off antialiasing in Juce? Okay, this is what I asked for.
Btw, this would be a cool feature to add in future versions. Antialiasing is really an improvement that doesn’t increase universality of graphic stuff. It even decreases it.
Jules is very angry with the antialiasing question … sure !
But Jules is right, because you need to understand that it’s not a simple question of flag (AA on / AA off). And so, you can easily wrote you’re own functions by using some simple algorithm you can find on the web.
Basically, you’ve a setPixel(int x, int y) method in the Graphics class. But it’s better to use the base class LowLevelGraphicsContext and write your own low level class. After that, you can easily use your context with the Image classe. Something like that :
Image img (Image::ARGB, width, height, true);
Now you can use normally the Graphics class.
For exemple, i’ve create my own AGG low level context and benefit of better rendering than JUCE at very small size. In other conditions, the optimization of JUCE is better than a not optimized AGG basic templates. So, I use a hybrid renderer to switch between the two when it’s necessary.
Screenshot of extreme small drawing using AGG at graphics renderer with JUCE:
draw and image with gimp and load it/draw it, it’s not that big a deal i thinl and i guess it’s simpler.