pyglet doesn't draw on first iteration

105 views
Skip to first unread message

anatoly techtonik

unread,
Dec 24, 2012, 10:30:38 AM12/24/12
to pyglet...@googlegroups.com
Why pyglet doesn't display label on the first iteration?
On my Vista machine it is visible only after I hit Enter the second time.

import pyglet

wincfg = pyglet.gl.Config(double_buffer=False)
window = pyglet.window.Window(config=wincfg)

label = pyglet.text.Label('[]',
                          font_name='Lucida Console',
                          font_size=14,
                          x=10, y=10)
label.draw()
pyglet.gl.glFlush()
window.dispatch_events()

raw_input("Done.")

label.draw()
pyglet.gl.glFlush()
window.dispatch_events()

raw_input("Done.")

Anonymouse

unread,
Dec 24, 2012, 4:06:58 PM12/24/12
to pyglet...@googlegroups.com
I can't be sure, but I think it's because you need to dispatch_events() once before drawing anything so that an on_resize event gets handled, which will set the projection matrix for the window. If you draw before it, the projection matrix is probably such that you can't see wherever the text gets drawn. So call window.dispatch_events() once before drawing and it does display.

--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pyglet-users/-/Tr5ouPliAKMJ.
To post to this group, send email to pyglet...@googlegroups.com.
To unsubscribe from this group, send email to pyglet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.

anatoly techtonik

unread,
Dec 24, 2012, 4:28:25 PM12/24/12
to pyglet...@googlegroups.com
Doesn't help. Here is the script with added event logger for the window. On my machine the output is:

>py testdraw.py
on_activate()
on_show()
on_resize(width=640, height=480)
on_expose()
Before Label draw.
on_deactivate()
After.
Done.



import pyglet

wincfg = pyglet.gl.Config(double_buffer=False)
window = pyglet.window.Window(config=wincfg)
window.push_handlers(pyglet.window.event.WindowEventLogger())
window.dispatch_events()

raw_input("Before Label draw.")

label = pyglet.text.Label('[]',
                          font_name='Lucida Console',
                          font_size=14,
                          x=10, y=10)
label.draw()
pyglet.gl.glFlush()
window.dispatch_events()

raw_input("After.")

label.draw()
pyglet.gl.glFlush()
window.dispatch_events()

raw_input("Done.")

Anonymouse

unread,
Dec 24, 2012, 4:56:58 PM12/24/12
to pyglet...@googlegroups.com
You mean it doesn't draw after you press enter for the first time? Because it does for me.

anatoly techtonik

unread,
Dec 24, 2012, 5:09:42 PM12/24/12
to pyglet...@googlegroups.com
Exactly. It draws only after "After." is displayed and I press Enter.
Are you on a Windows Vista too?

Anonymouse

unread,
Dec 27, 2012, 12:44:12 PM12/27/12
to pyglet...@googlegroups.com
I'm on linux (ubuntu 12.10). Maybe try adding a window.flip() after label.draw()?

anatoly techtonik

unread,
Dec 28, 2012, 3:58:59 PM12/28/12
to pyglet...@googlegroups.com
I'm afraid that without window.flip() may break pyglet on other platforms with pyglet.gl.Config(double_buffer=False). Does it work the same way for Linux? I think that for the proper test another label should be drawn after the "After." string is printed.
Message has been deleted

anatoly techtonik

unread,
Dec 29, 2012, 2:26:26 AM12/29/12
to pyglet...@googlegroups.com
Updated test with .flip()  Still fails on Windows to draw after the first draw/flush/dispatch. Still work ok on Linux no matter if flip() is used or not. pyglet failed under Wine so no way to test without Windows system I am afraid.
stepdraw.py
Reply all
Reply to author
Forward
0 new messages