Question

I'm trying to blit some simple images, and learn to use ImageGrid and other functions, but this same error keeps popping up:

File "C:\Python27\lib\site-packages\pyglet\gl\lib.py", line 105, in errcheck
raise GLException(msg)
GLException: None

This is my code:

import pyglet
class test(pyglet.window.Window):
def __init__(self):
    super(game, self).__init__()
    img = pyglet.image.load('images/sprites.png')
    self.sprite = pyglet.resource.image('images/sprites.png')
    seq = pyglet.image.ImageGrid(img, 10, 9, 96, 96)
    self.sprite2 = pyglet.image.TextureGrid(seq)

def on_draw(self):
    self.sprite2.blit(25, 25, width=150, height=150)
Was it helpful?

Solution

Well, first off, your indentations are wrong.

I also see an error in line 4, which is that your call to super() should be:

super(test, self).__init__()

It's a bit counter-intuitive, but the first argument should be the name of this class, the one you are defining.

In line 5 you load an image into the variable img, but in line 6 you also load the same image from line 5 into a second variable, an instance variable named self.sprite. This instance variable is never used again. Line 6 is a waste.

To answer your actual question: I think your mistake is in how you're trying to define your on_draw event. You're overloading the pyglet.window.Window class and attempting to overload the on_draw event directly as a method, which is not how it's designed to work. Create a class to hold your image and create a decorator in your main .py file which pushes the draw event to the window.

import pyglet

class Test(object):
    def __init__(self):
        super(Test, self).__init__()
        img = pyglet.image.load('images/sprites.png')
        // Removed prior self.sprite, as it was unneeded.
        // Renamed instance variable below.
        seq = pyglet.image.ImageGrid(img, 10, 9, 96, 96)
        self.sprite = pyglet.image.TextureGrid(seq)

// No indentation, so this is not in the test class.
test = Test()
window = pyglet.window.Window()

@window.event
def on_draw():
    // Don't forget to clear the window first!
    test.clear()
    test.sprite.blit(25, 25, width=150, height=150)

if __name__ == '__main__':
    pyglet.app.run()

Try that. Your image will probably look kinda weird, though, because your blit call is changing the anchor point and stretching the image in both directions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top