Exemplo n.º 1
0
def WriteAllPrograms():
    global boxProgram
    global rimProgram
    global cornerProgram
    WriteShaderProgram('/tmp/bevelBoxFlat.shader.tmp',
                       'bevelBoxFlat.shader',
                       {'__SPACING': spacingStr})
    WriteShaderProgram('/tmp/bevelBoxRim.shader.tmp',
                       'bevelBoxRim.shader',
                       {'__SPACING': spacingStr})
    WriteShaderProgram('/tmp/bevelBoxCorner.shader.tmp',
                       'bevelBoxCorner.shader',
                       {'__SPACING': spacingStr})

    boxProgram = ShaderProgram.open('/tmp/bevelBoxFlat.shader.tmp',
        inner_level = 1.0,
        outer_level = 1.0
    )
    rimProgram = ShaderProgram.open('/tmp/bevelBoxRim.shader.tmp',
        inner_level = 1.0,
        outer_level = 1.0
    )
    cornerProgram = ShaderProgram.open('/tmp/bevelBoxCorner.shader.tmp',
        inner_level = 1.0,
        outer_level = 1.0
    )
    auxLabel.text = 'Spacing: %s' % spacingStr
Exemplo n.º 2
0
def WriteAllPrograms():
    global trisProgram
    global quadsProgram
    WriteShaderProgram("/tmp/tris.shader.tmp", "tris.shader", {"__SPACING": spacingStr})
    WriteShaderProgram("/tmp/quads.shader.tmp", "quads.shader", {"__SPACING": spacingStr})

    trisProgram = ShaderProgram.open("/tmp/tris.shader.tmp", inner_level=1.0, outer_level=1.0)
    quadsProgram = ShaderProgram.open("/tmp/quads.shader.tmp", inner_level=1.0, outer_level=1.0)
    auxLabel.text = "Spacing: %s" % spacingStr
Exemplo n.º 3
0
Arquivo: genMap.py Projeto: seken/nink
	def __init__(self):
		super(Application, self).__init__(resizable=True)
		self.mapSize = 64
		self.mapTexture = Texture(self.mapSize, self.mapSize, data=[0,0,0,255]*(self.mapSize*self.mapSize))
		
		self.probContinue = 0.79
		self.minSquares = 10
		
		# keep away from start and friends (and gold)
		self.goblin_distance = 10
		
		# min distance from start
		self.husband_distance = 30
		
		# probability of placement
		self.prob_goblin = 0.1
		self.prob_friend = 0.1
		self.prob_gold = 0.1
		self.prob_king = 0.01
		self.prob_husband = 0.01
		
		self.new_map()
		
		self.program = ShaderProgram.open('shaders/main.shader')
		self.program.vars.tex = Sampler2D(GL_TEXTURE0)
Exemplo n.º 4
0
Arquivo: ground.py Projeto: seken/nink
	def __init__(self, texture, tiles, tdim, res, minc, maxc, path):
		super(Ground, self).__init__()
		self.map = texture
		self.tiles = tiles
		self.prog = ShaderProgram.open(path+'/shaders/ground.shader')
		self.prog.vars.map = Sampler2D(GL_TEXTURE0)
		self.prog.vars.tiles = Sampler2D(GL_TEXTURE1)
		self.prog.vars.tNumX = tdim.x
		self.prog.vars.tNumY = tdim.y;
		self.prog.vars.tAmount = tdim.z;
		self.prog.vars.resX = 1.0/res.x
		self.prog.vars.resY = 1.0/res.y
		self.min = minc
		self.max = maxc
		with nested(self.map):
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
		with nested(self.tiles):
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
		position = [
				self.min.x, 0, self.min.y,
				self.min.x, 0, self.max.y,
				self.max.x, 0, self.max.y,
				self.max.x, 0, self.min.y,
		]
		texCoord = [
			0, 0,
			0, 1,
			1, 1,
			1, 0,
		]
		position = (c_float*len(position))(*position)
		texCoord = (c_float*len(texCoord))(*texCoord)
		self.mesh = VBO(4,
			position_3=position,
			texCoord_2=texCoord)
Exemplo n.º 5
0
Arquivo: walls.py Projeto: seken/nink
	def __init__(self, texture, tiles, tdim, res, minc, maxc, path):
		super(Walls, self).__init__()
		self.map = texture
		self.tiles = tiles
		self.prog = ShaderProgram.open(path+'/shaders/wall.shader')
		self.prog.vars.map = Sampler2D(GL_TEXTURE0)
		self.prog.vars.tiles = Sampler2D(GL_TEXTURE1)
		self.prog.vars.tNumX = tdim.x
		self.prog.vars.tNumY = tdim.y;
		self.prog.vars.tAmount = tdim.z;
		self.prog.vars.resX = 1.0/res.x
		self.prog.vars.resY = 1.0/res.y
		self.min = minc
		self.max = maxc
		self.dimc = Vector(maxc.x - minc.x, maxc.y - minc.y, maxc.z - minc.z)
		self.tdim = tdim
		self.height = 1.5
		with nested(self.map):
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
		with nested(self.tiles):
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
		self.create_mesh()
