Ejemplo n.º 1
0
Archivo: app.py Proyecto: seken/nink
	def create_minimap(self):
		self.mm_tex = Texture.open(self.path+'/map/%s.png'%(self.map_name), unit=GL_TEXTURE0, filter=GL_NEAREST)
		position = [
			0.4, 0.4, 0,
			0.4, 1, 0,
			1, 1, 0,
			1, 0.4, 0,
		]
		texCoord = [
			0, 0,
			0, 1,
			1, 1,
			1, 0,
		]
		normal = [
			0, 0, 1,
			0, 0, 1,
			0, 0, 1,
			0, 0, 1,
		]
		position = (c_float*len(position))(*position)
		texCoord = (c_float*len(texCoord))(*texCoord)
		normal = (c_float*len(normal))(*normal)
		self.mm_mesh = VBO(4,
			position_3=position,
			texCoord_2=texCoord,
			normal_3=normal)
Ejemplo n.º 2
0
from __future__ import with_statement
from contextlib import nested

import pyglet
from gletools import Texture, Projection, DepthTest, SphereMapping, Matrix
from gletools.gl import *

rotation = 0
background = Texture.open('background.jpg')
sphere_map = Texture.open('sphere_map.jpg')
config = Config(buffers=2, samples=4)
window = pyglet.window.Window(width=background.width, height=background.height, config=config)
projection = Projection(0, 0, window.width, window.height)

def quad(min=0.0, max=1.0):
    glBegin(GL_QUADS)
    glTexCoord2f(1.0, 1.0)
    glVertex3f(max, max, 0.0)
    glTexCoord2f(1.0, 0.0)
    glVertex3f(max, min, 0.0)
    glTexCoord2f(0.0, 0.0)
    glVertex3f(min, min, 0.0)
    glTexCoord2f(0.0, 1.0)
    glVertex3f(min, max, 0.0)
    glEnd()

def simulate(delta, _):
    global rotation
    rotation += 40.0 * delta

