On Feb 28, 4:00 pm, Richard Jones <[email protected]> wrote:
> On Sun, Feb 27, 2011 at 6:10 AM, une <[email protected]> wrote:
> > I draw some quads on to the screen with pyglet.graphics.draw, and each
> > frame I change the color slightly to make it look as though they are
> > 'fading in'. However, while this is happening, pyglet is only
> > rendering at about 4 FPS, causing it to look . It will render faster
> > if I wiggle my mouse around in the window, which makes me think that
> > it's a performance optimization. Is there any way I can get around
> > this?
>
> Yes, it is.
>
> pyglet has a facility for calling functions
> periodically:http://pyglet.org/doc/programming_guide/calling_functions_periodicall...
>
> Also, if you must run your own event handling in a thread then you may
> set window.invalid to True, which will force the pyglet event loop to
> redraw. It's probably not thread-safe though.
>
> Richard
Switching to schedule_interval fixed the problem. Thanks for all the
help.
For the curious, the above example code, fixed, follows:
import pyglet
window = pyglet.window.Window()
fps = pyglet.clock.ClockDisplay()
color = (0, 0, 0)
def fade_in(dt):
global color
c = color[0] + 10
color = (c, c, c)
if c >= 250: pyglet.clock.unschedule(fade_in)
def on_draw():
global color
window.clear()
pyglet.graphics.draw(4, pyglet.gl.GL_QUADS,
('v2i', (0, 0,
100, 0,
100, 100,
0, 100)),
('c3B', color * 4))
fps.draw()
window.on_draw = on_draw
pyglet.clock.schedule_interval(fade_in, .1)
pyglet.app.run()
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en.