简体   繁体   English

Pyglet 将纹理区域 blit 到纹理上

[英]Pyglet blit a texture region onto a texture

I would like to create a single texture from multiple smaller texture regions.我想从多个较小的纹理区域创建单个纹理。 What I'm trying is:我正在尝试的是:

import pyglet
import pyglet.gl as gl

large_texture = pyglet.image.Texture(width=800,
                                     height=600,
                                     target=gl.GL_TEXTURE_2D,
                                     id=0)
texture = pyglet.resource.texture("assets/my_image.png")
region = texture.get_region(0, 0, 32, 32)
region_2 = texture.get_region(0, 32, 32, 32)
large_texture.blit_into(region.get_image_data(), x=0, y=0, z=0)
large_texture.blit_into(region_2.get_image_data(), x=0, y=32, z=0)

I was expecting that this would place the two texture regions onto the large_texture , but instead, I get this error:我期待这会将两个纹理区域放在large_texture上,但相反,我得到了这个错误:

pyglet.gl.lib.GLException: b'invalid value'

Is there something obvious that I am missing, or what (if any) is the correct way to achieve this?有什么明显的我遗漏的东西,或者什么(如果有的话)是实现这一目标的正确方法?

You aren't actually creating a texture right now.您现在实际上并没有创建纹理。

large_texture = pyglet.image.Texture(width=800,
                                     height=600,
                                     target=gl.GL_TEXTURE_2D,
                                     id=0)

Is just declaring a Python object (usually used internally by Pyglet).只是声明一个 Python object (通常由 Pyglet 内部使用)。

The actual texture creation is done in the create method: large_texture = pyglet.image.Texture.create(width=800, height=600)实际的纹理创建在 create 方法中完成: large_texture = pyglet.image.Texture.create(width=800, height=600)

Once you do that, it should work.一旦你这样做,它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM