I've drawn a rectangle (4 line segments), but they're too thin. How can I change the thickness of each line?
The following example of mine gives me this:
if __name__ == '__main__':
app = App()
game_area = None
labels = [pyglet.text.Label("0"*8,
font_name = "Times New Roman",
font_size=18,
color = (255, 0, 0, 255),
x = app.width // 2,
y = app.height // 2 - n,
anchor_x = "center",
anchor_y = "center") for n in range(0, 100, 18)]
@app.event
def on_draw():
app.clear()
[label.draw() for label in labels]
pyglet.graphics.draw(4, pyglet.gl.GL_LINES,
("v2f", (0, 0, 0, app.height, app.width / 2, app.height, app.width / 2, 0))
)
pyglet.app.run()
You can change the width of lines by calling glLineWidth. This is accomplished through pyglet like so:
pyglet.gl.glLineWidth(desired_line_size)
If you require lines of varying thickness you'll have to call the function again with the new thickness before drawing each line. Otherwise, you can just set the thickness in your initialization and leave it be.
I've realized that actually I have to draw triangles in order to achieve "thickness":
def draw_game_area():
pyglet.graphics.draw(24, pyglet.gl.GL_TRIANGLES,
("v2f", (ORIGIN, ORIGIN, ORIGIN, app.height, LINE_SEGMENT_THICKNESS, ORIGIN,
ORIGIN, app.height, LINE_SEGMENT_THICKNESS, app.height, LINE_SEGMENT_THICKNESS, ORIGIN,
ORIGIN, ORIGIN, ORIGIN, LINE_SEGMENT_THICKNESS, app.width / 2, ORIGIN,
ORIGIN, LINE_SEGMENT_THICKNESS, app.width / 2, LINE_SEGMENT_THICKNESS, app.width / 2, ORIGIN,
app.width / 2 - LINE_SEGMENT_THICKNESS, app.height, app.width / 2, app.height, app.width / 2, ORIGIN,
app.width / 2 - LINE_SEGMENT_THICKNESS, app.height, app.width / 2, ORIGIN, app.width / 2 - LINE_SEGMENT_THICKNESS, ORIGIN,
ORIGIN, app.height, app.width / 2, app.height, app.width / 2, app.height - LINE_SEGMENT_THICKNESS,
ORIGIN, app.height, ORIGIN, app.height - LINE_SEGMENT_THICKNESS, app.width / 2, app.height - LINE_SEGMENT_THICKNESS))
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With