class Bunny(object):
Ejemplo n.º 3
0
Archivo: app.py Proyecto: seken/nink
	def __init__(self, map_name, path):
		super(Application, self).__init__(resizable=True, width=512, height=512, caption='Nink saves the town')
		
		# Start screen
		self.menuTexture = Texture.open(path+'/images/start.png', unit=GL_TEXTURE0, filter=GL_NEAREST)
		self.husbTexture = Texture.open(path+'/images/husb_death.png', unit=GL_TEXTURE0, filter=GL_NEAREST)
		self.ninkTexture = Texture.open(path+'/images/nink_death.png', unit=GL_TEXTURE0, filter=GL_NEAREST)
		self.winTexture = Texture.open(path+'/images/win.png', unit=GL_TEXTURE0, filter=GL_NEAREST)
		self.make_menu_mesh()
		
		# Healthbar
		self.heart = Texture.open(path+'/images/heart.png', unit=GL_TEXTURE0, filter=GL_NEAREST)
		self.make_heart_meshes()
		
		# Sounds
		self.bg_music = pyglet.media.load(path+'/sound/TIGshot.mp3')
		self.win_sound = pyglet.media.load(path+'/sound/win.wav')
		self.hurt_sound = pyglet.media.StaticSource(pyglet.media.load(path+'/sound/hurt.wav'))
		self.pickup_sound = pyglet.media.StaticSource(pyglet.media.load(path+'/sound/pickup.wav'))
		self.arrow_sound = pyglet.media.StaticSource(pyglet.media.load(path+'/sound/arrow.wav'))
		self.death_sound = pyglet.media.StaticSource(pyglet.media.load(path+'/sound/death.wav'))
		self.goblin_death_sound = pyglet.media.StaticSource(pyglet.media.load(path+'/sound/goblin_death.wav'))
		self.follow_sound = pyglet.media.StaticSource(pyglet.media.load(path+'/sound/follow.wav'))
		
		self.scale = 96/2
		self.time = 0
		self.game = 0
		self.camera = Matrix()
		self.camera = self.camera.translate(0, -5, -10)
		self.path = path
		
		# Main shader
		self.program = ShaderProgram.open(path+'/shaders/main.shader')
		self.program.vars.tex = Sampler2D(GL_TEXTURE0)
		
		# Map
		self.map_name = map_name
		mapimg = pyglet.image.load(path+'/map/'+map_name+'.png')
		self.ground = self.create_ground(mapimg)
		self.walls = self.create_walls(mapimg)
		self.create_minimap()
		
		# Normal Mesh
		position = [
			-0.5, -0.5, 0,
			-0.5, 0.5, 0,
			0.5, 0.5, 0,
			0.5, -0.5, 0,
		]
		texCoord = [
			0, 0,
			0, 1,
			1, 1,
			1, 0,
		]
		normal = [
			0, 0, 1,
			0, 0, 1,
			0, 0, 1,
			0, 0, 1,
		]
		position = (c_float*len(position))(*position)
		texCoord = (c_float*len(texCoord))(*texCoord)
		normal = (c_float*len(normal))(*normal)
		self.normal_mesh = VBO(4,
			position_3=position,
			texCoord_2=texCoord,
			normal_3=normal)
		# Gold Mesh
		position = [
			-0.25, -0.25, 0,
			-0.25, 0.25, 0,
			0.25, 0.25, 0,
			0.25, -0.25, 0,
		]
		texCoord = [
			0, 0,
			0, 1,
			1, 1,
			1, 0,
		]
		normal = [
			0, 0, 1,
			0, 0, 1,
			0, 0, 1,
			0, 0, 1,
		]
		position = (c_float*len(position))(*position)
		texCoord = (c_float*len(texCoord))(*texCoord)
		normal = (c_float*len(normal))(*normal)
		self.gold_mesh = VBO(4,
			position_3=position,
			texCoord_2=texCoord,
			normal_3=normal)
		
		# Friend texture
		character = pyglet.image.load(path+'/images/others.png')
		self.friendTex = Texture(character.width, character.height, data=character.get_data('RGBA', character.width*4))
		
		# Gold texture
		gold = pyglet.image.load(path+'/images/gold.png')
		self.goldTex = Texture(gold.width, gold.height, data=gold.get_data('RGBA', gold.width*4))
		
		# Arrow texture
		arrow = pyglet.image.load(path+'/images/arrow.png')
		self.arrowTex = Texture(arrow.width, arrow.height, data=arrow.get_data('RGBA', arrow.width*4))
		
		# Game state
		self.arrows = []
		self.enemy = []
		self.friendly = []	
		self.gold = []
			
		# Datapoints
		points = csv.reader(open(path+'/map/'+map_name+'.txt', 'rb'), delimiter=',')
		for row in points:
			point = (((float(row[1])+0.5)/mapimg.width * self.scale*2) - self.scale, ((float(row[2])-0.5)/mapimg.width * self.scale*2) - self.scale)
			if row[0] == 'start':
				self.start_point = Vector(point[0], 0, point[1])
				self.player = self.create_protagonist(self.walls.collisionMap, point)
			elif row[0] == 'husband':
				h = self.create_husband(self.walls.collisionMap, point)
				h.husband = True
				self.friendly.append(h)
				self.husband = h
			elif row[0] == 'friend':
				self.friendly.append(self.create_friend(self.walls.collisionMap, point, self.friendTex))
			elif row[0] == 'gold':
				self.gold.append(self.create_gold(self.walls.collisionMap, point))
			elif row[0] == 'enemy':
				self.enemy.append(self.create_enemy(self.walls.collisionMap, point))
				
		pyglet.clock.schedule_interval(lambda x: self.on_update(x), 1.0/50.0)
		glEnable(GL_DEPTH_TEST)
		glDepthFunc(GL_LEQUAL)
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		self.keys = key.KeyStateHandler()
		self.push_handlers(self.keys)
Ejemplo n.º 4
0
            self.vbo.normals.copy_from(self.normal_texture)

    def draw(self):
        self.vbo.draw(GL_TRIANGLES)


if __name__ == '__main__':
    window = pyglet.window.Window(fullscreen=True)
    projection = Projection(0,
                            0,
                            window.width,
                            window.height,
                            near=0.1,
                            far=100)
    angle = ChangeValue()
    texture = Texture.open('images/heightmap.png')
    heightmap = Heightmap(texture.width, texture.height)
    sun = Sun()

    @window.event
    def on_draw():
        window.clear()

        heightmap.update_from(texture)

        with nested(projection, Color, sun):
            glColor3f(0.5, 0.5, 0.5)
            glPushMatrix()
            glTranslatef(0, 0, -1)
            glRotatef(20, 1, 0, 0)
            glRotatef(angle, 0.0, 1.0, 0.0)
