Python pygame 模块,DOUBLEBUF 实例源码

我们从Python开源项目中,提取了以下36个代码示例,用于说明如何使用pygame.DOUBLEBUF

项目:Projects    作者:it2school    | 项目源码 | 文件源码
def todo_test_flip(self):

        # __doc__ (as of 2008-08-02) for pygame.display.flip:

          # pygame.display.flip(): return None
          # update the full display Surface to the screen
          # 
          # This will update the contents of the entire display. If your display
          # mode is using the flags pygame.HWSURFACE and pygame.DOUBLEBUF, this
          # will wait for a vertical retrace and swap the surfaces. If you are
          # using a different type of display mode, it will simply update the
          # entire contents of the surface.
          # 
          # When using an pygame.OPENGL display mode this will perform a gl buffer swap. 

        self.fail()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def todo_test_mode_ok(self):

        # __doc__ (as of 2008-08-02) for pygame.display.mode_ok:

          # pygame.display.mode_ok(size, flags=0, depth=0): return depth
          # pick the best color depth for a display mode
          # 
          # This function uses the same arguments as pygame.display.set_mode().
          # It is used to depermine if a requested display mode is available. It
          # will return 0 if the display mode cannot be set. Otherwise it will
          # return a pixel depth that best matches the display asked for.
          # 
          # Usually the depth argument is not passed, but some platforms can
          # support multiple display depths. If passed it will hint to which
          # depth is a better match.
          # 
          # The most useful flags to pass will be pygame.HWSURFACE,
          # pygame.DOUBLEBUF, and maybe pygame.FULLSCREEN. The function will
          # return 0 if these display flags cannot be set.
          # 

        self.fail()
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def set_resolution(self):
        self.screen = pygame.display.set_mode((self.width+5, self.height), pygame.DOUBLEBUF)
        if self.backgroundimage is None:
            self.background = pygame.Surface(self.screen.get_size()).convert()
            self.background.fill((255,255,255)) # fill background white

        else:
            self.background = pygame.image.load(self.backgroundimage)
            self.background = pygame.transform.scale(self.background, self.screen.get_size())
            self.background.convert()
            for x in range(10):  # backgroundimage0 - backgroundimage9
                filename = self.backgroundimage[:-4] + str(x) + self.backgroundimage[-4:]
                try:
                    image = pygame.image.load(filename)                 
                    image = pygame.transform.scale(image, self.screen.get_size())
                    image.convert()
                    self.backgrounds.append(image)
                except:
                    print("no backgroundimage found for {}".format(filename))
        self.backgrounds.append(self.background)
        self.background = self.backgrounds[1]
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def todo_test_flip(self):

        # __doc__ (as of 2008-08-02) for pygame.display.flip:

          # pygame.display.flip(): return None
          # update the full display Surface to the screen
          # 
          # This will update the contents of the entire display. If your display
          # mode is using the flags pygame.HWSURFACE and pygame.DOUBLEBUF, this
          # will wait for a vertical retrace and swap the surfaces. If you are
          # using a different type of display mode, it will simply update the
          # entire contents of the surface.
          # 
          # When using an pygame.OPENGL display mode this will perform a gl buffer swap. 

        self.fail()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def todo_test_mode_ok(self):

        # __doc__ (as of 2008-08-02) for pygame.display.mode_ok:

          # pygame.display.mode_ok(size, flags=0, depth=0): return depth
          # pick the best color depth for a display mode
          # 
          # This function uses the same arguments as pygame.display.set_mode().
          # It is used to depermine if a requested display mode is available. It
          # will return 0 if the display mode cannot be set. Otherwise it will
          # return a pixel depth that best matches the display asked for.
          # 
          # Usually the depth argument is not passed, but some platforms can
          # support multiple display depths. If passed it will hint to which
          # depth is a better match.
          # 
          # The most useful flags to pass will be pygame.HWSURFACE,
          # pygame.DOUBLEBUF, and maybe pygame.FULLSCREEN. The function will
          # return 0 if these display flags cannot be set.
          # 

        self.fail()
项目:mini_rpg    作者:paolo-perfahl    | 项目源码 | 文件源码
def __init__(self, width=1050, height=800, fps=30, grid=50):
        """Initialize pygame, window, background, font,..."""
        pygame.init()
        pygame.display.set_caption("Press ESC to quit")
        PygView.width = width    # make global readable
        PygView.height = height
        PygView.grid = grid
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        self.background.fill((255,255,255)) # fill background white
        self.clock = pygame.time.Clock()
        self.fps = fps
        self.playtime = 0.0
        #self.font = pygame.font.SysFont('mono', 24, bold=True)

        self.joysticks = []
        for x in range(pygame.joystick.get_count()):
             j = pygame.joystick.Joystick(x)
             j.init()
             self.joysticks.append(j)
        self.loadresources() # loadresources calls paintgrid
        #pygame.joystick.init()
        #self.joysticks = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())]
