# Pyglet Layout won't render?

Here's some sample code I copy pasted to try and get a Pyglet layout to work. I just get a blank screen. Every time I try to write my own code based on the docs or copy/paste some example code it just will not render the layout.

Interwebs reveal a few other people with this issue but no answers given.

Labels seem to work fine although even they are quirky.

import pyglet

white = (255, 255, 255, 255)

window = pyglet.window.Window(width=200, height=200, caption='Text layout')

# document
document = pyglet.text.decode_text(
('Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! '
'Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World!'))
document.set_style(start=0, end=0, attributes=dict(font_size=12, color=white))

# text layout
text_layout = pyglet.text.layout.TextLayout(document=document,
width=window.width,
height=window.height,
multiline=True,
wrap_lines=True)
text_layout.color = (.5,.5,.5,1.0)

@window.event
def on_draw():
window.clear()
text_layout.draw()

pyglet.app.run()


It turns out I need to declare a font type in the attributes of the document.

font_name="Times New Roman"


to the attributes dictionary and voila. Frustrating that all the examples I found did not explicitly declare a font type, and yet for me this seems to be a requirement. I was just about to give up and roll my own text renderer.

• The lack of community support for this otherwise nice framework, has made me decide to stop using Pyglet altogether. Far less frustrating(and more educational) to just roll my own text renderer in PyOpenGL than to try and guess my way through the various bugs I'm getting. I could read the documentation more thoroughly but even then there is no guarantee I'll find my answer. I did like the look of the API for rendering text but its just not worth the headaches. – Curtis Sherwood Jun 25 '17 at 4:03