Ejemplo 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
Ejemplo 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
Ejemplo n.º 3
0
    def __init__(self, processor):
        self.processor = processor 
        off = (1.0/processor.width)*1.2, (1.0/processor.height)*1.2
        self.vertical = ShaderProgram(
            FragmentShader.open('shaders/gaussian/vertical.frag'),
            off = off,
        )

        self.horizontal = ShaderProgram(
            FragmentShader.open('shaders/gaussian/horizontal.frag'),
            off = off,
        )
Ejemplo n.º 4
0
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.framebuffer = Framebuffer()
        self.tex1 = Texture(width,
                            height,
                            filter=GL_NEAREST,
                            format=GL_RGBA32F,
                            clamp='st')
        self.tex2 = Texture(width,
                            height,
                            filter=GL_NEAREST,
                            format=GL_RGBA32F,
                            clamp='st')
        self.tex3 = Texture(width,
                            height,
                            filter=GL_NEAREST,
                            format=GL_RGBA32F,
                            clamp='st')

        self.program = ShaderProgram(
            FragmentShader.open('shaders/ripples.frag'),
            offsets=(1.0 / width, 1.0 / height),
            tex2=Sampler2D(GL_TEXTURE1),
            tex3=Sampler2D(GL_TEXTURE2),
        )
Ejemplo n.º 5
0
Archivo: genMap.py Proyecto: 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)
Ejemplo n.º 6
0
 def init_program(self):
     self.near = 0.25
     self.far = 3.0
     self.fov = 120.0
     self.program = ShaderProgram(
             VertexShader.open(os.path.join(os.path.dirname(__file__) , 'opglex/shaders/simple.vert')),
             FragmentShader.open(os.path.join(os.path.dirname(__file__), 'opglex/shaders/simple.frag')),
             offset = [0.0, 0.0, 0.0],
             perspectiveMatrix = Matrix.perspective(self.width, self.height, self.fov, self.near, self.far)
     )
Ejemplo n.º 7
0
def Sun(color=(1.0, 1.0, 1.0),
        direction=(0.5, -0.5, 0.0),
        ambient=(0.1, 0.1, 0.1)):
    return ShaderProgram(
        VertexShader.open('shaders/sun.vert'),
        FragmentShader.open('shaders/sun.frag'),
        color=color,
        direction=direction,
        ambient=ambient,
    )
Ejemplo n.º 8
0
 def shader(self, *names, **kwargs):
     if names in self.shaders:
         return self.shaders[names]
     else:
         shader = ShaderProgram(
             *[
                 FragmentShader.open(res_open(here('shaders/%s' % name)))
                 if name.endswith('.frag') else VertexShader.open(
                     res_open(here('shaders/%s' % name))) for name in names
             ], **kwargs)
         self.shaders[names] = shader
         return shader
Ejemplo n.º 9
0
    def __init__(self, **kwargs):
        super(Knot_Display, self).__init__(**kwargs)

        self.program = ShaderProgram(
	    FragmentShader.open('test.frag'),
            VertexShader.open('test.vert')
        )
	
	self.numpoints = 100000
	self.point_size = (4*4 + 4)
	
	# create_buffer(size, target=34962, usage=35048, vbo=True)
	self.vbos = []
	for i in range(2):
	    vbo = pyglet.graphics.vertexbuffer.create_buffer( self.numpoints*self.point_size, GL_ARRAY_BUFFER, GL_STREAM_DRAW )
	    self.vbos.append(vbo)
	print len(self.vbos)
Ejemplo n.º 10
0
    def __init__(self, width, height, scale=0.2):
        self.width = width
        self.height = height
        self.view = Screen(0, 0, width, height)

        self.vertex_texture = Texture(width, height, GL_RGBA32F)
        self.normal_texture = Texture(width, height, GL_RGBA32F)
        self.fbo = Framebuffer(
            self.vertex_texture,
            self.normal_texture,
        )
        self.fbo.drawto = GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT

        self.program = ShaderProgram(
            FragmentShader.open('shaders/heightmap_normal.frag'),
            offsets=(1.0 / width, 1.0 / height),
            scale=scale,
        )
        self.vbo = self.generate_vbo(width, height)