项目:wargame    作者:maximinus    | 项目源码 | 文件源码
def __init__(self, resource_directory):
        self.setup_logging(resource_directory)
        logger.info('Starting Wargame v{0}'.format(VERSION))
        system_checks()
        self.screen = pygame.display.set_mode((640, 480), pygame.DOUBLEBUF)
        pygame.display.set_caption('HexGame')
        Resources.load_resources(resource_directory, self.screen)
        self.clock = pygame.time.Clock()
        self.scenes = {}
        self.current_scene = None
        self.last_tick = 0
项目:photobooth    作者:maduck    | 项目源码 | 文件源码
def __init__(self):
        self.runtime_id = 0
        self._canvas = None
        self._background = None
        self._photo_space = None
        self.target_dir = None
        self.font = None
        self._init_camera()
        self.photos = []
        self.printer = backends.acquire_backend("output", "line_printer", self.config)
        self._init_gpio()
        self._get_last_runtime_id()
        self.get_current_photo_directory()

        pygame.init()
        self.clock = pygame.time.Clock()
        self.limit_cpu_usage()
        display_mode = pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN
        self._canvas = pygame.display.set_mode((0, 0), display_mode)
        self.screen_width = pygame.display.Info().current_w
        self.screen_height = pygame.display.Info().current_h
        self._background = self.fill_background()
        self._photo_space = self.fill_photo_space()
        self._running = True
        self.font = pygame.font.Font(self.config.get('font_filename'), self.config.getint('font_size'))
        pygame.mouse.set_visible(False)
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def __initialize_display(self):
        self.resolution_key = self.settings['screen']['resolution']
        resolution = self.settings['valid_resolutions'][self.resolution_key]
        self.resolution = (resolution['width'], resolution['height'])

        if self.settings['screen']['fullscreen']:
            self.screen = pygame.display.set_mode(self.resolution, pygame.FULLSCREEN | pygame.DOUBLEBUF)
        else:
            self.screen = pygame.display.set_mode(self.resolution, pygame.DOUBLEBUF)
        pygame.display.set_caption(self.settings['title'])
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def __init__(self, width=640, height=400, fps=30, filename = "level1.txt", tilew = 20, tileh = 20):
        """Initialize pygame, window, background, font,...
           default arguments 
        """
        pygame.init()
        pygame.display.set_caption("--- MAP-VIEWER ---")
        PygView.width = width    # make global readable
        PygView.height = height
        self.filename = filename
        self.tilew = tilew
        self.tileh = tileh

        self.lines = 32
        self.chars = 64
        self.tiles = []


        print(self.lines, self.chars) 
        print(self.tiles)
        PygView.width = self.chars * self.tilew
        PygView.height = self.lines * self.tileh

        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        self.background.fill((255,255,255)) # fill background white

        #self.clock = pygame.time.Clock()
        #self.fps = fps
        #self.playtime = 0.0
        #self.font = pygame.font.SysFont('mono', 24, bold=True)
        self.paint()
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def __init__(self, width=640, height=400, fps=30):
        """Initialize pygame, window, background, font,..."""
        pygame.init()
        pygame.display.set_caption("Press ESC to quit")
        PygView.width = width    # make global readable
        PygView.height = height
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.loadresources()
        self.background = pygame.Surface(PygView.images[0].get_size())
        self.background.blit(PygView.images[0], (0,0))
        #self.background = pygame.Surface(self.screen.get_size()).convert()  
        #self.background.fill((255,255,255)) # fill background white
        self.clock = pygame.time.Clock()
        self.fps = fps
        self.playtime = 0.0
        #self.loadresources()
        self.mapzoom = 5
        dx = Vec2d(20,15)
        print("dx",dx)
        ex = Vec2d(7,0)
        print("ex", ex)
        print("dx + ex:", dx+ex)  # vektor addition
        print("dx * 2", dx * 2)   # vektor multiplizieren
        print("x, y von dx", dx.x, dx.y) # attribute vom Vektor
        print("senkrechte zu dx", dx.perpendicular())
        print("distanz zw. dx und ex",  dx.get_distance(ex))
项目:model-converter-python    作者:tforgione    | 项目源码 | 文件源码
def resize(width, height):
    length = min(width, height)
    offset = int( math.fabs(width - height) / 2)

    # Ugly AF
    pg.display.set_mode((width, height), pg.DOUBLEBUF | pg.RESIZABLE | pg.OPENGL)

    if width < height:
        gl.glViewport(0, offset, length, length)
    else:
        gl.glViewport(offset, 0, length, length)
