如何解决在pyglet / opengl中渲染纹理立方体的最有效方法
目前,我有这段代码,用于渲染带纹理的立方体。它可以在几个多维数据集上正常工作,但是当我添加数百个多维数据集时,创建它会花费很多时间。
def get_tex(file):
tex = pyglet.image.load(file).get_texture()
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
return pyglet.graphics.TextureGroup(tex)
def make_textures(textures):
result = {}
base = "imgs/"
faces = ("left","right","top","bottom","front","back")
for face in faces:
file_name = textures.get(face,textures.get("side"))
result[face] = get_tex(base + file_name)
return result
def get_vertices(x,y,z):
dx,dy,dz = x + 1,y + 1,z + 1
return [
(x,z,x,dz,z),# side
(dx,dx,dz),# side
(x,# top
(x,# bottom
(dx,# side
]
class Grass:
textures = make_textures({"side": "grass_side.png","top": "grass_top.png","bottom": "dirt.png"})
def draw_block(self,block):
position = (block.x,block.y,block.z)
if block._type == "grass":
block = Grass
else:
block = Grass
vertices = get_vertices(*position)
faces = ("left","back")
for vertex,face in zip(vertices,faces):
self.batch.add(
4,gl.GL_QUADS,block.textures[face],("v3f/static",vertex),("t2f/static",(0,1,1)),)
但这创建时间太长了,因为我正在调用gl函数,所以我不能使用其他线程来执行此操作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。