I am completely new to opengl, pyglet and miru... you have been
warned :) It is quite ugly, but is throw away... I am in it for the
learning.
The following code shows my attempt to muck around with primitives and
textures. I am not sure how given an image loaded as below, I can
actually get it to display.
Any help is appreciated:
#!/usr/bin/env python2.6
'''
some tests using Miru
'''
import miru
import os
from miru.context import context
import pyglet
from pyglet import gl
from miru import ext
from miru.ext import geom
import session
class EffectsManager (object):
def __init__ (self):
session.effects = []
def processEffects (self, dt):
for effect in session.effects:
effect.processEffect(dt)
class CoolEffect (object):
#def __init__ (effect_type):
#pass
def processEffect (self):
raise NotImplementedError
class CubeFlipTransition (CoolEffect):
def __init__ (self, obj):
self.obj = obj
self.idx = 0
self.effect_idx = session.effects.append(self)
def processEffect (self, dt):
if self.idx < 30:
self.idx += 1
self.obj.pos += (0, 0, -0.5)
elif 30 <= self.idx < 60:
self.idx += 1
ty = 90 // 30
self.obj.angle += (0, ty, 0)
self.obj.angle.y %= 360.
elif 60 <= self.idx < 90:
self.idx += 1
self.obj.pos += (0, 0, 0.5)
else:
session.effects.pop(session.effects.index(self))
def setup ():
#global obj
session.win = miru.ui.Window(640, 480)
context.window = session.win
context.control = miru.input.SimpleMouseControl()
context.camera.lights = miru.camera.LightGroup([
miru.camera.PositionalLight(pos=(0,0,5)),
miru.camera.PositionalLight(pos=(0,1,0)),
miru.camera.PositionalLight(pos=(1,0,0))])
context.camera.pos = (0,0,15)
cube = ext.geom.Cube(width=5)
batch = pyglet.graphics.Batch()
vlist = miru.ext.geom.get_vlist(cube, batch)
img_0_path = r'examples/moosebat.png'
img_0 = pyglet.image.load(img_0_path)
tex_0 = img_0.get_texture()
img_group = miru.graphics.TextureBindGroup(tex_0)
#greygroup = miru.graphics.ColorGroup(0.5)
vertices = vlist.vertices[:]
data = [('v3f', vertices),
('t3f'), #, vertices), #list(cube.texcoord_data)),
('n3f', list(vlist.normals))]
count = len(vertices) // 3
batch.add(count, gl.GL_TRIANGLES, img_group, *data)
session.main_cube = miru.core.Object(batch)
context.add_object(session.main_cube)
gl.glEnable( gl.GL_CULL_FACE )
session.effects_mgr = EffectsManager()
# hard coded effects for testing
CubeFlipTransition(session.main_cube)
setup()
@session.win.event
def on_draw ():
session.win.clear()
context.render()
def update(dt):
session.effects_mgr.processEffects(dt)
pyglet.clock.schedule_interval(update, interval=1/30.0)
def main ():
pyglet.app.run()
if __name__ == '__main__':
main()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---