Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading an image using Pyglet

I am playing around with pyglet 1.2alpha-1 and Python 3.3. I have the following (extremely simple) application and cannot figure out what my issue is:

import pyglet

window = pyglet.window.Window()
#image = pyglet.resource.image('img1.jpg')
image = pyglet.image.load('img1.jpg')
label = pyglet.text.Label('Hello, World!!',
                      font_name='Times New Roman',
                      font_size=36,
                      x=window.width//2, y=window.height//2,
                      anchor_x='center', anchor_y='center')

@window.event
def on_draw():
    window.clear()
    label.draw()
    #    image.blit(0,0)

pyglet.app.run()

With the above code, my text label will appear as long as image.blit(0, 0) is commented out. However, if I try to display the image, the program crashes with the following error:

  File "C:\Python33\lib\site-packages\pyglet\gl\lib.py", line 105, in errcheck
raise GLException(msg)
pyglet.gl.lib.GLException: b'invalid value'

I also get the above error if I try to use pyglet.resource.image instead of pyglet.image.load (the image and py file are in the same directory).

Any one know how I can fix this issue?

I am using Python 3.3, pyglet 1.2alpha-1, and Windows 8.

like image 241
Mike Caputo Avatar asked Oct 04 '22 14:10

Mike Caputo


2 Answers

The code -including the image.blit- runs fine for me. I'm using python 2.7.3, pyglet 1.1.4 There's nothing wrong with the code. You might consider trying other python and pyglet versions for the time being (until pyglet has a new stable release)

like image 121
Rolf Schorpion Avatar answered Oct 13 '22 11:10

Rolf Schorpion


This isn't a "fix", but might at least determine if it's fixable or not (mine was not). (From the Pyglet mailing group.)

You can verify whether the system does not even support Textures greater than 1024, by running this code (Python 3+):

from ctypes import c_long
from pyglet.gl import glGetIntegerv, GL_MAX_TEXTURE_SIZE

i = c_long()
glGetIntegerv(GL_MAX_TEXTURE_SIZE, i)
print (i)  # output: c_long(1024) (or higher)

That is the maximum texture size your system supports. If it's 1024, then any larger pictures will raise an Exception. (And the only fix is, get a better system).

like image 26
John C Avatar answered Oct 13 '22 10:10

John C