fogleman / gg

Go Graphics - 2D rendering in Go with a simple API.
https://godoc.org/github.com/fogleman/gg
MIT License
4.42k stars 357 forks source link

Line width fine-control #35

Closed jdevelop closed 6 years ago

jdevelop commented 6 years ago

I am trying to create the bimaps, and looks like I can't have vertical or horizontal line of width of exactly 1 px. Is there any way of making the width "strict"?

fogleman commented 6 years ago

This is a common problem when using antialiasing renderers. The trick is to draw the line in the "middle" of a pixel, e.g. x = 0.5

I added an example to demonstrate:

https://github.com/fogleman/gg/blob/master/examples/crisp.go

jdevelop commented 6 years ago

Interesting, let me try :) Is there a way that it can work with fonts? I want to draw some stuff on a cheap 128x64 OLED display, currently any font if scaled down to 10px - is readable, but ugly. Seems to be the same problem?

fogleman commented 6 years ago

I wouldn't suggest vector fonts on such a display but rather some bitmap-based font.

jdevelop commented 6 years ago

Can gg.Context work with bitmap fonts?

fogleman commented 6 years ago

The default font is basicfont.Face7x13. Try rendering text without setting a new font.

fogleman commented 6 years ago

Should look something like this (zoomed in)

screen shot 2018-02-23 at 11 38 12 am

jdevelop commented 6 years ago

Perfect, that worked! Can I use other bitmap fonts?

fogleman commented 6 years ago

I think that's the only such font that's built in.

https://godoc.org/golang.org/x/image/font/basicfont

jdevelop commented 6 years ago

Oh, I see - looks like there're some ways to load the custom bitmaps. Thanks a lot :) I think this one can be closed.