class Overlay: def __init__(self): self.quad = MeshQuad() self.texture = Texture("media/textures/border4.png") #self.texture = Texture("media/textures/flare.png") self.shader = Shader("media/shaders/overlay.vert", "media/shaders/overlay.frag", isFile=True) def on_beat(self, dt): pass def update(self, dt): pass def draw(self): glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) #glBlendFunc(GL_SRC_ALPHA, GL_ONE) #glDepthMask(GL_FALSE) #glDisable(GL_DEPTH_TEST) self.texture.bind() self.shader.bind() glPushMatrix() glLoadIdentity() self.quad.draw() glPopMatrix() self.shader.release() self.texture.release() #glEnable(GL_DEPTH_TEST) #glDepthMask(GL_TRUE) glDisable(GL_BLEND)
class LightBeams: def __init__(self, n=512): self.texture = Texture("media/textures/flare3.png") #self.texture = Texture("media/textures/heart.tga") self.shader = Shader("media/shaders/beams.vert", fs=None, isFile=True) self.beams = [] self.n = n for i in range(self.n): self.beams.append([ random.random() * 10, random.random() * 10, random.random() * 10 ]) self.beamlistid = glGenLists(1) glNewList(self.beamlistid, GL_COMPILE) glBegin(GL_POINTS) for i in range(self.n): glVertex3f(self.beams[i][0], self.beams[i][1], self.beams[i][2]) glEnd() glEndList() self.dt = 0 def on_beat(self, beat): pass def update(self, dt): self.dt += dt def draw(self): #glColor4f(0.9,0.1,0.1,1) self.texture.bind() glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE) glEnable(GL_POINT_SPRITE) glPointSize(60.0) glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE) #glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 60.0); #glPointParameterf(GL_POINT_SIZE_MIN, 30.0); #glPointParameterf(GL_POINT_SIZE_MAX, 40.0); glDepthMask(GL_FALSE) glPushMatrix() glTranslatef(-5, -5, -5) self.shader.bind() self.shader["time"] = float(self.dt) glCallList(self.beamlistid) self.shader.release() glPopMatrix() glDepthMask(GL_TRUE) glDisable(GL_POINT_SPRITE) glDisable(GL_BLEND) self.texture.release() glColor4f(1, 1, 1, 1) self.beat = False
class LightBeams: def __init__(self,n=512): self.texture = Texture("media/textures/flare3.png") #self.texture = Texture("media/textures/heart.tga") self.shader = Shader("media/shaders/beams.vert",fs=None,isFile=True) self.beams = [] self.n = n for i in range(self.n): self.beams.append([random.random() * 10, random.random() * 10, random.random() * 10]) self.beamlistid = glGenLists(1) glNewList(self.beamlistid, GL_COMPILE) glBegin(GL_POINTS) for i in range(self.n): glVertex3f( self.beams[i][0], self.beams[i][1], self.beams[i][2] ) glEnd() glEndList() self.dt = 0 def on_beat(self, beat): pass def update(self, dt): self.dt += dt def draw(self): #glColor4f(0.9,0.1,0.1,1) self.texture.bind() glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE) glEnable(GL_POINT_SPRITE) glPointSize(60.0) glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); #glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 60.0); #glPointParameterf(GL_POINT_SIZE_MIN, 30.0); #glPointParameterf(GL_POINT_SIZE_MAX, 40.0); glDepthMask(GL_FALSE) glPushMatrix() glTranslatef(-5,-5,-5) self.shader.bind() self.shader["time"] = float(self.dt) glCallList(self.beamlistid) self.shader.release() glPopMatrix() glDepthMask(GL_TRUE) glDisable(GL_POINT_SPRITE) glDisable(GL_BLEND) self.texture.release() glColor4f(1,1,1,1) self.beat = False
def __init__(self, w=1024, h=1024): self.quad = MeshQuad() self.shader = Shader("media/shaders/postprocess.vert", "media/shaders/postprocess.frag", isFile=True) self.rt = RenderTarget(w, h, multisample=True) self.dt = 0 self.mode = 0 self.texture = Texture("media/textures/gradient.png")
class PostProcess: def __init__(self, w=1024, h=1024): self.quad = MeshQuad() self.shader = Shader("media/shaders/postprocess.vert", "media/shaders/postprocess.frag", isFile=True) self.rt = RenderTarget(w, h, multisample=True) self.dt = 0 self.mode = 0 self.texture = Texture("media/textures/gradient.png") def on_beat(self, beat): pass def switch(self, n): self.mode = n def current(self): return self.mode def num(self): return 6 def bind(self): if self.mode == 0: return self.rt.bind() def release(self): if self.mode == 0: return self.rt.release() def update(self, dt): self.dt += dt def draw(self): if self.mode == 0: return self.rt.texture.bind() self.shader.bind() self.shader["time"] = float(self.dt) self.shader["rt_w"] = float(self.rt.w) self.shader["rt_h"] = float(self.rt.h) self.shader["mode"] = float(self.mode) self.shader["texture2"] = int(1) self.texture.bind(1) self.quad.draw() self.texture.release() self.shader.release() self.rt.texture.release()
def __init__(self, n=32, f=6): self.n = n # number of floating platforms (a.k.a gardens) self.f = f # maximum number of flowers per platform self.platforms = [] self.flowers = [] for i in range(self.n): nx = (random.random() * 5) - random.random() * 1 ny = (random.random() * 5) nz = (random.random() * 5) - random.random() * 1 self.platforms.append(MeshCube(0.1, 0.02, 0.1, tx=nx, ty=ny, tz=nz)) self.flowers.extend(self.create_flowers(nx, ny + 0.02, nz)) self.flowertexture = Texture("media/textures/flare2.png") self.flowerlistid = glGenLists(1) glNewList(self.flowerlistid, GL_COMPILE) glColor4f(0.0, 0.4, 0.8, 1) for f in self.flowers: i = 0 glLineWidth(1.5) glBegin(GL_LINE_STRIP) for s in range(f['n']): glNormal3f(f['n'], float(i), float(f['d'])) glVertex3f(f['x'], f['y'] + (s * 0.1), f['z']) i += 1 glEnd() glColor4f(1, 1, 1, 1) glEndList() self.flowerlistid2 = glGenLists(1) glNewList(self.flowerlistid2, GL_COMPILE) glColor4f(1, 1, 1, 1) for f in self.flowers: i = 0 glPointSize(20.0) glBegin(GL_POINTS) for s in range(f['n']): glNormal3f(f['n'], float(i), float(f['d'])) glVertex3f(f['x'], f['y'] + (s * 0.1), f['z']) i += 1 glEnd() glEndList() self.platformshader = Shader("media/shaders/spherecubes.vert", "media/shaders/spherecubes.frag", isFile=True) self.flowershader = Shader("media/shaders/flowers.vert", None, isFile=True) self.dt = 0
class PostProcess: def __init__(self, w=1024, h=1024): self.quad = MeshQuad() self.shader = Shader("media/shaders/postprocess.vert", "media/shaders/postprocess.frag", isFile=True) self.rt = RenderTarget(w,h,multisample=True) self.dt = 0 self.mode = 0 self.texture = Texture("media/textures/gradient.png") def on_beat(self, beat): pass def switch(self, n): self.mode = n def current(self): return self.mode def num(self): return 6 def bind(self): if self.mode == 0: return self.rt.bind() def release(self): if self.mode == 0: return self.rt.release() def update(self, dt): self.dt += dt def draw(self): if self.mode == 0: return self.rt.texture.bind() self.shader.bind() self.shader["time"] = float(self.dt) self.shader["rt_w"] = float(self.rt.w) self.shader["rt_h"] = float(self.rt.h) self.shader["mode"] = float(self.mode) self.shader["texture2"] = int(1) self.texture.bind(1) self.quad.draw() self.texture.release() self.shader.release() self.rt.texture.release()
def __init__(self, w=1024, h=1024): self.quad = MeshQuad() self.shader = Shader("media/shaders/postprocess.vert", "media/shaders/postprocess.frag", isFile=True) self.rt = RenderTarget(w,h,multisample=True) self.dt = 0 self.mode = 0 self.texture = Texture("media/textures/gradient.png")
def __setitem__(self, name, value): if isinstance(value, Texture): self.textures[name] = value elif isinstance(value, str): if name == 'init': for f in ['back', 'front', 'left', 'right', 'top', 'bottom']: self[f] = value % f else: self.textures[name] = Texture(value) else: raise TypeError('Trying to set a non-texture')
def __init__(self, n=32, f=6): self.n = n # number of floating platforms (a.k.a gardens) self.f = f # maximum number of flowers per platform self.platforms = [] self.flowers = [] for i in range(self.n): nx = (random.random() * 5) - random.random() * 1 ny = (random.random() * 5) nz = (random.random() * 5) - random.random() * 1 self.platforms.append(MeshCube(0.1,0.02,0.1,tx=nx,ty=ny,tz=nz)) self.flowers.extend(self.create_flowers(nx, ny+0.02, nz)) self.flowertexture = Texture("media/textures/flare2.png") self.flowerlistid = glGenLists(1) glNewList(self.flowerlistid, GL_COMPILE) glColor4f(0.0,0.4,0.8,1) for f in self.flowers: i = 0 glLineWidth(1.5) glBegin(GL_LINE_STRIP) for s in range(f['n']): glNormal3f(f['n'],float(i),float(f['d'])) glVertex3f(f['x'],f['y']+(s*0.1),f['z']) i+=1 glEnd() glColor4f(1,1,1,1) glEndList() self.flowerlistid2 = glGenLists(1) glNewList(self.flowerlistid2, GL_COMPILE) glColor4f(1,1,1,1) for f in self.flowers: i = 0 glPointSize(20.0) glBegin(GL_POINTS) for s in range(f['n']): glNormal3f(f['n'],float(i),float(f['d'])) glVertex3f(f['x'],f['y']+(s*0.1),f['z']) i+=1 glEnd() glEndList() self.platformshader = Shader("media/shaders/spherecubes.vert", "media/shaders/spherecubes.frag", isFile=True) self.flowershader = Shader("media/shaders/flowers.vert", None, isFile=True) self.dt = 0
def __init__(self, n=512): self.texture = Texture("media/textures/flare3.png") #self.texture = Texture("media/textures/heart.tga") self.shader = Shader("media/shaders/beams.vert", fs=None, isFile=True) self.beams = [] self.n = n for i in range(self.n): self.beams.append([ random.random() * 10, random.random() * 10, random.random() * 10 ]) self.beamlistid = glGenLists(1) glNewList(self.beamlistid, GL_COMPILE) glBegin(GL_POINTS) for i in range(self.n): glVertex3f(self.beams[i][0], self.beams[i][1], self.beams[i][2]) glEnd() glEndList() self.dt = 0
def __init__(self,n=512): self.texture = Texture("media/textures/flare3.png") #self.texture = Texture("media/textures/heart.tga") self.shader = Shader("media/shaders/beams.vert",fs=None,isFile=True) self.beams = [] self.n = n for i in range(self.n): self.beams.append([random.random() * 10, random.random() * 10, random.random() * 10]) self.beamlistid = glGenLists(1) glNewList(self.beamlistid, GL_COMPILE) glBegin(GL_POINTS) for i in range(self.n): glVertex3f( self.beams[i][0], self.beams[i][1], self.beams[i][2] ) glEnd() glEndList() self.dt = 0
def __init__(self, w, h, multisample=False, samples=4): self.w = w self.h = h self.texture = Texture(w=w, h=h) self.id = GLuint() self.depth_id = GLuint() if multisample: self.mid = GLuint() self.mcolor_id = GLuint() self.mdepth_id = GLuint() glGenFramebuffersEXT(1, byref(self.mid)) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self.mid) glGenRenderbuffersEXT(1, byref(self.mcolor_id)) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, self.mcolor_id) glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA, w, h) glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, self.mcolor_id) glGenRenderbuffersEXT(1, byref(self.mdepth_id)) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, self.mdepth_id) glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_DEPTH_COMPONENT, w, h) glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, self.mdepth_id) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) else: self.mid = None self.mcolor_id = None self.mdepth_id = None glBindTexture(GL_TEXTURE_2D, self.texture.id) glGenFramebuffersEXT(1, byref(self.id)) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self.id) # FIXME: add support for other (or multiple) "attachment" types # FIXME: add support for glDrawBuffers # FIXME: add GL_DEPTH_COMPONENT support glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE, self.texture.id, 0) glGenRenderbuffersEXT(1, byref(self.depth_id)) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, self.depth_id) glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, w, h) glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, self.depth_id) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) glBindTexture(GL_TEXTURE_2D, 0)
def __init__(self): self.quad = MeshQuad() self.texture = Texture("media/textures/border4.png") #self.texture = Texture("media/textures/flare.png") self.shader = Shader("media/shaders/overlay.vert", "media/shaders/overlay.frag", isFile=True)
class FlowerGardens: def __init__(self, n=32, f=6): self.n = n # number of floating platforms (a.k.a gardens) self.f = f # maximum number of flowers per platform self.platforms = [] self.flowers = [] for i in range(self.n): nx = (random.random() * 5) - random.random() * 1 ny = (random.random() * 5) nz = (random.random() * 5) - random.random() * 1 self.platforms.append(MeshCube(0.1,0.02,0.1,tx=nx,ty=ny,tz=nz)) self.flowers.extend(self.create_flowers(nx, ny+0.02, nz)) self.flowertexture = Texture("media/textures/flare2.png") self.flowerlistid = glGenLists(1) glNewList(self.flowerlistid, GL_COMPILE) glColor4f(0.0,0.4,0.8,1) for f in self.flowers: i = 0 glLineWidth(1.5) glBegin(GL_LINE_STRIP) for s in range(f['n']): glNormal3f(f['n'],float(i),float(f['d'])) glVertex3f(f['x'],f['y']+(s*0.1),f['z']) i+=1 glEnd() glColor4f(1,1,1,1) glEndList() self.flowerlistid2 = glGenLists(1) glNewList(self.flowerlistid2, GL_COMPILE) glColor4f(1,1,1,1) for f in self.flowers: i = 0 glPointSize(20.0) glBegin(GL_POINTS) for s in range(f['n']): glNormal3f(f['n'],float(i),float(f['d'])) glVertex3f(f['x'],f['y']+(s*0.1),f['z']) i+=1 glEnd() glEndList() self.platformshader = Shader("media/shaders/spherecubes.vert", "media/shaders/spherecubes.frag", isFile=True) self.flowershader = Shader("media/shaders/flowers.vert", None, isFile=True) self.dt = 0 def create_flowers(self, x, y, z): flowers = [] dx = x dy = y dz = z dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({'x':dx-0.05,'y':dy,'z':dz-0.05,'n':int(dn),'d':d}) dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({'x':dx-0.05,'y':dy,'z':dz+0.05,'n':int(dn),'d':d}) dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({'x':dx,'y':dy,'z':dz,'n':int(dn),'d':d}) dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({'x':dx+0.05,'y':dy,'z':dz-0.05,'n':int(dn),'d':d}) dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({'x':dx+0.05,'y':dy,'z':dz+0.05,'n':int(dn),'d':d}) return flowers def on_beat(self, beat): self.dt += (beat.confidence / 3) def update(self, dt): self.dt += dt def draw(self): glPushMatrix() glTranslatef(-2,-3,-2) self.platformshader.bind() self.platformshader["lightPos"] = [10,10,0] for p in self.platforms: p.draw() self.platformshader.release() self.flowershader.bind() self.flowershader["time"] = float(self.dt) glCallList(self.flowerlistid) glEnable(GL_POINT_SPRITE) glPointSize(50.0) glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE) glDepthMask(GL_FALSE) self.flowertexture.bind() glCallList(self.flowerlistid2) self.flowertexture.release() glDepthMask(GL_TRUE) glDisable(GL_BLEND) glDisable(GL_POINT_SPRITE) self.flowershader.release() glPopMatrix()
class FlowerGardens: def __init__(self, n=32, f=6): self.n = n # number of floating platforms (a.k.a gardens) self.f = f # maximum number of flowers per platform self.platforms = [] self.flowers = [] for i in range(self.n): nx = (random.random() * 5) - random.random() * 1 ny = (random.random() * 5) nz = (random.random() * 5) - random.random() * 1 self.platforms.append(MeshCube(0.1, 0.02, 0.1, tx=nx, ty=ny, tz=nz)) self.flowers.extend(self.create_flowers(nx, ny + 0.02, nz)) self.flowertexture = Texture("media/textures/flare2.png") self.flowerlistid = glGenLists(1) glNewList(self.flowerlistid, GL_COMPILE) glColor4f(0.0, 0.4, 0.8, 1) for f in self.flowers: i = 0 glLineWidth(1.5) glBegin(GL_LINE_STRIP) for s in range(f['n']): glNormal3f(f['n'], float(i), float(f['d'])) glVertex3f(f['x'], f['y'] + (s * 0.1), f['z']) i += 1 glEnd() glColor4f(1, 1, 1, 1) glEndList() self.flowerlistid2 = glGenLists(1) glNewList(self.flowerlistid2, GL_COMPILE) glColor4f(1, 1, 1, 1) for f in self.flowers: i = 0 glPointSize(20.0) glBegin(GL_POINTS) for s in range(f['n']): glNormal3f(f['n'], float(i), float(f['d'])) glVertex3f(f['x'], f['y'] + (s * 0.1), f['z']) i += 1 glEnd() glEndList() self.platformshader = Shader("media/shaders/spherecubes.vert", "media/shaders/spherecubes.frag", isFile=True) self.flowershader = Shader("media/shaders/flowers.vert", None, isFile=True) self.dt = 0 def create_flowers(self, x, y, z): flowers = [] dx = x dy = y dz = z dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({ 'x': dx - 0.05, 'y': dy, 'z': dz - 0.05, 'n': int(dn), 'd': d }) dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({ 'x': dx - 0.05, 'y': dy, 'z': dz + 0.05, 'n': int(dn), 'd': d }) dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({'x': dx, 'y': dy, 'z': dz, 'n': int(dn), 'd': d}) dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({ 'x': dx + 0.05, 'y': dy, 'z': dz - 0.05, 'n': int(dn), 'd': d }) dn = random.random() * self.f while dn < 3: dn = random.random() * self.f d = random.random() - 0.5 flowers.append({ 'x': dx + 0.05, 'y': dy, 'z': dz + 0.05, 'n': int(dn), 'd': d }) return flowers def on_beat(self, beat): self.dt += (beat.confidence / 3) def update(self, dt): self.dt += dt def draw(self): glPushMatrix() glTranslatef(-2, -3, -2) self.platformshader.bind() self.platformshader["lightPos"] = [10, 10, 0] for p in self.platforms: p.draw() self.platformshader.release() self.flowershader.bind() self.flowershader["time"] = float(self.dt) glCallList(self.flowerlistid) glEnable(GL_POINT_SPRITE) glPointSize(50.0) glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE) glDepthMask(GL_FALSE) self.flowertexture.bind() glCallList(self.flowerlistid2) self.flowertexture.release() glDepthMask(GL_TRUE) glDisable(GL_BLEND) glDisable(GL_POINT_SPRITE) self.flowershader.release() glPopMatrix()