Exemplo n.º 1
0
def init_shaders():
    global _shader, _shader_program, _vertex_shader_src, _fragment_shader_src
    vertex_shader = Shader(gl.GL_VERTEX_SHADER,
                           _SHADER_DIR + _vertex_shader_src)
    fragment_shader = Shader(gl.GL_FRAGMENT_SHADER,
                             _SHADER_DIR + _fragment_shader_src)
    _shader = ShaderProgramManager((vertex_shader, fragment_shader), True)
    return _shader.is_linked()
Exemplo n.º 2
0
def main():
    global screen,s,app,scale
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-d","--display",type='int',dest='display',default=720, help='original width')
    parser.add_option("-s","--screen" ,type='int',dest='screen' ,default=1440,help='upscaled width')
    parser.add_option("-o",dest='old' ,action='store_true',default=False,help='For 3:4 game')
    parser.add_option("-v",dest='vgl' ,action='store_true',default=False,help='Use virtualgl')
    parser.add_option("-f",dest='fsrcnnx3' ,action='store_true',default=False,help='Use fsrcnnx3')
    # parser.add_option("-w",dest='window' ,action='store_true',default=False,help='windows mode')
    opt,arg = parser.parse_args()
    h = opt.display
    w = int(h/3*4) if opt.old else int(h/9*16)
    uh = opt.screen
    scale = uh/h
    uw = int(scale*w)
    if len(arg)>0:
        app = arg[0]
        if opt.vgl:
            os.system(f"Xvfb :1 -screen 0 {w}x{h}x24 &")
            os.system(f"DISPLAY=:1 VGL_FORCEALPHA=1 VGL_DRAWABLE=pixmap vglrun wine explorer /desktop=name,{w}x{h} "+app+ " &")
            print("Use vgl")
            # os.system(f"VGL_FORCEALPHA=1 VGL_DRAWABLE=pixmap xvfb-run  -l --server-args=\"-screen 0 {w}x{h}x24\" vglrun wine explorer /desktop=name,{w}x{h} "+app+ " &")
            os.system("x11vnc -fs 0.9 -nocursor -display :1  > /dev/null 2>&1 &")
#            os.system("x0vncserver -display=:1 -localhost -SecurityTypes none > /dev/null 2>&1 &")
        else:
            os.system(f"xvfb-run  -l --server-args=\"-screen 0 {w}x{h}x24\" wine explorer /desktop=name,{w}x{h} "+app+ " &")
            os.system("x11vnc -nocursor -display :99  > /dev/null 2>&1 &")
        time.sleep(2)
    else:
        app = ""
        # exit()
    # os.system("x11vnc -nocursor -display :1  > /dev/null 2>&1 &")
    # os.system("x11vnc -nocursor -multiptr -display :99  > /dev/null 2>&1 &")
    # subprocess.call('x11vnc','-display',':99')
    time.sleep(1)
    pygame.init()
#    pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0))
    screen = pygame.display.set_mode((uw,uh), DOUBLEBUF| NOFRAME | OPENGL, 32)

    ctx = moderngl.create_context()
    if opt.fsrcnnx3:
        s = Shader(w,h,ctx,algo="/fsrcnnx3.glsl",scale=3)
    else:
        s = Shader(w,h,ctx,algo="/A4K_L_x2_denoise.glsl")
    v = Event()
    application = service.Application("rfb test") # create Application
    vncClient = internet.TCPClient('localhost', 5900, UpscaleFactory(v)) # create the service
    vncClient.setServiceParent(application)
    vncClient.startService()
    reactor.callLater(0.1, v.event_handle)
    reactor.run()
