On 12/30/07, Mike Lawrence <[EMAIL PROTECTED]> wrote: > > Hi all, > > The code below demonstrates the problem. I'm running pyglet 1.0beta3 > with python 2.5 on OS 10.5.1.
If anyone's keen to become a pyglet expert, this is a great troubleshooting problem to sink your teeth into. Don't spoil the challenge if you want to figure it out yourself ;-) . . . (spoiler) . . . > def show_message(win,text,my_font): > win.dispatch_events() > win.clear() > rendered_text = font.Text(my_font,text,win.width/2,win.height/2) > rendered_text.draw() > win.flip() > > > def draw_cross(win,size,thickness,color): > win.clear() > aspect=win.height/float(win.width) > glColor3f(color[0],color[1],color[2]) > glRectf(-aspect*size*thickness/2,-size/2,aspect*size*thickness/2,size/ > 2) > glRectf(-aspect*size/2,-size*thickness/2,aspect*size/2,size*thickness/ > 2) > win.flip() > > > ######## > #Demonstrate the problem > ######## > > #I can draw a cross... > draw_cross(win,.5,.2,[.5,.5,.5]) > > #but when I write some text to the screen... > show_message(win,'Ahoy there!',my_font) > > #I can no longer draw the cross... > draw_cross(win,.5,.2,[.5,.5,.5]) > > #but I can draw more text... > show_message(win,'Arrrgh!',my_font) The problem has nothing to do with text rendering, just the peculiar arrangement of your code. Note that show_message() begins with a dispatch_events, but draw_cross() does not. The first draw_cross() invocation therefore runs before any dispatch_events() calls. Why does this matter, since you're not responding to any events? There is one important event that is triggered when the window is first created, but queued until the first dispatch_events() is called: on_resize. There is a default handler on Window that handles this by setting up an orthographic projection in window coordinates. Before this handler is called, the default OpenGL projection is resident, which is a normalized "unit" cube ([-1, 1] on all axes). So, the first draw_cross() invocation correctly renders into this unit cube. The show_message() invocation then causes the on_resize event to be handled, which sets up the window-space orthographic projection that pyglet.font.Text expects. Finally, the next draw_cross() doesn't appear to draw anything because it's now drawing into window-space coordinates, and the cross will be smaller than a pixel. The moral: stick to the recommended event loop even for simple test programs, unless you have a very specific need not to. And unless you're providing your own on_resize handler, you must draw everything in window-space coordinates. Cheers, Alex. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