项目:Slither    作者:PySlither    | 项目源码 | 文件源码
def setFullScreen(mode):
    "If mode is True, turns on full screen, otherwise, turns it off"
    global screen
    if mode:
        screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN|pygame.HWSURFACE|pygame.DOUBLEBUF)
    else:
        screen = pygame.display.set_mode(SCREEN_SIZE)
项目:tutorials    作者:krzyszti    | 项目源码 | 文件源码
def __init__(self):
        self._running = True
        self.background = pygame.image.load('background.png')
        self.hero = pygame.image.load('hero.png')
        self.x = 0
        self.y = 0
        pygame.init()
        self._display_surf = pygame.display.set_mode((640, 480), pygame.HWSURFACE | pygame.DOUBLEBUF)
项目:ATLeS    作者:liffiton    | 项目源码 | 文件源码
def get_screen(xwin=False):
    """Initializes a new pygame screen using the framebuffer"""
    # Based on "Python GUI in Linux frame buffer"
    # http://www.karoltomala.com/blog/?p=679
    disp_no = os.getenv("DISPLAY")
    if disp_no:
        print "I'm running under X display = {0}".format(disp_no)

    # Make sure that SDL_VIDEODRIVER is set
    if xwin:
        driver = 'x11'
    else:
        driver = 'directfb'   # alternatives: 'fbcon', 'svgalib'
    if not os.getenv('SDL_VIDEODRIVER'):
        os.putenv('SDL_VIDEODRIVER', driver)

    try:
        pygame.display.init()
    except pygame.error:
        raise Exception('Display init failed with driver: {0}'.format(driver))

    if xwin:
        size = (320, 200)
        options = 0
    else:
        # fullscreen
        info = pygame.display.Info()
        size = (info.current_w, info.current_h)
        print "Framebuffer size: %d x %d" % (size[0], size[1])
        options = pygame.FULLSCREEN | pygame.DOUBLEBUF
    screen = pygame.display.set_mode(size, options)

    # Clear the screen to start
    screen.fill((0, 0, 0))
    pygame.mouse.set_visible(False)
    # Render the screen
    pygame.display.update()

    return screen
项目:python-mediadecoder    作者:dschreij    | 项目源码 | 文件源码
def __init__(self, dimensions, fullscreen = False, soundrenderer="pyaudio",
        loop=False):
        """ Constructor.

        Parameters
        ----------
        dimensions : tuple (width, height)
            The dimension of the window in which the video should be shown. Aspect
            ratio is maintained.
        fullscreen : bool, optional
            Indicates whether the video should be displayed in fullscreen.
        soundrenderer : {'pyaudio','pygame'}
            Designates which sound backend should render the sound. 
        """

        pygame.init()
        (windowWidth, windowHeight) = dimensions
        flags = pygame.DOUBLEBUF|pygame.OPENGL|pygame.HWSURFACE
        self.fullscreen = fullscreen
        if fullscreen:
            flags = flags | pygame.FULLSCREEN
        pygame.display.set_mode((windowWidth,windowHeight), flags)
        self.windowSize = (windowWidth, windowHeight)

        self.soundrenderer=soundrenderer        
        self.loop = loop
        self.texUpdated = False

        self.__initGL()

        self.decoder = Decoder(
            videorenderfunc=self.__texUpdate,
        )
        self.texture_locked = False
项目:PyGame-Learning-Environment    作者:ntasfi    | 项目源码 | 文件源码
def __init__(self, width, height):
        self.width = width
        self.height = height

        pygame.init()
        self.window = pygame.display.set_mode( (self.width, self.height), pygame.DOUBLEBUF, 24 )
        pygame.display.set_caption("PLE ViZDoom")
项目:subroofer    作者:Sypherio    | 项目源码 | 文件源码
def set_up_pygame():

    bits = 16

    pygame.mixer.pre_init(44100, -bits, 2)

    pygame.init()
    _display_surf = pygame.display.set_mode(size, pygame.HWSURFACE | pygame.DOUBLEBUF)
项目:mini_rpg    作者:paolo-perfahl    | 项目源码 | 文件源码
def __init__(self, width=640, height=400, fps=30, grid=50):
        """Initialize pygame, window, background, font,..."""
        pygame.init()
        pygame.display.set_caption("Press ESC to quit")
        PygView.width = width    # make global readable
        PygView.height = height
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        self.background.fill((255,255,255)) # fill background white
        self.clock = pygame.time.Clock()
        self.fps = fps
        self.playtime = 0.0
        self.grid = grid
        #self.font = pygame.font.SysFont('mono', 24, bold=True)
        self.loadresources()
