Hello. I've written a simple image viewer to present some slides. It is a mere improvement over the image display example, it accepts a list of files and allows changing from one to another.
Pressing key 'e' moves forward, key 'w' backwards, 'q' quits the program, and 'f' switches between windowed and full screen modes. When you press the forward/backwards keys, before actually displaying the next image the program draws a black cross on the screen to notify the user that the key event has been acknowledged, and it is just taking some time to load and process the file. For tests I usually load a large directory of jpg files and press continuously the 'e' key without releasing it to see how long it takes to slide through all the images. This all works ok in windowed mode. However, the problem is weird flicker in full screen mode, running on a macbook. What I see in windowed mode is the first image, then I quickly see the others with the black cross, since basically the program is consuming 100% cpu processing images. But everything works fine, no flicker or image tearing. In full screen mode what I see is the first image of the set, and then madly flickering the other images. My personal guess on the issue is that either flipping or vsyncing doesn't work on macbooks full screen. Can somebody try the example on their computers and see if they get the same visual result? Here's the attached example, which I run like './flicker *.jpg'. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
#!/usr/bin/env python # vim:tabstop=4 shiftwidth=4 encoding=utf-8 import os import os.path import pyglet import sys from pyglet.gl import * file_list = [] pointer = 0 gFull_screen = False WINDOW_W, WINDOW_H = 640, 480 ON_TEXT_FORWARD = u"e" ON_TEXT_BACKWARD = u"w" ON_TEXT_QUIT = u"q" ON_TEXT_FULLSCREEN = u"f" # Create main window. window = pyglet.window.Window(visible = False, resizable = True) window.loaded_texture = None window.background = None @window.event def on_draw(): glColor3f(1, 1, 1) if not window.background: checks = pyglet.image.create(32, 32, pyglet.image.CheckerImagePattern()) window.background = \ pyglet.image.TileableTexture.create_for_image(checks) window.background.blit_tiled(0, 0, 0, window.width, window.height) texture = window.loaded_texture if not texture: return # Calculate correct proportional scale ratio. max_w, max_h = window.width, window.height w, h = texture.width, texture.height factor = max_w / float(w) w *= factor h *= factor if h > max_h: factor = max_h / float(h) w *= factor h *= factor x = int((max_w - w) / 2.0) y = int((max_h - h) / 2.0) texture.blit(x, y, width = w, height = h) def draw_cross(): glBegin(GL_LINES) glColor3f(0, 0, 0) glVertex2f(0, 0) glVertex2f(window.width, window.height) glVertex2f(0, window.height) glVertex2f(window.width, 0) glEnd() @window.event def on_text(text): global pointer global gFull_screen refresh = reload = False if ON_TEXT_FORWARD == text: new_pointer = min(pointer + 1, len(file_list) - 1) assert new_pointer >= 0 if new_pointer != pointer: reload = True pointer = new_pointer if ON_TEXT_BACKWARD == text: new_pointer = max(pointer - 1, 0) if new_pointer != pointer: reload = True pointer = new_pointer if ON_TEXT_QUIT == text.lower(): sys.exit(0) if ON_TEXT_FULLSCREEN == text: window.set_fullscreen(gFull_screen) gFull_screen = not gFull_screen refresh = True if reload: draw_cross() # TODO: Don't we have too many flips here? window.flip() load(pointer) if refresh: window.flip() def load(position): """f(int) -> None Loads into window.loaded_texture the specified position of the image list. """ global pointer try: img = pyglet.image.load(file_list[position]) window.loaded_texture = img.get_texture(rectangle = True) except Exception, e: window.loaded_texture = None pointer = position def pyglet_main(): # Enable alpha blending, required for image.blit. glEnable(GL_TEXTURE_2D) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) load(0) window.width = WINDOW_W window.height = WINDOW_H window.set_visible() pyglet.app.run() def main(): file_list.extend(sys.argv[1:]) if len(file_list) < 1: print "Need to specify input files" sys.exit(1) pyglet_main() if "__main__" == __name__: main()