Ejemplo n.º 11
0
Archivo: ground.py Proyecto: 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)
Ejemplo n.º 12
0
Archivo: walls.py Proyecto: 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()
Ejemplo n.º 13
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)
Ejemplo n.º 14
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
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
class Knot_Display(pyglet.window.Window):

    def __init__(self, **kwargs):
        super(Knot_Display, self).__init__(**kwargs)

        self.program = ShaderProgram(
	    FragmentShader.open('test.frag'),
            VertexShader.open('test.vert')
        )
	
	self.numpoints = 100000
	self.point_size = (4*4 + 4)
	
	# create_buffer(size, target=34962, usage=35048, vbo=True)
	self.vbos = []
	for i in range(2):
	    vbo = pyglet.graphics.vertexbuffer.create_buffer( self.numpoints*self.point_size, GL_ARRAY_BUFFER, GL_STREAM_DRAW )
	    self.vbos.append(vbo)
	print len(self.vbos)
	
    def on_resize(self, width, height):
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(-1, 1, -1, 1)
        glMatrixMode(GL_MODELVIEW)
	glLoadIdentity()

        glDisable(GL_DEPTH_TEST)
        return pyglet.event.EVENT_HANDLED

    def on_mouse_press(self, x, y, button, modifiers):
        # self.set_exclusive_mouse()
        return

    def on_mouse_release(self, x, y, button, modifiers):
        # self.set_exclusive_mouse(exclusive=False)
        return

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        # rotate on left-drag
        return

    def on_draw(self): 
	# Specify the source buffer
        self.vbos[0].target = GL_ARRAY_BUFFER
	self.vbos[0].bind()
	glEnableVertexAttribArray(0)
	glEnableVertexAttribArray(1)
	glEnableVertexAttribArray(2)
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, self.point_size, 0)
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, self.point_size, 8)
	glVertexAttribPointer(2, 1, GL_UNSIGNED_INT, GL_FALSE, self.point_size, 16)

	# Specify the target buffer
	self.vbos[1].target = GL_TRANSFORM_FEEDBACK_BUFFER
	self.vbos[1].bind()
	
	# Specify transform feedback output
	LP_c_char = ctypes.POINTER(ctypes.c_char)
	LP_LP_c_char = ctypes.POINTER(LP_c_char)
	ptrs = [ ctypes.cast(ctypes.byref(ctypes.c_char_p(str)), LP_c_char) for str in ['oPosition', 'oVelocity', 'oSeed'] ]
	c_array = ctypes.cast(ctypes.byref(LP_c_char(ptrs)), LP_LP_c_char)
	glTransformFeedbackVaryings(self.program.id, len(ptrs), c_array, GL_INTERLEAVED_ATTRIBS)
	self.program.link()
	
	# Perform simulation step
	with self.program:
	    glEnable(GL_RASTERIZER_DISCARD);
	    glBeginTransformFeedback(GL_POINTS)
	    glDrawArrays(GL_POINTS, 0, self.numpoints)
	    glEndTransformFeedback()
	    glDisable(GL_RASTERIZER_DISCARD);

	with self.program:
	    # Draw points
            glPointSize(1.8)
            glBegin(GL_POINTS)
            glDrawArrays(GL_POINTS, 0, self.numpoints)
	    glEnd()

	self.vbos[0].unbind()
Ejemplo n.º 17
0
from gletools.gl import *

window = pyglet.window.Window()
texture = Texture(256, 256, filter=GL_LINEAR)
framebuffer = Framebuffer()
framebuffer.textures[0] = texture
screen = Screen(0, 0, texture.width, texture.height)
projection = Projection(0, 0, window.width, window.height)
program = ShaderProgram(
    FragmentShader('''
    uniform vec3 seed_vector;
    float nice_noise1(vec2 co){
        return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
    }
    void main(){
        gl_FragColor = vec4(
            nice_noise1(gl_TexCoord[0].xy * seed_vector.x),
            nice_noise1(gl_TexCoord[0].xy * seed_vector.y),
            nice_noise1(gl_TexCoord[0].xy * seed_vector.z),
            0
        );
    }''')
)
from random import random
program.vars.seed_vector = [random() for _ in xrange(3)]
rotation = 0.0

def quad(min=0.0, max=1.0):
    glBegin(GL_QUADS)
    glTexCoord2f(1.0, 1.0)
    glVertex3f(max, max, 0.0)