项目:mini_rpg    作者:paolo-perfahl    | 项目源码 | 文件源码
def __init__(self, text, width=640, height=400, fps=30, color=(0,0,255)):
        """Initialize pygame, window, background, font,...
           default arguments 
        """

        pygame.mixer.pre_init(44100, -16, 2, 2048) 

        pygame.init()

        #jump = pygame.mixer.Sound(os.path.join('data','jump.wav'))  #load sound
        #self.sound1 = pygame.mixer.Sound(os.path.join('data','Pickup_Coin.wav'))
        #self.sound2 = pygame.mixer.Sound(os.path.join('data','Jump.wav'))
        #self.sound3 = pygame.mixer.Sound(os.path.join('data','mix.wav'))
        pygame.display.set_caption("Press ESC to quit, UP / DOWN to scroll")
        self.text = text
        self.color = color
        self.lines = text.split("\n")
        self.width = width
        self.height = height
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        self.background.fill((255,255,255)) # fill background white
        self.clock = pygame.time.Clock()
        self.fps = fps
        self.playtime = 0.0
        self.offset_y = self.height - 10
        self.x = 100
        self.dy = 50
        self.font = pygame.font.SysFont('mono', 24, bold=True)
项目:mini_rpg    作者:paolo-perfahl    | 项目源码 | 文件源码
def set_resolution(self):
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        self.background.fill((255,255,255)) # fill background white
项目:Buffe    作者:bentzinir    | 项目源码 | 文件源码
def _init_gui(self):
        pygame.init()

        self._build_targets()

        if GUI_MODE:
            self._screen = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)

        self._running = True
项目:program-arcade-games-w-python    作者:Apress    | 项目源码 | 文件源码
def main():
    """ Main function for the game. """

    # Get Pygame ready
    pygame.init()

    # Set the width and height of the screen [width,height]
    size = (640,480)
    video_flags = pygame.OPENGL | pygame.DOUBLEBUF    
    screen = pygame.display.set_mode(size, video_flags)

    # Create an OpenGL viewport
    resize_gl_scene(size)
    init_gl()

    # These are for calculating FPS
    frames = 0
    ticks = pygame.time.get_ticks()

    done = False

    while not done:
        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            done = True

        draw_gl_scene()
        pygame.display.flip()
        frames = frames + 1

    total_ticks = pygame.time.get_ticks() - ticks
    print("Average of {:.1f} fps".format((frames * 1000) / total_ticks))

    pygame.quit()
