Pixel perfect Graphics drawing

Does anyone know how to disable antialiasing when drawing on a Graphics object? For example if I draw a line (lineTo) it is aliased and in this particular case I would prefer it be pixel perfect. I have tried all the various settings including snapping, smoothing, quality, shaders, etc. I went digging into the OpenGL code to see where the draw commands are happening but couldn’t really determine exactly where they occur so I could compare to suggestions I found online about how to draw without aliasing to ensure my settings are actually being used.

I also tried drawing the Graphics to a BitmapData/Bitmap with a low stage quality and pixel snapping but it is still aliased.

I have tried just about everything I can think of short of drawing pixels directly to an image using various pixel perfect drawing algorithms, any help would be greatly appreciated. Hopefully I am missing something obvious.

The Graphics API wasn’t really designed for drawing without anti-aliasing. You haven’t missed any settings to disable it.

I bet you could make a filter that results in the desired effect. Check out the Heroku Shaders demo. I discussed this on the forum here.

Seems like this might do it: (Shader Library) Pixelation Post Processing Effect (GLSL) | Geeks3D

For “pixel perfect” I would rather use the bitmap/bitmapdata combo “openfl.display.BitmapData - OpenFL API Reference

openfl.display.BitmapData - OpenFL API Reference
openfl.display.BitmapData - OpenFL API Reference
openfl.display.BitmapData - OpenFL API Reference
openfl.display.BitmapData - OpenFL API Reference

Alternatively, I guess you can eventually hack your way with “openfl.display.Graphics - OpenFL API Reference” if it’s only one line… But well, yeah, that’s what it is… Hackish.

Dec '23
1 year later

Wanted to bump this and see if there is any actual solution for this now since I originally ran into this issue. I found a “workaround” for this previous problem but would love to have a proper solution now. Tried various tips from all the posts and code examples but still can’t make it work. Anything besides just drawing pixels directly myself to a bitmap data?

Eh… I guess to this day it’s still BitmapData or btfo…

Just out of curiosity how does the Graphics API achieve AA? I went looking through the code and didn’t see any of the usual approaches. I noticed the SDLWindow does set the SDL_GL_MULTISAMPLEBUFFERS but then I don’t see any calls that would suggest it is using the multisampled texture in OpenGL. I didn’t see any shader code that would seem to do it either. Hopefully I am not missing something obvious because I am not all that well versed in OpenGL rendering beyond the basics.

Much of our implementation for Graphics drawing is done in software using Cairo (native) or Canvas (HTML5). There are a few Graphics methods that can be done fully in hardware, but most is software only. So it would be in the code that deals with Cairo or Canvas, depending on which target you are using.