Ejemplo n.º 5
0
from __future__ import with_statement
from contextlib import nested

import pyglet
from gletools import Texture, Projection, DepthTest, SphereMapping, Matrix
from gletools.gl import *

rotation = 0
background = Texture.open('background.jpg')
sphere_map = Texture.open('sphere_map.jpg')
config = Config(buffers=2, samples=4)
window = pyglet.window.Window(width=background.width,
                              height=background.height,
                              config=config)
projection = Projection(0, 0, window.width, window.height)


def quad(min=0.0, max=1.0):
    glBegin(GL_QUADS)
    glTexCoord2f(1.0, 1.0)
    glVertex3f(max, max, 0.0)
    glTexCoord2f(1.0, 0.0)
    glVertex3f(max, min, 0.0)
    glTexCoord2f(0.0, 0.0)
    glVertex3f(min, min, 0.0)
    glTexCoord2f(0.0, 1.0)
    glVertex3f(min, max, 0.0)
    glEnd()


def simulate(delta, _):
Ejemplo n.º 6
0
    Texture, Framebuffer, Depthbuffer, Sampler2D,
    Projection, Screen, 
)
from gletools.gl import *

window = pyglet.window.Window()

framebuffer = Framebuffer()
framebuffer.textures = [
    Texture(window.width, window.height, filter=GL_LINEAR),
    Texture(window.width, window.height, filter=GL_LINEAR),
    Texture(window.width, window.height, filter=GL_LINEAR, unit=GL_TEXTURE1),
]
framebuffer.depth = Depthbuffer(window.width, window.height)

picture = Texture.open('texture.png')

depth_shader = VertexShader('''
    varying float depth;
    void main()
    {
        depth = -(gl_ModelViewMatrix * gl_Vertex).z;
        gl_TexCoord[0] = gl_MultiTexCoord0;
        gl_Position = ftransform();
        gl_FrontColor = gl_Color;
    }

''')

blur = ShaderProgram(
    depth_shader,
Ejemplo n.º 7
0
    Projection,
    Screen,
)
from gletools.gl import *

window = pyglet.window.Window()

framebuffer = Framebuffer()
framebuffer.textures = [
    Texture(window.width, window.height, filter=GL_LINEAR),
    Texture(window.width, window.height, filter=GL_LINEAR),
    Texture(window.width, window.height, filter=GL_LINEAR, unit=GL_TEXTURE1),
]
framebuffer.depth = Depthbuffer(window.width, window.height)

picture = Texture.open('texture.png')

depth_shader = VertexShader('''
    varying float depth;
    void main()
    {
        depth = -(gl_ModelViewMatrix * gl_Vertex).z;
        gl_TexCoord[0] = gl_MultiTexCoord0;
        gl_Position = ftransform();
        gl_FrontColor = gl_Color;
    }

''')

blur = ShaderProgram(
    depth_shader,
Ejemplo n.º 8
0
    def update_from(self, source):
        with nested(self.fbo, self.view, source, self.program):
            quad(self.width, self.height, 0, 0)
            self.vbo.vertices.copy_from(self.vertex_texture)
            self.vbo.normals.copy_from(self.normal_texture)

    def draw(self):
        self.vbo.draw(GL_TRIANGLES)


if __name__ == "__main__":
    window = pyglet.window.Window(fullscreen=True)
    projection = Projection(0, 0, window.width, window.height, near=0.1, far=100)
    angle = ChangeValue()
    texture = Texture.open("images/heightmap.png")
    heightmap = Heightmap(texture.width, texture.height)
    sun = Sun()

    @window.event
    def on_draw():
        window.clear()

        heightmap.update_from(texture)

        with nested(projection, Color, sun):
            glColor3f(0.5, 0.5, 0.5)
            glPushMatrix()
            glTranslatef(0, 0, -1)
            glRotatef(20, 1, 0, 0)
            glRotatef(angle, 0.0, 1.0, 0.0)