本文整理汇总了Python中shader.Shader.set方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.set方法的具体用法?Python Shader.set怎么用?Python Shader.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shader.Shader
的用法示例。
在下文中一共展示了Shader.set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Render
# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import set [as 别名]
class Render(object):
def __init__(self, camera, window):
super(Render, self).__init__()
self.scene_batch = pyglet.graphics.Batch()
self.static_batch = pyglet.graphics.Batch()
self.camera = camera
self.window = window
# scaling factors
self.scale = vec2(window.width / 1360., window.height / 765.)
self.players = {}
#for rendering
self.fbo = FBO(window.width, window.height)
self.lighting = Shader('lighting')
self.lighting.set('mvp', Matrix.orthographic(
0., window.width, 0., window.height, 0, 1))
self.lighting.set('lightPos', vector((-20., 20, 10)))
self.screen = TexQuad(
0, 0, window.width, window.height, self.fbo.textures[0].tex_coords)
def draw(self):
with self.fbo:
self.fbo.clear()
with self.camera as mvp:
self.scene_batch.draw()
for player in self.players.itervalues():
player.draw(mvp)
#send texture data to shader
for i in range(3):
glActiveTexture(GL_TEXTURE0 + i)
glBindTexture(GL_TEXTURE_2D, self.fbo.textures[i].id)
self.lighting.set('texs', arr(self.fbo.textures[0].id,
self.fbo.textures[1].id,
self.fbo.textures[2].id))
glActiveTexture(GL_TEXTURE0)
#draw; for now scene batch like this, eventually it will also be 3d
self.window.clear()
with self.lighting:
self.screen.draw()
self.static_batch.draw()
def maphook(self, map, add=False, spawn=False, remove=False, taken=False):
if spawn:
self.map.spawn(map)
elif taken:
self.map.taken(map)
elif add:
self.map = DrawableMap(map, self.scene_batch, self.scale)
def playerhook(self, player, remove=False, update=False, add=False):
id = player.id
if update:
self.players[id].update(player, self.scale)
elif add:
self.players[id] = DrawablePlayer(player, self.scene_batch,
self.scale)
elif remove:
self.players[id].remove()
del self.players[id]
def update(self, dt):
#self.model.update(dt, self.players[1].state)
for player in self.players.itervalues():
player.animate(dt)
def weapon_check(self, id, weaponinfo):
self.players[id].update_weapon(weaponinfo[1])
def attack(self, id):
try:
self.players[id].attack()
except KeyError:
pass
示例2: Model
# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import set [as 别名]
class Model(object):
"""docstring for Model"""
def __init__(self, filename, scale):
super(Model, self).__init__()
p_data = parsedae.parse_dae(filename, scale)
verts, norms, facedata, jd, js, skn, anm, fsc = p_data
self.maxtime = max(anm[0][0])
_anim = AnimatedModel(*p_data)
self.anim = AnimationUpdater(anm, _anim)
self.meshes = []
self.batch = pyglet.graphics.Batch()
for faces in facedata:
color = faces[0]
facearr = [(vert, faces[2][i]) for i, vert in enumerate(faces[1])]
self.meshes.append(Mesh(verts, facearr, norms, color, skn))
self.tarr = [[None for j in range(len(facedata[i][1])*3)]
for i in range(len(facedata))]
self.add(self.batch)
self.quats, self.vecs = _anim.get_bindpose()
self.shader = Shader('skinning')
self.shader.set('quats', self.quats)
self.shader.set('vecs', self.vecs)
self.shader.set('scale', fsc)
def add(self, batch):
for mesh in self.meshes:
mesh.data_to_batch(batch)
def remove(self):
for mesh in self.meshes:
mesh.vertex_list.delete()
def update(self, dt, state):
self.quats, self.vecs = self.anim.update(dt, state)
self.shader.set('quats', self.quats)
self.shader.set('vecs', self.vecs)
def start_attack(self):
self.anim.start_attack()
def draw(self, mvp):
self.shader.set('mvp', mvp)
with self.shader:
self.batch.draw()
def change_color(self, color):
self.meshes[1].vertex_list._set_attribute_data(
2, color[:4] * self.meshes[1].length)
def update_weapon(self, color):
self.meshes[2].vertex_list._set_attribute_data(
2, color[:4] * self.meshes[2].length)