项目:pyweather    作者:rbischoff    | 项目源码 | 文件源码
def __init__(self, drivers=DEFAULT_DRIVERS, size=DEFAULT_SIZE, screen_type=DEFAULT_SCREEN, borders=(5, 5),
                 border_width=3, line_color=(255, 255, 255), font='freesans', font_color=(255, 255, 255),
                 icons=ICON_DICTIONARY):
        """DisplayDriver class is the class that build the base display for use in the weather
        app.  Argument descriptions: drivers is a tuple of strings with available SDL_VIDEODRIVER
        environmental varaibles; size is a tuple of two integers describing the x, y size of the
        screen; screen_type is a string value that corresponds to the pygame constants for
        dispay.set_mode
        """

        formats = {'no_frame': pygame.NOFRAME, 'full_screen': pygame.FULLSCREEN, 'double_buff': pygame.DOUBLEBUF,
                   'hw_surface': pygame.HWSURFACE, 'open_GL': pygame.OPENGL, 'resizable': pygame.RESIZABLE}

        self._system_data = SystemData()
        self._display_instance = None
        self._drivers = drivers
        self._size = size
        self._borders = borders
        self._border_width = border_width
        self._line_color = line_color
        self._font = font
        self._font_color = font_color
        self._format = formats[screen_type]
        self._icons = icons
        self._base_dir = os.getcwd() + ICON_BASE_DIR
        self._scale_icons = True
        self._xmax = self._size[0] - self._borders[0]
        self._ymax = self._size[1] - self._borders[1]
        self._av = 1
        self._av_time = 1
        self._screen = None
        self._blits = []
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def todo_test_set_mode(self):

        # __doc__ (as of 2008-08-02) for pygame.display.set_mode:

          # pygame.display.set_mode(resolution=(0,0), flags=0, depth=0): return Surface
          # initialize a window or screen for display
          # 
          # This function will create a display Surface. The arguments passed in
          # are requests for a display type. The actual created display will be
          # the best possible match supported by the system.
          # 
          # The resolution argument is a pair of numbers representing the width
          # and height. The flags argument is a collection of additional
          # options.  The depth argument represents the number of bits to use
          # for color.
          # 
          # The Surface that gets returned can be drawn to like a regular
          # Surface but changes will eventually be seen on the monitor.
          # 
          # If no resolution is passed or is set to (0, 0) and pygame uses SDL
          # version 1.2.10 or above, the created Surface will have the same size
          # as the current screen resolution. If only the width or height are
          # set to 0, the Surface will have the same width or height as the
          # screen resolution. Using a SDL version prior to 1.2.10 will raise an
          # exception.
          # 
          # It is usually best to not pass the depth argument. It will default
          # to the best and fastest color depth for the system. If your game
          # requires a specific color format you can control the depth with this
          # argument. Pygame will emulate an unavailable color depth which can
          # be slow.
          # 
          # When requesting fullscreen display modes, sometimes an exact match
          # for the requested resolution cannot be made. In these situations
          # pygame will select the closest compatable match. The returned
          # surface will still always match the requested resolution.
          # 
          # The flags argument controls which type of display you want. There
          # are several to choose from, and you can even combine multiple types
          # using the bitwise or operator, (the pipe "|" character). If you pass
          # 0 or no flags argument it will default to a software driven window.
          # Here are the display flags you will want to choose from:
          # 
          #    pygame.FULLSCREEN    create a fullscreen display
          #    pygame.DOUBLEBUF     recommended for HWSURFACE or OPENGL
          #    pygame.HWSURFACE     hardware accelerated, only in FULLSCREEN
          #    pygame.OPENGL        create an opengl renderable display
          #    pygame.RESIZABLE     display window should be sizeable
          #    pygame.NOFRAME       display window will have no border or controls

        self.fail()
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def init():
    "Ininitializes a new pygame screen using the framebuffer"
    # Based on "Python GUI in Linux frame buffer"
    # http://www.karoltomala.com/blog/?p=679
    disp_no = os.getenv("DISPLAY")
    if disp_no:
        print "I'm running under X display = {0}".format(disp_no)

    # Check which frame buffer drivers are available
    # Start with fbcon since directfb hangs with composite output
    drivers = ['fbcon', 'directfb', 'svgalib']
    #drivers = ['directfb', 'svgalib']
    #drivers = ['fbcon']
    found = False
    for driver in drivers:
        # Make sure that SDL_VIDEODRIVER is set
        if not os.getenv('SDL_VIDEODRIVER'):
            os.putenv('SDL_VIDEODRIVER', driver)
        try:
            print 'Driver: {0} '.format(driver)
            pygame.display.init()
        except pygame.error:
            print 'Driver: {0} failed.'.format(driver)
            continue
        found = True
        break

    if not found:
        raise Exception('No suitable video driver found!')

    size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
    print "Framebuffer size: %d x %d" % (size[0], size[1])

    pygame.mouse.set_visible(False)
    screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
    #screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.DOUBLEBUF | pygame.HWSURFACE)
    #screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.DOUBLEBUF)
    #screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.HWSURFACE)


    # Clear the screen to start
    screen.fill((255, 105, 180))        
    # Initialise font support
    pygame.font.init()
    # Render the screen
    pygame.display.update()
    return screen
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def init():
    "Ininitializes a new pygame screen using the framebuffer"
    # Based on "Python GUI in Linux frame buffer"
    # http://www.karoltomala.com/blog/?p=679
    disp_no = os.getenv("DISPLAY")
    if disp_no:
        print "I'm running under X display = {0}".format(disp_no)

    # Check which frame buffer drivers are available
    # Start with fbcon since directfb hangs with composite output
    #drivers = ['fbcon', 'directfb', 'svgalib']
    #drivers = ['directfb', 'svgalib']
    drivers = ['vesafbdf']
    found = False
    for driver in drivers:
        # Make sure that SDL_VIDEODRIVER is set
        if not os.getenv('SDL_VIDEODRIVER'):
            os.putenv('SDL_VIDEODRIVER', driver)
        try:
            print 'Driver: {0} '.format(driver)
            pygame.display.init()
        except pygame.error:
            print 'Driver: {0} failed.'.format(driver)
            exit()
            continue
        found = True
        break

    if not found:
        raise Exception('No suitable video driver found!')

    size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
    print "Framebuffer size: %d x %d" % (size[0], size[1])

    pygame.mouse.set_visible(False)
    screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
    #screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.DOUBLEBUF | pygame.HWSURFACE)
    #screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.DOUBLEBUF)
    #screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.HWSURFACE)


    # Clear the screen to start
    screen.fill((255, 105, 180))        
    # Initialise font support
    pygame.font.init()
    # Render the screen
    pygame.display.update()
    return screen
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def __init__(self, text, width=640, height=400, fps=30, textcolor=(0,0,255), 
                 bgcolor=(255,255,255), font=('mono', 24, True), new_init=True, bg_filename=None):
        """Initialize pygame, window, background, font,...
           default arguments 
        """

        #pygame.mixer.pre_init(44100, -16, 2, 2048) 

        if new_init:
            pygame.init()

        #jump = pygame.mixer.Sound(os.path.join('data','jump.wav'))  #load sound
        #self.sound1 = pygame.mixer.Sound(os.path.join('data','Pickup_Coin.wav'))
        #self.sound2 = pygame.mixer.Sound(os.path.join('data','Jump.wav'))
        #self.sound3 = pygame.mixer.Sound(os.path.join('data','mix.wav'))
        pygame.display.set_caption("Press ESC to quit, curosr keys / PgUp, PgDown to scroll")
        self.text = text
        self.bgcolor = bgcolor
        self.textcolor = textcolor
        self.lines = text.split("\n")
        self.width = width
        self.height = height
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        if bg_filename is None:
           self.background.fill(self.bgcolor) # fill background white
        else:
           try:
               print("i try to load:", bg_filename)
               self.background = pygame.image.load(bg_filename)
               self.background = pygame.transform.scale(self.background, (self.width, self.height))
           except:
                print("exception while processing:", bg_filename)
                self.background.fill(self.bgcolor) # fill background white
        self.clock = pygame.time.Clock()
        self.fps = fps
        self.playtime = 0.0
        self.offset_y = self.height - 10
        self.x = 100
        self.dy = 50
        self.text_height = len(self.lines) * self.dy
        self.bold = font[2]
        self.font = pygame.font.SysFont(font[0], font[1], self.bold)
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def __init__(self, width=640, height=400, fps=30, filename = "level1.txt", tilew = 20, tileh = 20):
        """Initialize pygame, window, background, font,...
           default arguments 
        """
        pygame.init()
        pygame.display.set_caption("--- MAP-VIEWER ---")
        PygView.width = width    # make global readable
        PygView.height = height
        self.filename = filename
        self.tilew = tilew
        self.tileh = tileh
        self.lines = []
        try:
            lines = 0
            chars = 0
            with open(self.filename) as myfile:
                for line in myfile:
                    self.lines.append(line[:-1])
                    lines += 1
                chars = len(line) - 1
        except:
            print("-- fileReadingError --")
        print(lines, chars) 
        PygView.width = chars * self.tilew
        PygView.height = lines * self.tileh
        self.colourdict = {3:(1, 0, 122), 
                           4:(93, 92, 244),
                           5:(145, 144, 245),
                           6:(246, 252, 84),
                           7:(226, 144, 36),
                           8:(127, 127, 127)}
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        self.background.fill((255,255,255)) # fill background white
        for line in range(lines):
            for char in range(chars):
                pygame.draw.rect(self.background, self.colourdict[int(self.lines[line][char])],
                                 (self.tilew * char, self.tileh * line, tilew, tileh))
        #self.clock = pygame.time.Clock()
        #self.fps = fps
        #self.playtime = 0.0
        #self.font = pygame.font.SysFont('mono', 24, bold=True)
        self.paint()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def todo_test_set_mode(self):

        # __doc__ (as of 2008-08-02) for pygame.display.set_mode:

          # pygame.display.set_mode(resolution=(0,0), flags=0, depth=0): return Surface
          # initialize a window or screen for display
          # 
          # This function will create a display Surface. The arguments passed in
          # are requests for a display type. The actual created display will be
          # the best possible match supported by the system.
          # 
          # The resolution argument is a pair of numbers representing the width
          # and height. The flags argument is a collection of additional
          # options.  The depth argument represents the number of bits to use
          # for color.
          # 
          # The Surface that gets returned can be drawn to like a regular
          # Surface but changes will eventually be seen on the monitor.
          # 
          # If no resolution is passed or is set to (0, 0) and pygame uses SDL
          # version 1.2.10 or above, the created Surface will have the same size
          # as the current screen resolution. If only the width or height are
          # set to 0, the Surface will have the same width or height as the
          # screen resolution. Using a SDL version prior to 1.2.10 will raise an
          # exception.
          # 
          # It is usually best to not pass the depth argument. It will default
          # to the best and fastest color depth for the system. If your game
          # requires a specific color format you can control the depth with this
          # argument. Pygame will emulate an unavailable color depth which can
          # be slow.
          # 
          # When requesting fullscreen display modes, sometimes an exact match
          # for the requested resolution cannot be made. In these situations
          # pygame will select the closest compatable match. The returned
          # surface will still always match the requested resolution.
          # 
          # The flags argument controls which type of display you want. There
          # are several to choose from, and you can even combine multiple types
          # using the bitwise or operator, (the pipe "|" character). If you pass
          # 0 or no flags argument it will default to a software driven window.
          # Here are the display flags you will want to choose from:
          # 
          #    pygame.FULLSCREEN    create a fullscreen display
          #    pygame.DOUBLEBUF     recommended for HWSURFACE or OPENGL
          #    pygame.HWSURFACE     hardware accelerated, only in FULLSCREEN
          #    pygame.OPENGL        create an opengl renderable display
          #    pygame.RESIZABLE     display window should be sizeable
          #    pygame.NOFRAME       display window will have no border or controls

        self.fail()