Ejemplo n.º 18
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)
Ejemplo n.º 19
0
class World(pyglet.window.Window):
    
    def __init__(self, *args, **kwargs):
        super(World, self).__init__(*args, **kwargs)

        self.init()
    

    def init_program(self):
        self.near = 0.25
        self.far = 3.0
        self.fov = 120.0
        self.program = ShaderProgram(
                VertexShader.open(os.path.join(os.path.dirname(__file__) , 'opglex/shaders/simple.vert')),
                FragmentShader.open(os.path.join(os.path.dirname(__file__), 'opglex/shaders/simple.frag')),
                offset = [0.0, 0.0, 0.0],
                perspectiveMatrix = Matrix.perspective(self.width, self.height, self.fov, self.near, self.far)
        )

    def init_vertex_buffer(self):
        self.vertex_buffer_object = GLuint()
        self.index_buffer_object = GLuint()

        glGenBuffers(1, self.vertex_buffer_object)

        glBindBuffer(GL_ARRAY_BUFFER, self.vertex_buffer_object)
        glBufferData(GL_ARRAY_BUFFER, size_of(vertex_data), vertex_data.ctypes.data, GL_STATIC_DRAW)
        glBindBuffer(GL_ARRAY_BUFFER, 0)

        glGenBuffers(1, self.index_buffer_object)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.index_buffer_object)
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, size_of(index_data), index_data.ctypes.data, GL_STATIC_DRAW)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)

    def init_vaos(self):
        self.vao1 = GLuint()
        glGenVertexArrays(1, self.vao1)
        glBindVertexArray(self.vao1)

        color_data_offset = sizeof(GLfloat) * 3 * n_vertices
        glBindBuffer(GL_ARRAY_BUFFER, self.vertex_buffer_object)
        glEnableVertexAttribArray(0)
        glEnableVertexAttribArray(1)
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0)
        glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, color_data_offset)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.index_buffer_object)
        glBindVertexArray(0)
        
        self.vao2 = GLuint()
        glGenVertexArrays(1, self.vao2)
        glBindVertexArray(self.vao2)

        pos_data_offset    = sizeof(GLfloat) * 3 * (n_vertices / 2)
        color_data_offset += sizeof(GLfloat) * 4 * (n_vertices / 2)
        
        glEnableVertexAttribArray(0)
        glEnableVertexAttribArray(1)
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, pos_data_offset)
        glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, color_data_offset)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.index_buffer_object)

        glBindVertexArray(0)

    def init(self):
        
        self.init_program()
        pyglet.clock.schedule(lambda dt: None)
        self.fps = pyglet.clock.ClockDisplay()
        self.init_vertex_buffer()
        self.init_vaos()
                
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)
        glFrontFace(GL_CW)

        glEnable(GL_DEPTH_TEST)
        glDepthMask(GL_TRUE)
        glDepthFunc(GL_LEQUAL)
        glDepthRange(0.0, 1.0)

    def on_draw(self):
#        print 'draw!'
#        x, y = self.comp_offset()
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glClearDepth(1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        with self.program:
            glBindVertexArray(self.vao1)
            glUniform3f(self.program.uniform_location('offset'), 0.0, 0.0, 0.0)
            glDrawElements(GL_TRIANGLES, size_of(index_data), GL_UNSIGNED_SHORT, 0)

            glBindVertexArray(self.vao2)
            glUniform3f(self.program.uniform_location('offset'), 0.0, 0.0, 1.0 )
            glDrawElements(GL_TRIANGLES, size_of(index_data), GL_UNSIGNED_SHORT, 0)

            glBindVertexArray(0)

        self.fps.draw()

    def on_resize(self, w, h):
#        print 'resizing'
        self.program.vars['perspectiveMatrix'] = Matrix.perspective(w, h, self.fov, self.near, self.far)
        glViewport(0, 0, w, h)
        
    def on_key_press(self, symbol, modifiers):
        print 'key pressed'
        if symbol == pyglet.window.key.ESCAPE:
            print 'escape'
            self.dispatch_event('on_close')
        elif symbol == pyglet.window.key.SPACE:
            try: depth_clamp
            except NameError:
                depth_clamp = False
            if depth_clamp:
                glDisable(GL_DEPTH_CLAMP)
            else:
                glEnable(GL_DEPTH_CLAMP)

            depth_clamp = not depth_clamp

    def comp_offset(self):
        spin_time = 5.0
        scale = math.pi * 2.0 / spin_time
        elapsed_ms = time.clock() / 10
        current_ms = elapsed_ms % spin_time
        x = math.cos(current_ms * scale) * 0.5
        y = math.sin(current_ms * scale) * 0.5
#        print x, y
        return x, y

    def on_close(self):
        print 'reactor stopping'
        reactor.callFromThread(reactor.stop)

        return True
Ejemplo n.º 20
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)
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
from contextlib import nested

import pyglet
from gletools import ShaderProgram, FragmentShader, Texture, Framebuffer, Projection, Screen
from gletools.gl import *

