On 03. 05. 23 1:04, Matan wrote:
> Hi,
>
> Just as part of easing into pyglet and opengl, I am wondering if anyone
> can explain the following line of code:
>
>
https://github.com/pyglet/pyglet/blob/5bc0f80e0446bc4ebb2b381370802f60320c0d8a/pyglet/shapes.py#L1178
>
> Where it seems like 2 of the 4 corners of the rectangle repeat on the
> array. I just wanted to experiment making a rectangle shape with rounded
> corners by using bezier curves on the corners and would be happy to
> learn why opengl is being sent 6 points here.
A rectangle is made of two triangles:
D--C
| /|
|/ |
A--B
The vertex list has 3 points for each triangle: A,B,C, A,C,D.
If you're just starting out, I recommend trying a straight-edged shape
(a trapezoid, for example) before moving on to curved corners :)
> Also in case you have any thoughts or suggestions about sizing such a
> rectangle to wrap around text such that adjusting the edges of the box
> to fully contain the text glyphs (or sizing the glyphs to match the size
> of the box can be accomplished). This is towards making text areas
> nicely surrounded by a shape. The current button implementation under
> `gui` seems to use an image instead.
Look at TextLayout's content_width and content_height:
https://pyglet.readthedocs.io/en/latest/modules/text/layout.html#pyglet.text.layout.TextLayout
Classes like Label inherit these from TextLayout.