Bug in images created with pyglet.image.load

398 views
Skip to first unread message

Hugo Ruscitti

unread,
Jun 21, 2008, 6:08:37 PM6/21/08
to pyglet...@googlegroups.com
Hi, i think that exist a problem with images created with pyglet.image.load,
when i blit an image created with pyglet.image.load it show a little border
that no exist in original image.

I create a example that show this problem comparing images creates with
"pyglet.image.load" and "pyglet.resource.image":

screenshot of example:
http://www.losersjuegos.com.ar/incoming/descargas/20080621/image_load.png

image used in example:
http://www.losersjuegos.com.ar/incoming/descargas/20080621/0.png

-- %< --
import os
import pyglet

window = pyglet.window.Window()

image_1 = pyglet.image.load('0.png')
image_2 = pyglet.resource.image('0.png')

@window.event
def on_draw():
window.clear()

for x in range(0, 400, image_1.width):
image_1.blit(x, 200)

for x in range(0, 400, image_2.width):
image_2.blit(x, 10)

pyglet.app.run()
-- %< --

Regards.

--
Hugo Ruscitti
www.losersjuegos.com.ar

Alex Holkner

unread,
Jun 21, 2008, 7:35:46 PM6/21/08
to pyglet...@googlegroups.com

This is an interesting example, that actually demonstrates a problem
with your video card, as well as exposing some of the internal
heuristics used by pyglet. I hope you like messy details...

pyglet.image.load() loads an image into system memory only (i.e., it
just decodes the data, without uploading it to the video card). The
result of image.load() is an ImageData object. When you call
ImageData.blit(), a Texture object is implicitly created (via
ImageData.get_texture()), which is where the actual OpenGL texture is
created.

You may know that for standard texture formats, OpenGL supports on
textures with powers of 2 dimensions (e.g., 32x32, 16x64, 256x128,
...). When ImageData.get_texture() is called on an image with
dimensions that do not conform (e.g. yours, which has dimensions
140x128), a larger texture is created (256x128), with the actual image
data placed in the lower left corner. The rest of the texture is
initialised to black with 0 alpha.

The border you are seeing is the interpolation between the edge of
your image and the black/uninitialised area. A conforming OpenGL
video card won't show this border, but your video card apparently has
a slightly different notion of where the center of a pixel/texel is.
You could possibly tweak the generation of tex_coords in
TextureRegion.__init__, but this would result in artifacts on other
video cards.

pyglet.resource uses the ARB_texture_rectangle OpenGL extension which
allows it to create textures of non-power-2 sizes. It does this
heuristically for any image larger than 128x128 (smaller images are
packed tightly into larger textures). There are some limitations on
the use of these "rectangular" textures, which is why pyglet doesn't
create them by default. You can explicitly request one though:

image = pyglet.image.load('0.png')
texture = image.get_texture(rectangle=True)
texture.blit().

