Brilliant - all very useful advice. Using the r119 everything is working fine.

Cheers,

Andrew

On Sat, Jun 14, 2008 at 6:32 PM, Alex Holkner <[EMAIL PROTECTED]> wrote:
>
> On Fri, Jun 13, 2008 at 6:02 PM, Andrew Charles <[EMAIL PROTECTED]> wrote:
>> I seem to be leaking memory when I draw text to a window. Or else I'm
>> doing it wrong. I'm running Leopard on intel hardware, in case that's
>> relevant.
>
> Thanks, I've fixed this in r2117.
>
> There's a couple of issues in your test case that nicely demonstrate
> the problems people will encounter when migrating from pyglet 1.0 to
> 1.1.  I thought I'd point these out, though I'm sure you're probably
> aware of many/all of them, because other list readers can benefit:
>
>>
>> from pyglet import window
>> from pyglet import font
>> from pyglet import clock
>> from pyglet import app
>
> It's preferable now to just `import pyglet` (this wasn't supported in
> pyglet 1.0).  It's cleaner, and frees up useful variable names like
> "window" and "image" for your own use.
>
>> ft = font.load('Arial',12)
>> txt = font.Text(ft,"Hello pyglet")
>> txt.color = (1.0, 0.0, 0.0, 1.0)
>
> pyglet.font.Text is deprecated in pyglet 1.0 in favour of the new
> pyglet.text.Label, which has more features and is faster.  The
> equivalent for the above Text is:
>
> txt = pyglet.text.Label('Hello pyglet', font_name='Arial',
> font_size=12, color=(255, 0, 0, 255))
>
> The only major adjustment you'll need to get used to is specifying
> colors in range 0-255 instead of 0-1.
>
>> def update(dt):
>>    glClear(GL_COLOR_BUFFER_BIT)
>>    txt = font.Text(ft,"I'm melting!")
>>    txt.draw()
>
> When using the pyglet.app.run() loop (which you are, further down),
> you are not allowed to do any drawing outside of the Window.on_draw
> event.  The reason is that your drawing will not be made to any
> particular GL context, or synchronised with the buffer flips.  Replace
> the above with:
>
> @win.event
> def on_draw():
>   glClear(...)
>   txt = ...
>   txt.draw()
>
> def update(dt):
>   pass
>
> Note that the update function is still needed so that something is
> scheduled on the clock (unless you don't actually have anything to
> update, as in this example, if it weren't contrived to show the memory
> leak).
>
> The biggest performance problem your example suffers from is in
> recreating the Font object each frame (Font is now implemented in
> terms of Label, and construction is quite expensive).  Try to create
> the Font (or Label) objects less frequently, and set the text on the
> object to change the display:
>
> @win.event
> def on_draw():
>   win.clear()
>   txt.text = "I'm melting!"
>   txt.draw()
>
> You could also change the text in the update function if you prefer.
>
> Cheers
> Alex.
>
> >
>

-------------------------
Andrew Charles
Centre for Australian Weather and Climate,
Australian Bureau of Meteorology.
Condensed Matter Theory Group,
RMIT University.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to