项目:LovelySpace    作者:lmb753    | 项目源码 | 文件源码
def __init__(self):
        self.parameters = Parameters("Config/default.ini")
        if isfile("Config/config.ini") :
            self.parameters.Load("Config/config.ini")

        # screen mode
        screenMode = self.parameters["screenMode"]
        if(screenMode == Screen_mode.Fullscreen) :
            args = pygame.HWSURFACE | pygame.FULLSCREEN | pygame.DOUBLEBUF
        elif(screenMode == Screen_mode.Borderless) :
            os.environ['SDL_VIDEO_WINDOW_POS'] = '0,0'
            args = pygame.NOFRAME
        else:
            args = 0
            os.environ["SDL_VIDEO_CENTERED"] = "1"

        # window icon
        self.icon = pygame.image.load("Assets/icon.png")
        self.icon = pygame.transform.scale(self.icon, (32, 32))
        pygame.display.set_icon(self.icon)

        # window parameters
        self.width = self.parameters["windowWidth"]
        self.height = self.parameters["windowHeight"]

        # some managers and important things
        self.screen = pygame.display.set_mode((self.width, self.height), args)
        pygame.display.set_caption("Lovely Space")
        self.clock = pygame.time.Clock()
        self.input = input.Input(self)
        self.audio = audio.Audio()
        self.size = size.Size(self.width, self.height, 1920, 1080)

        # a random font
        self.fpsFont = pygame.font.SysFont("Arial", 25)

        # drunk shit
        self.iniPosition = pygame.math.Vector2(0, 200)
        self.drunkY = 1
        self.drunkX = 1

        # pause things
        self.pause = None
        self.isPaused = False

        self.mode = titlescreen.TitleScreen(self)
        #self.mode = game.Game(self)
