Shape drawing problem
kayon opened this issue · 7 comments
Circle border
common.Circle{ BorderWidth: 1, BorderColor: color.Black, }
The border drawing is abnormal. Fill color cannot be transparent. The same goes for running demos/shapes.
Circle Arc
common.Circle{ Arc: 180 }
Text
When there are Chinese characters in the string.
index out of range ... common.(*textShader).generateBufferContent
Hello! Thanks for looking into all these, I've been meaning to test out edge cases like these but haven't really had much time as of late.
The circle color handling transparency should be a quick fix, just need to update the shader to accept alpha values. The other two problems could be a bit tricker. I think they're both floating-point errors, where 180 somewhere along the line of floating-point arithmetic becomes 180.1 or some such. I'll probably try rounding arc angles to whole degrees or something similar.
Just been looking through the files for this and I think the issue is coming from lines 273-305 of engo/common/render_shaders_shapes.go
Looks like the circle is being drawn full size in the right place for the border, then drawn again but offset left and up by border width, rather than in the same position but 2*borderwidth smaller.
I found the offset by putting it in the same position as a rectangle of the same width/height to see which part of the circle was wrong.
Just managed to fix the circle border issue.
Transparency isn't working with borders, it hides the main layer but the border layer still fills that space. The border code needs tweaking to only occupy the area around the rest of the shape.
Cool beans. The issue with the other two is a bit more challenging sadly. One problem is the number of triangles we're making the circles out of is 300, which doesn't divide by 180 nicely, so the problem is you'll never get nice flat stuff like that this way. I don't like that, so I think upping the triangles to 360 would be a good idea. That way every whole angle gets a triangle.
Drawing a transparent circle isn't going to be possible the way it's currently done. Right now it's drawing two circles, the border and then the normal circle on top of it. If you make the normal circle transparent, you'll see the border circle underneath! So we're going to have to either decide transparent circles with borders aren't supported, or draw them using another method.
Okay didn't realise you were using triangles, to be honest, interesting! But yeah I was seeing the issue with the two circles... shame it won't create nice edges, because it would be great if we could just get it to draw between the edge and edge-borderwidth rather than edge and center.