I'd be interested to know what graphics card you're using (run "python
-m pyglet.info" if you're not sure). Updating your driver may also
solve the problem.

Cheers
Alex.

Luke Miller

unread,
Jun 21, 2008, 7:43:54 PM6/21/08
to pyglet...@googlegroups.com
I think I get the same border error on my GeForce 8600 GTS.
Incidentally, I ran the python -m pyglet.info command and got various
errors:

Hmm, should that be the x84_64 ... I'm running 32 bit...?

Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/pyglet/info.py", line 173, in _try_dump
File "build/bdist.linux-x86_64/egg/pyglet/info.py", line 77, in dump_window
File "build/bdist.linux-x86_64/egg/pyglet/window/__init__.py", line
1667, in <module>
File "build/bdist.linux-x86_64/egg/pyglet/gl/__init__.py", line 388,
in _create_shadow_window
File "build/bdist.linux-x86_64/egg/pyglet/window/xlib/__init__.py",
line 471, in __init__
File "build/bdist.linux-x86_64/egg/pyglet/window/__init__.py", line
671, in __init__
File "build/bdist.linux-x86_64/egg/pyglet/window/xlib/__init__.py",
line 637, in _create
File "build/bdist.linux-x86_64/egg/pyglet/window/xlib/__init__.py",
line 782, in set_caption
File "build/bdist.linux-x86_64/egg/pyglet/window/xlib/__init__.py",
line 1029, in _set_text_property
AttributeError: 'NoneType' object has no attribute 'encode'
/usr/lib/python2.5/site-packages/pyglet-1.1beta1-py2.5.egg/pyglet/gl/gl_info.py:134:
UserWarning: No GL context created yet.
/usr/lib/python2.5/site-packages/pyglet-1.1beta1-py2.5.egg/pyglet/gl/gl_info.py:175:
UserWarning: No GL context created yet.
/usr/lib/python2.5/site-packages/pyglet-1.1beta1-py2.5.egg/pyglet/gl/gl_info.py:166:
UserWarning: No GL context created yet.
/usr/lib/python2.5/site-packages/pyglet-1.1beta1-py2.5.egg/pyglet/gl/gl_info.py:124:
UserWarning: No GL context created yet.
/usr/lib/python2.5/site-packages/pyglet-1.1beta1-py2.5.egg/pyglet/gl/glu_info.py:124:
UserWarning: No GL context created yet.
/usr/lib/python2.5/site-packages/pyglet-1.1beta1-py2.5.egg/pyglet/gl/glu_info.py:149:
UserWarning: No GL context created yet.
Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/pyglet/info.py", line 173, in _try_dump
File "build/bdist.linux-x86_64/egg/pyglet/info.py", line 121, in dump_glx
File "build/bdist.linux-x86_64/egg/pyglet/window/xlib/__init__.py",
line 471, in __init__
File "build/bdist.linux-x86_64/egg/pyglet/window/__init__.py", line
669, in __init__
SystemError: Parent module 'pyglet.window' not loaded
ALSA lib pcm_dmix.c:874:(snd_pcm_dmix_open) unable to open slave
open /dev/[sound/]dsp: Device or resource busy
Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/pyglet/info.py", line 173, in _try_dump
File "build/bdist.linux-x86_64/egg/pyglet/info.py", line 144, in dump_media
File "build/bdist.linux-x86_64/egg/pyglet/media/__init__.py", line
1337, in <module>
File "build/bdist.linux-x86_64/egg/pyglet/media/drivers/openal/__init__.py",
line 337, in driver_init
Exception: No OpenAL device.
ALSA lib pcm_dmix.c:874:(snd_pcm_dmix_open) unable to open slave
open /dev/[sound/]dsp: Device or resource busy
ALSA lib pcm_dmix.c:874:(snd_pcm_dmix_open) unable to open slave
open /dev/[sound/]dsp: Device or resource busy


2008/6/22 Alex Holkner <alex.h...@gmail.com>:

Alex Holkner

unread,
Jun 21, 2008, 7:50:14 PM6/21/08
to pyglet...@googlegroups.com
On 6/22/08, Luke Miller <dodgy...@gmail.com> wrote:
>
> I think I get the same border error on my GeForce 8600 GTS.

That's surprising. I'll be interested to see the output of
pyglet.info when you get it working (or glxinfo, equivalently).

> Incidentally, I ran the python -m pyglet.info command and got various
> errors:
>
> Hmm, should that be the x84_64 ... I'm running 32 bit...?

That's just the build directory from my computer hard-coded into
setuptools' error message. The eggs are platform-neutral.

> File "build/bdist.linux-x86_64/egg/pyglet/window/xlib/__init__.py",
> line 782, in set_caption
> File "build/bdist.linux-x86_64/egg/pyglet/window/xlib/__init__.py",
> line 1029, in _set_text_property
> AttributeError: 'NoneType' object has no attribute 'encode'

I'm pretty sure I fixed this; try upgrading to pyglet 1.1 beta 2.

Alex.

Hugo Ruscitti

unread,
Jun 22, 2008, 12:51:08 AM6/22/08
to pyglet...@googlegroups.com
On Sat, Jun 21, 2008 at 8:35 PM, Alex Holkner <alex.h...@gmail.com> wrote:
> I'd be interested to know what graphics card you're using (run "python
> -m pyglet.info" if you're not sure). Updating your driver may also
> solve the problem.

Sure, this is what i get when run "python -m pyglet.info":

-- %< --
Python
------------------------------------------------------------------------------
sys.version: 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]
sys.platform: linux2
os.getcwd(): /home/hugoruscitti

pyglet
------------------------------------------------------------------------------
pyglet.version: 1.1beta2
pyglet.__file__: /usr/lib/python2.5/site-packages/pyglet/__init__.pyc
pyglet.options['debug_trace_depth'] = 1
pyglet.options['audio'] = ('directsound', 'openal', 'alsa', 'silent')
pyglet.options['xsync'] = True
pyglet.options['debug_trace_flush'] = True
pyglet.options['debug_win32'] = False
pyglet.options['debug_gl_trace'] = False
pyglet.options['debug_x11'] = False
pyglet.options['shadow_window'] = True
pyglet.options['debug_font'] = False
pyglet.options['debug_media'] = False
pyglet.options['debug_trace'] = False
pyglet.options['debug_lib'] = False
pyglet.options['graphics_vbo'] = True
pyglet.options['vsync'] = None
pyglet.options['debug_trace_args'] = False
pyglet.options['debug_gl'] = True
pyglet.options['debug_graphics_batch'] = False
pyglet.options['font'] = ('gdiplus', 'win32')
pyglet.options['debug_texture'] = False
pyglet.options['debug_gl_trace_args'] = False

pyglet.window
------------------------------------------------------------------------------
platform: <pyglet.window.xlib.XlibPlatform object at 0x84624ec>
display: <pyglet.window.xlib.XlibDisplayDevice object at 0x84413cc>
screens[0]: XlibScreen(screen=0, x=0, y=0, width=1024, height=768, xinerama=1)
config['double_buffer'] = 1
config['stereo'] = 0
config['buffer_size'] = 32
config['aux_buffers'] = 0
config['sample_buffers'] = 0
config['samples'] = 0
config['red_size'] = 8
config['green_size'] = 8
config['blue_size'] = 8
config['alpha_size'] = 8
config['depth_size'] = 24
config['stencil_size'] = 8
config['accum_red_size'] = 0
config['accum_green_size'] = 0
config['accum_blue_size'] = 0
config['accum_alpha_size'] = 0
context: XlibGLContext()

pyglet.gl.gl_info
------------------------------------------------------------------------------
gl_info.get_version(): 1.3 Mesa 7.0.3-rc2
gl_info.get_vendor(): Tungsten Graphics, Inc
gl_info.get_renderer(): Mesa DRI Intel(R) 945GM 20061017 x86/MMX/SSE2
gl_info.get_extensions():
GL_3DFX_texture_compression_FXT1
GL_APPLE_client_storage
GL_APPLE_packed_pixels
GL_ARB_depth_texture
GL_ARB_fragment_program
GL_ARB_imaging
GL_ARB_multisample
GL_ARB_multitexture
GL_ARB_point_parameters
GL_ARB_shadow
GL_ARB_texture_border_clamp
GL_ARB_texture_compression
GL_ARB_texture_cube_map
GL_ARB_texture_env_add
GL_ARB_texture_env_combine
GL_ARB_texture_env_crossbar
GL_ARB_texture_env_dot3
GL_ARB_texture_mirrored_repeat
GL_ARB_texture_rectangle
GL_ARB_transpose_matrix
GL_ARB_vertex_buffer_object
GL_ARB_vertex_program
GL_ARB_window_pos
GL_ATI_blend_equation_separate
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_blend_color
GL_EXT_blend_equation_separate
GL_EXT_blend_func_separate
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_clip_volume_hint
GL_EXT_compiled_vertex_array
GL_EXT_convolution
GL_EXT_copy_texture
GL_EXT_cull_vertex
GL_EXT_draw_range_elements
GL_EXT_fog_coord
GL_EXT_histogram
GL_EXT_multi_draw_arrays
GL_EXT_packed_pixels
GL_EXT_point_parameters
GL_EXT_polygon_offset
GL_EXT_rescale_normal
GL_EXT_secondary_color
GL_EXT_separate_specular_color
GL_EXT_shadow_funcs
GL_EXT_stencil_wrap
GL_EXT_subtexture
GL_EXT_texture
GL_EXT_texture3D
GL_EXT_texture_edge_clamp
GL_EXT_texture_env_add
GL_EXT_texture_env_combine
GL_EXT_texture_env_dot3
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_lod_bias
GL_EXT_texture_object
GL_EXT_texture_rectangle
GL_EXT_vertex_array
GL_IBM_rasterpos_clip
GL_IBM_texture_mirrored_repeat
GL_INGR_blend_func_separate
GL_MESA_pack_invert
GL_MESA_window_pos
GL_MESA_ycbcr_texture
GL_NV_blend_square
GL_NV_light_max_exponent
GL_NV_texgen_reflection
GL_NV_texture_rectangle
GL_NV_vertex_program
GL_NV_vertex_program1_1
GL_OES_read_format
GL_SGIS_generate_mipmap
GL_SGIS_texture_border_clamp
GL_SGIS_texture_edge_clamp
GL_SGIS_texture_lod
GL_SGIX_depth_texture
GL_SGI_color_matrix
GL_SGI_color_table
GL_SUN_multi_draw_arrays

pyglet.gl.glu_info
------------------------------------------------------------------------------
glu_info.get_version(): 1.3
glu_info.get_extensions():
GLU_EXT_nurbs_tessellator
GLU_EXT_object_space_tess

pyglet.gl.glx_info
------------------------------------------------------------------------------
context.is_direct(): 1
glx_info.get_server_vendor(): SGI
glx_info.get_server_version(): 1.2
glx_info.get_server_extensions():
GLX_ARB_multisample
GLX_EXT_import_context
GLX_EXT_texture_from_pixmap
GLX_EXT_visual_info
GLX_EXT_visual_rating
GLX_MESA_copy_sub_buffer
GLX_OML_swap_method
GLX_SGI_make_current_read
GLX_SGI_swap_control
GLX_SGIS_multisample
GLX_SGIX_fbconfig
GLX_SGIX_visual_select_group
glx_info.get_client_vendor(): SGI
glx_info.get_client_version(): 1.4
glx_info.get_client_extensions():
GLX_ARB_get_proc_address
GLX_ARB_multisample
GLX_EXT_import_context
GLX_EXT_visual_info
GLX_EXT_visual_rating
GLX_MESA_allocate_memory
GLX_MESA_copy_sub_buffer
GLX_MESA_swap_control
GLX_MESA_swap_frame_usage
GLX_OML_swap_method
GLX_OML_sync_control
GLX_SGI_make_current_read
GLX_SGI_swap_control
GLX_SGI_video_sync
GLX_SGIS_multisample
GLX_SGIX_fbconfig
GLX_SGIX_pbuffer
GLX_SGIX_visual_select_group
GLX_EXT_texture_from_pixmap
glx_info.get_extensions():
GLX_ARB_get_proc_address
GLX_ARB_multisample
GLX_EXT_import_context
GLX_EXT_visual_info
GLX_EXT_visual_rating
GLX_MESA_allocate_memory
GLX_MESA_copy_sub_buffer
GLX_MESA_swap_control
GLX_MESA_swap_frame_usage
GLX_OML_swap_method
GLX_SGI_make_current_read
GLX_SGI_swap_control
GLX_SGI_video_sync
GLX_SGIS_multisample
GLX_SGIX_fbconfig
GLX_SGIX_visual_select_group

pyglet.media
------------------------------------------------------------------------------
driver: pyglet.media.drivers.openal

pyglet.media.avbin
------------------------------------------------------------------------------
Library: <CDLL 'libavbin.so', handle 89a18f0 at 895f88c>
AVbin version: 2
FFmpeg revision: 10112

pyglet.media.drivers.openal
------------------------------------------------------------------------------
Library: <CDLL 'libopenal.so.0', handle 891dfe0 at 88e5cec>
Version: (1, 0)
Extensions:

weird vorbid_get
-- %< --

--
Hugo Ruscitti
www.losersjuegos.com.ar

Lucio Torre

unread,
Jun 22, 2008, 5:21:49 AM6/22/08
to pyglet...@googlegroups.com
On Sat, Jun 21, 2008 at 8:35 PM, Alex Holkner <alex.h...@gmail.com> wrote:
This is an interesting example, that actually demonstrates a problem
with your video card, as well as exposing some of the internal
heuristics used by pyglet.  I hope you like messy details...


Is there any way to have this kind of 'bad video card' problems solved by pyglet? Ive seen a lot of issues where this happens, and people are still using 3dgames, 3d desktops and 3d everything, and asking them to upgrade or buy a new video card is not always possible if i want them as users of whatever i develop.

regards,

lucio.

Richard Jones

unread,
Jun 22, 2008, 6:14:40 AM6/22/08
to pyglet...@googlegroups.com

If you look in the pyglet source you'll see there's already a bunch of work-arounds like the ones you describe :)

Resources are the main roadblock, rather than absence of any sort of willingess.


     Richard
 

Lucio Torre

unread,
Jun 22, 2008, 12:57:04 PM6/22/08
to pyglet...@googlegroups.com

Nice!

And please dont take it as a criticism for your work, just a misunderstanding in direction.

Regards,

Lucio.

Reply all
Reply to author
Forward
0 new messages