项目:ATLeS    作者:liffiton    | 项目源码 | 文件源码
def _get_screen(xwin=False):
    """Initializes a new pygame screen using the framebuffer"""
    if display_mocked:
        xwin = True

    # Based on "Python GUI in Linux frame buffer"
    # http://www.karoltomala.com/blog/?p=679
    disp_no = os.getenv("DISPLAY")
    if disp_no:
        logging.info("Running under X display %s", disp_no)

    # Make sure that SDL_VIDEODRIVER is set
    if xwin:
        driver = 'x11'
    else:
        driver = 'directfb'   # alternatives: 'fbcon', 'svgalib'
    if not os.getenv('SDL_VIDEODRIVER'):
        os.putenv('SDL_VIDEODRIVER', driver)

    try:
        pygame.display.init()
    except pygame.error:
        logging.exception("Display init failed using driver: %s", driver)
        raise

    if xwin:
        size = (320, 200)
        options = 0
    else:
        # fullscreen
        info = pygame.display.Info()
        size = (info.current_w, info.current_h)
        logging.info("Framebuffer size: %d x %d", size[0], size[1])
        options = pygame.FULLSCREEN | pygame.DOUBLEBUF
    screen = pygame.display.set_mode(size, options)

    # Clear the screen to start
    screen.fill((0, 0, 0))
    pygame.mouse.set_visible(False)
    # Render the screen
    pygame.display.update()

    return screen
项目:TonsleyLEDManager    作者:JonnoFTW    | 项目源码 | 文件源码
def show(Runner, arg=None, fps=24, rows=17, cols=165, scale=8, withArgs=False):
    import pygame, sys
    FPS = fps
    fpsClock = pygame.time.Clock()

    board_dimensions = (cols, rows)
    #yep
    disp_size = (cols * scale, rows * scale)
    pygame.init()
    screen_opts =  pygame.RESIZABLE | pygame.DOUBLEBUF
    screen = pygame.display.set_mode(disp_size, screen_opts)
    changed = False
    if arg is None:
        runner = Runner(board_dimensions)
    else:
        runner = Runner(board_dimensions, arg)
    font = pygame.font.Font('slkscr.ttf', 32)
    while True:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                sys.exit()
            if e.type == pygame.VIDEORESIZE:
                disp_size = e.dict['size']
                screen = pygame.display.set_mode(disp_size, screen_opts)
        screen.fill((0, 0, 0))
        # draw the pixels
        txts = ["FPS: {0:.2f}".format(fpsClock.get_fps())]
        if withArgs:
            pixels, txt = runner.run(events)
            txts.append(txt)
        else:
            pixels = runner.run()
            if type(pixels) is tuple:
                pixels, txt = pixels
                txts.append(txt)

        temp_surface = pygame.Surface(board_dimensions)
        pygame.surfarray.blit_array(temp_surface, pixels)
        pygame.transform.scale(temp_surface, disp_size, screen)
        i = 1
        for txt in txts:
            for line in txt.splitlines():
                screen.blit(font.render(line.replace('[', '').replace(']', '').strip(), 1, (255, 255, 255)),
                            (30, 30 * i))
                i += 1

        pygame.display.flip()
        fpsClock.tick(FPS)
