我一直在尝试让批处理在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))))
我猜您对
batch.add()
的第4个参数不遵循pyglet期望的格式。检查一下这个可能有用。在另外,查看pyglet中发生错误的行可以提供更多信息。问题很可能是传递给pyglet函数的参数有问题。在
注:
add
的documentation可能很有趣。在“太多的值无法解包”是在您执行以下操作时遇到的错误
split返回三个值,但您尝试将它们粘成两个。 我想你最后一行的括号有错。试着用一些更清晰的语法。就像现在的情况,它是相当可怕和不可读的。在
你的问题在于:
我认为应该是:
^{pr2}$请注意我是如何将最后一个参数从格式
((tuple), (tuple))
更改为(tuple), (tuple))
。我不熟悉pyglet,但发现这是从documentation调用batch.add()
的正确方法。请注意,*data
表示函数调用结束时的参数变量列表,而不是像您所尝试的元组或列表。在试试看,让我们知道你的结果如何。在
相关问题 更多 >
编程相关推荐