window = pyglet.window.Window()
texture = Texture(64, 64, filter=GL_LINEAR)
screen = Screen(0, 0, texture.width, texture.height)
projection = Projection(0, 0, window.width, window.height)
framebuffer = Framebuffer()
framebuffer.textures[0] = texture
program = ShaderProgram(
    FragmentShader('''
    uniform float size;
    void main(){
        vec4 vec = vec4(gl_FragCoord.x-size/2.0, gl_FragCoord.y-size/2.0, 0.0, 1.0) / size;
        gl_FragColor = (normalize(vec) + 1.0) / 2.0;
    }'''))
program.vars.size = 64.0
rotation = 0.0


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)
Ejemplo n.º 23
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
Ejemplo n.º 24
0
from contextlib import nested

import pyglet
from gletools import ShaderProgram, FragmentShader, Texture, Framebuffer, Sampler2D
from gletools.gl import *

from lif_parser import LifParser

window = pyglet.window.Window(fullscreen=True, vsync=False)

framebuffer = Framebuffer()
front = Texture(window.width, window.height, format=GL_RGB, filter=GL_NEAREST)
back = Texture(window.width, window.height, format=GL_RGB, filter=GL_NEAREST)
framebuffer.textures[0] = front

program = ShaderProgram(FragmentShader.open('shader.frag'), )
program.vars.width = float(front.width)
program.vars.height = float(front.height)
program.vars.texture = Sampler2D(GL_TEXTURE0)


def quad():
    glBegin(GL_QUADS)
    glTexCoord2f(1.0, 1.0)
    glVertex3f(window.width, window.height, 0.0)
    glTexCoord2f(1.0, 0.0)
    glVertex3f(window.width, 0.0, 0.0)
    glTexCoord2f(0.0, 0.0)
    glVertex3f(0.0, 0.0, 0.0)
    glTexCoord2f(0.0, 1.0)
    glVertex3f(0.0, window.height, 0.0)
Ejemplo n.º 25
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)
Ejemplo n.º 26
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)
Ejemplo n.º 27
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()
Ejemplo n.º 28
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,
Ejemplo n.º 29
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.º 30
0
from gletools.gl import *
from util import Mesh, Processor, Kernel, offsets, gl_init
from gaussian import Gaussian

### setup ###

window = pyglet.window.Window()
projection = Projection(0, 0, window.width, window.height, near=18, far=50)
texture = Texture(window.width, window.height, GL_RGBA32F)
bunny = Mesh('meshes/brain')
processor = Processor(texture)

### Shaders and helpers ###

depth = ShaderProgram(
    VertexShader.open('shaders/normal.vert'),
    FragmentShader.open('shaders/depth.frag'),
)

average = ShaderProgram(
    VertexShader.open('shaders/normal.vert'),
    FragmentShader.open('shaders/convolution.frag'),
    kernel_size = 3*3,
    kernel = UniformArray(float, 1, [
        1,  1,  1,
        1,  1,  1,
        1,  1,  1,
    ]),
    output_factor = 1.0/9.0,
    input_factor = 1.0,
    offsets = offsets(-1, 1, window),
)
Ejemplo n.º 31
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")
Ejemplo n.º 32
0
from __future__ import with_statement
from contextlib import nested

import pyglet
from gletools import ShaderProgram, FragmentShader, Texture, Framebuffer, Projection, Screen
from gletools.gl import *

from random import random
from util import quad, Processor, ChangeValue
from gaussian import Gaussian

window = pyglet.window.Window()
projection = Projection(0, 0, window.width, window.height)
noise = ShaderProgram(
    FragmentShader.open('shaders/noise.frag'),
    seed=0.0,
)
width, height = 64, 64
noise_texture = Texture(width, height, format=GL_RGBA32F)
noise_processor = Processor(noise_texture)
texture = Texture(64, 64, format=GL_RGBA32F)
processor = Processor(texture)

noise_processor.filter(noise_texture, noise)
processor.copy(noise_texture, texture)
gaussian = Gaussian(processor)
gaussian.filter(texture, 2)

rotation = ChangeValue()

Ejemplo n.º 33
0
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,
    FragmentShader.open('shader.frag'),
)
blur.vars.width = float(window.width)
blur.vars.height = float(window.height)
blur.vars.texture = Sampler2D(GL_TEXTURE0)
blur.vars.depthmap = Sampler2D(GL_TEXTURE1)

depth = ShaderProgram(
    depth_shader,
    FragmentShader('''
        varying float depth;
        uniform sampler2D texture;
        void main(){
            vec4 color = texture2D(texture, gl_TexCoord[0].st);
            gl_FragData[0] = color;
            gl_FragData[1] = color;