Can't draw() sprites in pyglet

。_饼干妹妹 提交于 2019-12-05 12:57:36
Eric

Assuming you and your friends have ATI graphics cards:

Sprite.draw() uses the v2i format and VertexDomain.draw() internally. For some reason this combination doesn't work on Windows Vista/7 Catalyst drivers 11.9 and above, and consequently Sprite drawing fails as well. See also: pyglet vertex list not rendered (AMD driver?)

There is a pyglet issue you might want to follow: http://code.google.com/p/pyglet/issues/detail?id=544

Your options for the moment seem to be either to patch pyglet.sprite.Sprite as mentioned in the third comment on that issue or downgrade your video driver.

Update: No need to patch Sprite or downgrade your video driver. This problem seems to be fixed with Catalyst 12.4 (video driver 8.961.0.0).

The sprite is getting garbage collected because you don't hold a reference to it. Do this:

sprite = pyglet.sprite.Sprite(image, x=200, y=300, batch=batch)

For what it's worth, I prefer using a subclass of Window, like this: (this code works for me too)

import pyglet

class Window(pyglet.window.Window):
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        self.batch = pyglet.graphics.Batch()
        image = pyglet.resource.image('hextile.png')
        self.sprite = pyglet.sprite.Sprite(image, batch=self.batch)
    def on_draw(self):
        self.clear()
        self.batch.draw()

def main():
    window = Window(width=640, height=480, caption='Pyglet')
    pyglet.app.run()

if __name__ == '__main__':
    main()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!