Exemplo n.º 6
0
window = pyglet.window.Window()
rotation = 0.0

vbo = VBO(
    count       = 6,
    indices     = [0, 1, 2, 0, 2, 3],
    position_4  = [
        +1, +1, 0, 1,
        +1, -1, 0, 1,
        -1, -1, 0, 1,
        -1, +1, 0, 1,
    ],
)

program = ShaderProgram.open('triangles.shader',
    inner_level = 8.0,
    outer_level = 8.0,
)

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

pyglet.clock.schedule(simulate, 0.03)

@window.event
def on_draw():
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    window.clear()

    program.vars.modelview = Matrix().translate(0,0,-3).rotatex(-0.175).rotatez(rotation)
    program.vars.projection = Matrix.perspective(window.width, window.height, 60, 0.1, 100.0)
Exemplo n.º 7
0
from pyglet.gl import *
from gletools import ShaderProgram

from pyglet import clock
from pyglet import font

from external import Camera, World, Player

import Image

from ctypes import c_byte

import console
import controller

program = ShaderProgram.open('shaders/main.shader')

# Set up the Window (pyglet)
config = Config(buffers=2, samples=4)
window = pyglet.window.Window(caption='GlBlox',
                              width=1152,
                              height=864,
                              config=config,
                              vsync=False,
                              fullscreen=False)
window.set_exclusive_mouse(True)

console_font = font.load('Consolas', 14, bold=False, italic=False)

status = console.StatusConsole(x=window.width * 0.005,
                               y=window.height * 0.98,
Exemplo n.º 8
0
import pyglet
from pyglet.gl import *
from gletools import ShaderProgram, VertexObject, Matrix, VBO

from heightfield import Heightfield
from terrain import Terrain
from util import View

window = pyglet.window.Window(fullscreen=True, vsync=False)
view = View(window)
rotation = 0.0

heightfield = Heightfield()
terrain = Terrain(heightfield)

program = ShaderProgram.open('triangles.shader')

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

pyglet.clock.schedule(simulate, 0.03)

@window.event
def on_draw():
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glEnable(GL_CULL_FACE)
    glCullFace(GL_BACK)
    window.clear()
    
    model = Matrix().translate(-0.5, 0.0, 0.0)
Exemplo n.º 9
0
window = pyglet.window.Window()
rotation = 0.0

vbo = VertexObject(
    indices = [0, 1, 2, 3],
    v4f     = [
        +1, +1, 0, 1,
        +1, -1, 0, 1,
        -1, -1, 0, 1,
        -1, +1, 0, 1,
    ],
)

program = ShaderProgram.open('quads.shader',
    inner_level = 1.0,
    outer_level = 1.0,
    simple      = False,
)

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

pyglet.clock.schedule(simulate, 0.03)

@window.event
def on_draw():
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    window.clear()

    program.vars.modelview = Matrix().translate(0,0,-3).rotatex(-0.175).rotatez(rotation)
Exemplo n.º 10
0
window = pyglet.window.Window(config=config, fullscreen=True, vsync=False)
view = View(window)

size = 1024*4
diffuse = Texture.raw_open('data/patches/snowy_mountains.diffuse', 
    width=size, height=size, format=GL_RGBA32F,
    mipmap=4, filter=GL_LINEAR_MIPMAP_LINEAR, clamp='st',
    unit=GL_TEXTURE0,
)
terrain = Texture.raw_open('data/patches/snowy_mountains.terrain',
    width=size, height=size, format=GL_RGBA32F,
    unit=GL_TEXTURE1, clamp='st',
)

program = ShaderProgram.open('terrain.shader',
    diffuse = Sampler2D(GL_TEXTURE0),
    terrain = Sampler2D(GL_TEXTURE1),
)

normals = ShaderProgram.open('normals.shader')

vbo = make_triangles(128, 128, terrain)
fps = pyglet.clock.ClockDisplay(color=(144.0/255.0,195.0/255.0,6.0/255.0,0.5))

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

    model = Matrix().rotatex(-0.25).translate(-0.5, -0.5, 0.0)
    projection = Matrix.perspective(window.width, window.height, 65, 0.0001, 100.0)
    modelview = view.matrix * model
Exemplo n.º 11
0
        0,
        1,
        -1,
        -1,
        0,
        1,
        -1,
        +1,
        0,
        1,
    ],
)