Exemplo n.º 3
0
    def __init__(self,
                 max_particles=50,
                 width=1,
                 height=15,
                 density=10):  # density is the ratio width/particle_size
        super().__init__()

        self.max_particles = max_particles
        self.width = width
        self.height = height
        self.density = density

        self.color_shader = Shader(UNIFORM_COLOR_VERT, UNIFORM_COLOR_FRAG)

        # creating the small cube for a single particle
        self.particle = [(-0.5, -0.5, -0.5), (0.5, -0.5, -0.5),
                         (0.5, 0.5, -0.5), (-0.5, 0.5, -0.5),
                         (-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (0.5, 0.5, 0.5),
                         (-0.5, 0.5, 0.5)]
        self.particle_quad = VertexArray(
            [self.particle],
            (0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 0, 4, 3, 3, 4, 7, 1, 2, 5, 2,
             6, 5, 2, 3, 7, 2, 7, 6, 0, 1, 4, 1, 5, 4))

        self.particles = np.empty([max_particles], Particle)
        for i in range(max_particles):
            self.particles[i] = self.new_particle()
            self.add(self.particles[i])

        self.last_time = glfw.get_time()
Exemplo n.º 4
0
    def __init__(self, ground, n_trees=10, fire=False):
        super().__init__()
        positions = [(2 * ground.min_x, 2 * ground.min_z)] * (n_trees + 1)
        shape_vertex_array = load_monocolor_vertex_array(
            'assets/cylinder.obj')[0]  # just load the cylinder from file
        shader = Shader(UNIFORM_COLOR_VERT, UNIFORM_COLOR_FRAG)
        for i in range(n_trees):
            # random parameters for each tree
            leaves = randint(8, 15)

            # we pick a position not to close from the other ones
            new_pos = (2 * ground.min_x, 2 * ground.min_z)

            def new_pos_valid():
                for pos in positions:
                    if (new_pos[0] - pos[0])**2 + (
                            new_pos[1] -
                            pos[1])**2 < 25:  # Trees are about 5m wide
                        return False
                return True

            while not new_pos_valid():
                new_pos = (randint(int(ground.min_x), -int(ground.min_x)),
                           randint(int(ground.min_z), -int(ground.min_z)))
            # we can add the tree to the current forest
            positions[i] = new_pos
            if fire:
                on_fire = random() < 0.2
            self.add(
                Tree(ground, shape_vertex_array, shader, new_pos[0],
                     new_pos[1], leaves, on_fire))
Exemplo n.º 5
0
 def createShader(self, name):
     shaderTexts = self.getShaderFileContents(name)
     print "Creating shader " + name
     ShaderSystem.shaders[name] = Shader(vert=shaderTexts[0],
                                         frag=shaderTexts[1],
                                         geom=shaderTexts[2])
     return ShaderSystem.shaders[name]
Exemplo n.º 6
0
 def __init__(self, width, height, *args, **kw):
     try:
         self.bg_colour = kw["bg"]
         del kw["bg"]
     except KeyError:
         self.bg_colour = (0, 0, 0, 1)
     w = self.win = pyglet.window.Window(width, height, *args, **kw)
     self.mesh = Mesh((-0.5, -0.5, 0.0, 0.0, 0.0, 0.5, -0.5, 0.0, 1.0, 0.0,
                       0.5, 0.5, 0.0, 1.0, 1.0, -0.5, 0.5, 0.0, 0.0, 1.0),
                      contains_texture=True,
                      primitive=GL_QUADS)
     #        self.mesh = tnvmesh.make_cuboid(0.5, 0.5, 0.2)
     vshader = Shader(SIMPLE_VSHADER, GL_VERTEX_SHADER)
     gingham = ShaderProgram(vshader, Shader(GINGHAM_FSHADER))
     graph = ShaderProgram(vshader, Shader(GRAPHPAPER_FSHADER))
     edges = ShaderProgram(vshader, Shader(EDGES_FSHADER))
     self.shaders = [gingham, graph, edges]
     self.shaderindex = 0
     w.set_handlers(self.on_draw, self.on_resize, self.on_key_press)
Exemplo n.º 7
0
    def __init__(self, attributes, bone_nodes, bone_offsets, index=None):

        # setup shader attributes for linear blend skinning shader
        self.vertex_array = VertexArray(attributes, index)

        # feel free to move this up in Viewer as shown in previous practicals
        self.skinning_shader = Shader(SKINNING_VERT, SIMPLE_COLOR_FRAG)

        # store skinning data
        self.bone_nodes = bone_nodes
        self.bone_offsets = bone_offsets
Exemplo n.º 8
0
    def __init__(self, texture, attributes, index=None):
        # feel free to move this up in the viewer as per other practicals
        self.shader = Shader(TEXTURE_VERT, TEXTURE_FRAG)

        # triangle and face buffers

        self.vertex_array = VertexArray(attributes, index)

        # interactive toggles
        # self.wrap = cycle([GL.GL_REPEAT, GL.GL_MIRRORED_REPEAT,
        #                    GL.GL_CLAMP_TO_BORDER, GL.GL_CLAMP_TO_EDGE])
        # self.filter = cycle([(GL.GL_NEAREST, GL.GL_NEAREST),
        #                      (GL.GL_LINEAR, GL.GL_LINEAR),
        #                      (GL.GL_LINEAR, GL.GL_LINEAR_MIPMAP_LINEAR)])
        # self.wrap_mode, self.filter_mode = next(self.wrap), next(self.filter)

        # setup texture and upload it to GPU
        self.texture = texture
Exemplo n.º 9
0
    def __init__(self, file):
        # feel free to move this up in the viewer as per other practicals
        self.shader = Shader(TEXTURE_VERT, TEXTURE_FRAG)

        # triangle and face buffers
        vertices = 100 * np.array(
            ((-1, -1, 0), (1, -1, 0), (1, 1, 0), (-1, 1, 0)), np.float32)
        faces = np.array(((0, 1, 2), (0, 2, 3)), np.uint32)
        self.vertex_array = VertexArray([vertices], faces)

        # interactive toggles
        self.wrap = cycle([
            GL.GL_REPEAT, GL.GL_MIRRORED_REPEAT, GL.GL_CLAMP_TO_BORDER,
            GL.GL_CLAMP_TO_EDGE
        ])
        self.filter = cycle([(GL.GL_NEAREST, GL.GL_NEAREST),
                             (GL.GL_LINEAR, GL.GL_LINEAR),
                             (GL.GL_LINEAR, GL.GL_LINEAR_MIPMAP_LINEAR)])
        self.wrap_mode, self.filter_mode = next(self.wrap), next(self.filter)
        self.file = file

        # setup texture and upload it to GPU
        self.texture = Texture(file, self.wrap_mode, *self.filter_mode)
Exemplo n.º 10
0
shader = Shader(['''
void main() {
	// transform the vertex position
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	// pass through the texture coordinate
	gl_TexCoord[0] = gl_MultiTexCoord0;
}
'''], ['''
uniform sampler2D tex0;
uniform vec2 pixel;

void main() {
	// retrieve the texture coordinate
	vec2 c = gl_TexCoord[0].xy;

	// and the current pixel
	vec3 current = texture2D(tex0, c).rgb;

	// count the neightbouring pixels with a value greater than zero
	vec3 neighbours = vec3(0.0);
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2(-1,-1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2(-1, 0)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2(-1, 1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 0,-1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 0, 1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 1,-1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 1, 0)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 1, 1)).rgb, vec3(0.0)));

	// check if the current pixel is alive
	vec3 live = vec3(greaterThan(current, vec3(0.0)));

	// resurect if we are not live, and have 3 live neighrbours
	current += (1.0-live) * vec3(equal(neighbours, vec3(3.0)));

	// kill if we do not have either 3 or 2 neighbours
	current *= vec3(equal(neighbours, vec3(2.0))) + vec3(equal(neighbours, vec3(3.0)));

	// fade the current pixel as it ages
	current -= vec3(greaterThan(current, vec3(0.4)))*0.05;

	// write out the pixel
	gl_FragColor = vec4(current, 1.0);
}
'''])
Exemplo n.º 11
0
 def __init__(self, color, vertex_array, shader=None):
     self.vertex_array = vertex_array
     if shader is not None:
         self.color_shader = Shader(UNIFORM_COLOR_VERT, UNIFORM_COLOR_FRAG)
     self.color = color
Exemplo n.º 12
0
 def __init__(self, attributes, index=None):
     self.vertex_array = VertexArray(attributes, index)
     self.color_shader = Shader(SIMPLE_COLOR_VERT, SIMPLE_COLOR_FRAG)
Exemplo n.º 13
0
shader = Shader([
    '''
void main() {
	// transform the vertex position
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	// pass through the texture coordinate
	gl_TexCoord[0] = gl_MultiTexCoord0;
}
'''
], [
    '''
uniform sampler2D tex0;
uniform vec2 pixel;

void main() {
	// retrieve the texture coordinate
	vec2 c = gl_TexCoord[0].xy;

	// and the current pixel
	vec3 current = texture2D(tex0, c).rgb;

	// count the neightbouring pixels with a value greater than zero
	vec3 neighbours = vec3(0.0);
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2(-1,-1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2(-1, 0)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2(-1, 1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 0,-1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 0, 1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 1,-1)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 1, 0)).rgb, vec3(0.0)));
	neighbours += vec3(greaterThan(texture2D(tex0, c + pixel*vec2( 1, 1)).rgb, vec3(0.0)));

	// check if the current pixel is alive
	vec3 live = vec3(greaterThan(current, vec3(0.0)));

	// resurect if we are not live, and have 3 live neighrbours
	current += (1.0-live) * vec3(equal(neighbours, vec3(3.0)));

	// kill if we do not have either 3 or 2 neighbours
	current *= vec3(equal(neighbours, vec3(2.0))) + vec3(equal(neighbours, vec3(3.0)));

	// fade the current pixel as it ages
	current -= vec3(greaterThan(current, vec3(0.4)))*0.05;

	// write out the pixel
	gl_FragColor = vec4(current, 1.0);
}
'''
])
Exemplo n.º 14
0
    tmat = np.eye(4)
    tmat[0][3] = -_eye[0]
    tmat[1][3] = -_eye[1]
    tmat[2][3] = -_eye[2]

    # numpy.array * is element-wise multiplication, use dot()
    lookatmat = np.dot(rmat, tmat).transpose()
    return lookatmat


if __name__ == "__main__":
    width = 800
    height = 600
    window, context = ss.setup(b"Penguin Engine", width, height)
    myshader = sh.shader("./shaders/vertex_shader.vert",
                         "./shaders/fragment_shader.frag")
    myshader.process_shader()

    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glViewport(0, 0, width, height)
    #***************************************************************************
    vertices = np.array([
        -0.5, -0.5, 0.5, 0.0, 0.0, 0.5, -0.5, 0.5, 1.0, 0.0, -0.5, 0.5, 0.5,
        0.0, 1.0, 0.5, 0.5, 0.5, 1.0, 1.0, -0.5, -0.5, -0.5, 0.0, 0.0, 0.5,
        -0.5, -0.5, 1.0, 0.0, -0.5, 0.5, -0.5, 0.0, 1.0, 0.5, 0.5, -0.5, 1.0,
        1.0, -0.5, -0.5, -0.5, 0.0, 0.0, -0.5, -0.5, 0.5, 1.0, 0.0, -0.5, 0.5,
        -0.5, 0.0, 1.0, -0.5, 0.5, 0.5, 1.0, 1.0, 0.5, -0.5, 0.5, 0.0, 0.0,
        0.5, -0.5, -0.5, 1.0, 0.0, 0.5, 0.5, 0.5, 0.0, 1.0, 0.5, 0.5, -0.5,
        1.0, 1.0, -0.5, -0.5, -0.5, 0.0, 0.0, 0.5, -0.5, -0.5, 1.0, 0.0, -0.5,
        -0.5, 0.5, 0.0, 1.0, 0.5, -0.5, 0.5, 1.0, 1.0, -0.5, 0.5, 0.5, 0.0,
        0.0, 0.5, 0.5, 0.5, 1.0, 0.0, -0.5, 0.5, -0.5, 0.0, 1.0, 0.5, 0.5,