我一直在尝试让批处理在 pyglet 中工作,但我完全被来自pyglet/graphics/__init__.py
文件的错误消息“太多的值无法解包”弄糊涂了。我的猜测是,在将几何图形添加到批处理时,我在语法上做错了。
我将代码缩减为产生错误的基本部分:
from pyglet.gl import *
from pyglet.graphics import *
import pyglet
batch = pyglet.graphics.Batch()
img = pyglet.image.load('pic.png')
texture = img.get_texture()
class TextureEnableGroup(pyglet.graphics.Group):
def set_state(self):
glEnable(GL_TEXTURE_2D)
def unset_state(self):
glDisable(GL_TEXTURE_2D)
texture_enable_group = TextureEnableGroup()
class TextureBindGroup(pyglet.graphics.Group):
def __init__(self, texture):
super(TextureBindGroup, self).__init__(parent=texture_enable_group)
self.texture = texture
def set_state(self):
glBindTexture(GL_TEXTURE_2D, self.texture.id)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
def __eq__(self, other):
return (self.__class__ is other.__class__ and self.texture == other.__class__)
batch.add(12, GL_TRIANGLES, TextureBindGroup(texture), (('t2f', (0, 0)), ('v3f', (64, 64, 0)), ('t2f', (1, 1)), ('v3f', (-64, -64, 205)), ('t2f', (0, 1)), ('v3f', (-64, 64, 205)), ('t2f', (1, 1)), ('v3f', (64, -64, 205)), ('t2f', (1, 0)), ('v3f', (64, 64, 0)), ('t2f', (0, 1)), ('v3f', (-64, -64, 205))))