项目:pyimgui    作者:swistakm    | 项目源码 | 文件源码
def main():
    pygame.init()

    size = 800, 600

    pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL)

    io = imgui.get_io()
    io.fonts.add_font_default()
    io.display_size = size

    renderer = PygameRenderer()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

            renderer.process_event(event)

        imgui.new_frame()

        if imgui.begin_main_menu_bar():
            if imgui.begin_menu("File", True):

                clicked_quit, selected_quit = imgui.menu_item(
                    "Quit", 'Cmd+Q', False, True
                )

                if clicked_quit:
                    exit(1)

                imgui.end_menu()
            imgui.end_main_menu_bar()

        imgui.show_test_window()

        imgui.begin("Custom window", True)
        imgui.text("Bar")
        imgui.text_colored("Eggs", 0.2, 1., 0.)
        imgui.end()

        # note: cannot use screen.fill((1, 1, 1)) because pygame's screen
        #       does not support fill() on OpenGL sufraces
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()

        pygame.display.flip()
项目:KinectHowOld    作者:crwilcox    | 项目源码 | 文件源码
def __init__(self):
        pygame.init()


        # Used to manage how fast the screen updates
        self._clock = pygame.time.Clock()

        # Set the width and height of the screen [width, height]
        self._infoObject = pygame.display.Info()
        self._screen = pygame.display.set_mode(
            (self._infoObject.current_w >> 1, self._infoObject.current_h >> 1),
            pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE, 32
        )

        pygame.display.set_caption("Guess your Age!")

        # Loop until the user clicks the close button.
        self._done = False

        # Kinect runtime object, we want only color and body frames
        if PyKinectRuntime and USE_KINECT:
            self._kinect = PyKinectRuntime.PyKinectRuntime(
                PyKV2.FrameSourceTypes_Color |
                PyKV2.FrameSourceTypes_Body
            )
            frame_dimension = (
                self._kinect.color_frame_desc.Width,
                self._kinect.color_frame_desc.Height
            )
        else:
            self._kinect = None
            frame_dimension = 800, 600

        # back buffer surface for getting Kinect color frames, 32bit color,
        # width and height equal to the Kinect color frame size
        self._frame_surface = pygame.Surface(frame_dimension, 0, 32)

        # here we will store skeleton data
        self._bodies = None
        self._stored_bodies = {}

        self._faces = []
        self._face_bodies = []

        self._update_oxford = 0
        self.python_logo_image = pygame.image.load('pylogo.png')
        self.msft_logo_image = pygame.image.load('microsoftlogo.png')

        self.bg_color = pygame.Color(55, 117, 169)
项目:mini_rpg    作者:paolo-perfahl    | 项目源码 | 文件源码
def __init__(self, text, width=640, height=400, fps=30, textcolor=(0,0,255), 
                 bgcolor=(255,255,255), font=('mono', 24, True), new_init=True, bg_filename=None):
        """Initialize pygame, window, background, font,...
           default arguments 
        """

        #pygame.mixer.pre_init(44100, -16, 2, 2048) 

        if new_init:
            pygame.init()

        #jump = pygame.mixer.Sound(os.path.join('data','jump.wav'))  #load sound
        #self.sound1 = pygame.mixer.Sound(os.path.join('data','Pickup_Coin.wav'))
        #self.sound2 = pygame.mixer.Sound(os.path.join('data','Jump.wav'))
        #self.sound3 = pygame.mixer.Sound(os.path.join('data','mix.wav'))
        pygame.display.set_caption("Press ESC to quit, curosr keys / PgUp, PgDown to scroll")
        self.text = text
        self.bgcolor = bgcolor
        self.textcolor = textcolor
        self.lines = text.split("\n")
        self.width = width
        self.height = height
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        if bg_filename is None:
           self.background.fill(self.bgcolor) # fill background white
        else:
           try:
               print("i try to load:", bg_filename)
               self.background = pygame.image.load(bg_filename)
               self.background = pygame.transform.scale(self.background, (self.width, self.height))
           except:
                print("exception while processing:", bg_filename)
                self.background.fill(self.bgcolor) # fill background white
        self.clock = pygame.time.Clock()
        self.fps = fps
        self.playtime = 0.0
        self.offset_y = self.height - 10
        self.x = 100
        self.dy = 50
        self.text_height = len(self.lines) * self.dy
        self.bold = font[2]
        self.font = pygame.font.SysFont(font[0], font[1], self.bold)