program = ShaderProgram.open(
    'triangles.shader',
    inner_level=8.0,
    outer_level=8.0,
)


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


pyglet.clock.schedule(simulate, 0.03)


@window.event
def on_draw():
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
Exemplo n.º 12
0
from pyglet.gl import *
from gletools import ShaderProgram

from pyglet import clock
from pyglet import font

from external import Camera, World, Player

import Image

from ctypes import c_byte

import console
import controller

program = ShaderProgram.open("shaders/main.shader")

# Set up the Window (pyglet)
config = Config(buffers=2, samples=4)
window = pyglet.window.Window(caption="GlBlox", width=1152, height=864, config=config, vsync=False, fullscreen=False)
window.set_exclusive_mouse(True)

console_font = font.load("Consolas", 14, bold=False, italic=False)

status = console.StatusConsole(x=window.width * 0.005, y=window.height * 0.98, width=window.width)

console = console.Console(x=window.width * 0.005, y=window.height * 0.70, width=window.width)

status.addParameter("FPS")
status.addParameter("Vertices")
status.addParameter("Position")
Exemplo n.º 13
0
Arquivo: app.py Projeto: 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)
Exemplo n.º 14
0
        0,
        1,
        -1,
        -1,
        0,
        1,
        -1,
        +1,
        0,
        1,
    ],
)

program = ShaderProgram.open(
    'quads.shader',
    inner_level=1.0,
    outer_level=1.0,
    simple=False,
)


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


pyglet.clock.schedule(simulate, 0.03)


@window.event
def on_draw():
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
Exemplo n.º 15
0
            p3 = p2 + 1
            indices[offset:offset + 4] = p1, p2, p3, p4

    return VertexObject(
        indices=indices,
        v4f=v4f,
    )


window = pyglet.window.Window(vsync=False)
rotation = 0.0
vbo = make_plane(32, 32)

linear = ShaderProgram.open(
    'quads.shader',
    inner_level=16.0,
    outer_level=16.0,
    simple=True,
)

lod = ShaderProgram.open(
    'lod.shader',
    pixels_per_division=15.0,
    projected=False,
)

fps = pyglet.clock.ClockDisplay(color=(1, 0, 0, 0.5))


@window.event
def on_draw():
    window.clear()
Exemplo n.º 16
0
import pyglet
from pyglet.gl import *
from gletools import ShaderProgram, VertexObject, Matrix, VBO

from heightfield import Heightfield
from terrain import Terrain
from util import View

window = pyglet.window.Window(fullscreen=True, vsync=False)
view = View(window)
rotation = 0.0

heightfield = Heightfield()
terrain = Terrain(heightfield)

program = ShaderProgram.open('triangles.shader')


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


pyglet.clock.schedule(simulate, 0.03)


@window.event
def on_draw():
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glEnable(GL_CULL_FACE)
    glCullFace(GL_BACK)
Exemplo n.º 17
0
            p4 = p1+1
            p3 = p2+1
            indices[offset:offset+4] = p1, p2, p3, p4

    return VertexObject(
        indices = indices,
        v4f     = v4f,
    )

window = pyglet.window.Window(vsync=False)
rotation = 0.0
vbo = make_plane(32, 32)

linear = ShaderProgram.open('quads.shader',
    inner_level = 16.0,
    outer_level = 16.0,
    simple      = True,
)

lod = ShaderProgram.open('lod.shader',
    pixels_per_division = 15.0,
    projected = False,
)

fps = pyglet.clock.ClockDisplay(color=(1,0,0,0.5))

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

    program = lod
Exemplo n.º 18
0
    filter=GL_LINEAR_MIPMAP_LINEAR,
    clamp='st',
    unit=GL_TEXTURE0,
)
terrain = Texture.raw_open(
    'data/patches/snowy_mountains.terrain',
    width=size,
    height=size,
    format=GL_RGBA32F,
    unit=GL_TEXTURE1,
    clamp='st',
)

program = ShaderProgram.open(
    'terrain.shader',
    diffuse=Sampler2D(GL_TEXTURE0),
    terrain=Sampler2D(GL_TEXTURE1),
)

normals = ShaderProgram.open('normals.shader')

vbo = make_triangles(128, 128, terrain)
fps = pyglet.clock.ClockDisplay(color=(144.0 / 255.0, 195.0 / 255.0,
                                       6.0 / 255.0, 0.5))


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

    model = Matrix().rotatex(-0.25).translate(-0.5, -0.5, 0.0)