示例#1
0
def setupPyglet():
    window = pyglet.window.Window(width=width, height=height)
    pygl.glClearColor(0.05, 0.04, 0.04, 1)
    pygl.glPointSize(10)
    pygl.glLineWidth(5)
    pygl.glEnable(pygl.GL_BLEND)
    pygl.glBlendFunc(pygl.GL_SRC_ALPHA, pygl.GL_ONE_MINUS_SRC_ALPHA)

    def on_draw(dt):
        window.clear()

        global elapsedTime
        outputScene.drawScene(elapsedTime)
        if isRecording:
            write_to_video()

        elapsedTime += dt

    def write_to_video():
        buffer = (pygl.GLubyte * (3 * window.width * window.height))(0)
        pygl.glReadPixels(0, 0, width, height, pygl.GL_RGB,
                          pygl.GL_UNSIGNED_BYTE, buffer)
        pipe.stdin.write(buffer)

    pyglet.clock.schedule_interval(on_draw, 1 / 24)
示例#2
0
def on_draw():
    window.clear()
    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)

    if scene._current:
        scene._current.draw()
    fps_display.draw()
示例#3
0
文件: tiles.py 项目: pennomi/overseer
 def draw_hp(self):
     full_hp = TILE_COSTS[self.type]
     if full_hp == math.inf:
         return
     percent = int((full_hp - self.hp) / full_hp * 4)
     if 0 < percent < 4:
         # TODO: Move this to the main function
         gl.glEnable(gl.GL_BLEND)
         gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
         get_tile(percent, 3).blit(self.x, self.y)
 def texture_setting(self, pic_path):
     if len(self.text_indices) > 0:
         gl.glEnable(gl.GL_CULL_FACE)
         # texture set up
         pic = pyglet.image.load(pic_path)
         self.texture = pic.get_texture()
         print(self.texture.id)
         gl.glEnable(self.texture.target)
         gl.glBindTexture(self.texture.target, self.texture.id)
         self.vertex_list = pyglet.graphics.vertex_list_indexed(len(self.vertices) // 3,self.triangle_indices,\
                                                           ('v3f',self.vertices),('t2f',self.text_coord),('n3f',self.vertex_nomals))
示例#5
0
    def init(self):
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)

        gl.glCullFace(gl.GL_BACK)
        gl.glEnable(gl.GL_CULL_FACE)

        gl.glClearColor(*self.world.sky_color)

        vs_file = join(path.SOURCE, 'view', 'shaders', 'lighting.vert')
        vs = VertexShader(vs_file)
        fs_file = join(path.SOURCE, 'view', 'shaders', 'lighting.frag')
        fs = FragmentShader(fs_file)
        shader = ShaderProgram(vs, fs)
        shader.compile()
        shader.use()

        # create glyphs for every item added to the world before now
        for item in self.world:
            self.world_add_item(item)
        # create glyphs for every item added after this
        self.world.item_added += self.world_add_item
示例#6
0
        def on_resize(width, height):
            # sets the viewport
            gl.glViewport(0, 0, width, height)

            # sets the projection
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluPerspective(90.0, width / height, 0.1, 10000.0)

            # sets the model view
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glEnable(gl.GL_DEPTH_TEST)
            gl.glLoadIdentity()

            return pyglet.event.EVENT_HANDLED
示例#7
0
    def main_loop(self):
        clock.set_fps_limit(30)
        nodeSize = 5

        timer = 0
        while not self.has_exit:
            self.dispatch_events()
            self.clear()

            # White, so reset the colour
            glColor4f(1, 1, 1, 1)
            gl.glLineWidth(1)

            gl.glEnable(gl.GL_BLEND)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

            glColor4f(0, 0, 0, 1.0)
            clock.tick()
示例#8
0
    def draw(self, viewport):
        gl.glClearColor(183 / 255.0, 196 / 255.0, 200 / 255.0, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        x1 = viewport.tl.x
        x2 = viewport.br.x

        backgrounds = [
            (self.clouds, self.clouds.width), 
            (self.fg, self.fg.width), 
        ]

        for img, w in backgrounds:
            cx = x1 - x1 % w - w
            while cx < x2:
                img.blit(cx, 0)
                cx += w
示例#9
0
    def draw_ground_plane(self):
        size = 100

        gl.glPushMatrix()
        gl.glColor3f(1, 1, 1)  # no textures drawn without this for some reason
        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.tex.id)
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)  # you need two
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)  # I don't know why!

        pos = ('v3f', (-size, -self.cy, -size, size, -self.cy, -size, size,
                       -self.cy, size, -size, -self.cy, size))
        tex_coords = ('t2f', (0, 0, 1, 0, 1, 1, 0, 1))
        vlist = pyglet.graphics.vertex_list(4, pos, tex_coords)
        vlist.draw(gl.GL_QUADS)

        gl.glDisable(gl.GL_TEXTURE_2D)
        gl.glPopMatrix()
示例#10
0
    def draw(self, viewport):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        alt = viewport.bl.y
        h = viewport.height 
        w = viewport.width
        c1 = self.gradient.colour(alt)
        c2 = self.gradient.colour(alt + 10000)

        o = v(0, 0)
        x = v(w, 0)
        y = v(0, h)

        vs = [o, x, x + y, y]
        cs = [c1, c1, c2, c2]
        
        pyglet.graphics.draw(4, gl.GL_QUADS,
            ('v2f', list(walk(vs))),
            ('c3f', list(walk(cs)))
        )
示例#11
0
    def _init_gl_parameters(self):
        gl.glShadeModel(gl.GL_SMOOTH)  # Enable Smooth Shading
        gl.glClearColor(0.0, 0.0, 0.0, 0.5)  # Black Background
        gl.glClearDepth(1.0)  # Depth Buffer Setup
        gl.glEnable(gl.GL_DEPTH_TEST)  # Enables Depth Testing
        gl.glDepthFunc(gl.GL_LEQUAL)  # The Type Of Depth Testing To Do

        gl.glEnable(gl.GL_MULTISAMPLE)

        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glCullFace(gl.GL_BACK)
        gl.glFrontFace(gl.GL_CCW)

        gl.glEnable(gl.GL_TEXTURE_2D)  # Enable Texture Mapping
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                           gl.GL_NEAREST)
示例#12
0
import pyglet
from pyglet import resource
from pyglet import sprite
from pyglet.gl import gl

gl.glEnable(gl.GL_TEXTURE_2D)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
pyglet.image.Texture.default_mag_filter = gl.GL_NEAREST
pyglet.image.Texture.default_min_filter = gl.GL_NEAREST

resource.path = ['../resources', '../resources/art', '../resources/sounds']
resource.reindex()

black = resource.image('black.png')
black_spr = sprite.Sprite(black, x=0, y=0)
grass_tile = resource.image('tile_test.png')
grass_spr = sprite.Sprite(grass_tile)