我们从Python开源项目中,提取了以下46个代码示例,用于说明如何使用pygame.FULLSCREEN。
def todo_test_list_modes(self): # __doc__ (as of 2008-08-02) for pygame.display.list_modes: # pygame.display.list_modes(depth=0, flags=pygame.FULLSCREEN): return list # get list of available fullscreen modes # # This function returns a list of possible dimensions for a specified # color depth. The return value will be an empty list if no display # modes are available with the given arguments. A return value of -1 # means that any requested resolution should work (this is likely the # case for windowed modes). Mode sizes are sorted from biggest to # smallest. # # If depth is 0, SDL will choose the current/best color depth for the # display. The flags defaults to pygame.FULLSCREEN, but you may need # to add additional flags for specific fullscreen modes. # self.fail()
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()
def __init__(self, name, size, fullscreen=True): # Call init routines pygame.init() # Window name pygame.display.set_caption(name) # Hide mouse cursor pygame.mouse.set_visible(False) # Store screen and size self.size = size if fullscreen: self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN) else: self.screen = pygame.display.set_mode(size) # windowed mode is for debug so we also show the cursor pygame.mouse.set_visible(True) # Clear screen self.clear() self.apply()
def __init__(self, screen, resolution=(800,480), ui_placement_mode=False, fps=60, dev_mode=False, audio=(22050, -8, 1, 1024)): # init system pygame.mixer.init(audio[0], audio[1], audio[2], audio[3]) pygame.font.init() pygame.init() self.screenSurface = pygame.display.set_mode(resolution) #, pygame.FULLSCREEN) self.fpsClock = pygame.time.Clock() self.fps = fps pygame.display.set_caption("LCARS") if not dev_mode: pygame.mouse.set_visible(False) # set up screen elements self.all_sprites = pygame.sprite.LayeredDirty() self.all_sprites.UI_PLACEMENT_MODE = ui_placement_mode self.screen = screen self.screen.setup(self.all_sprites) self.running = True
def init_pygame( self, native_width=480, native_height=272 ): self.background_colour = ( 255,255,255 ) pygame.init() display_info = pygame.display.Info() w = display_info.current_w h = display_info.current_h self.window_size=(w,h) if (w <= native_width) or (h <= native_height): self.window = pygame.display.set_mode( self.window_size, pygame.FULLSCREEN ) else: self.window = pygame.display.set_mode( (native_width, native_height) ) self.surface = pygame.display.get_surface() pygame.mouse.set_visible( False ) self.clock = pygame.time.Clock()
def fullscreen_toggle(self, info): """toggle between fullscreen and windowed version with CTRL + F current activity will be reset""" self.redraw_needed = [True, True, True] if self.config.fullscreen is True: self.config.fullscreen = False self.size = self.wn_size[:] self.screen = pygame.display.set_mode(self.size, pygame.RESIZABLE) self.fs_rescale(info) else: self.config.fullscreen = True self.size = self.fs_size[:] self.screen = pygame.display.set_mode(self.size, pygame.FULLSCREEN) self.fs_rescale(info) pygame.display.flip()
def screenSize(sizex, sizey, xpos=None, ypos=None, fullscreen=False): global bgcolor global screen global bgSurface if xpos != None and ypos != None: os.environ['SDL_VIDEO_WINDOW_POS'] = "%d, %d" % (xpos, ypos + 50) else: windowInfo = pygame.display.Info() monitorWidth = windowInfo.current_w monitorHeight = windowInfo.current_h os.environ['SDL_VIDEO_WINDOW_POS'] = "%d, %d" % ((monitorWidth - sizex) / 2, (monitorHeight - sizey) / 2) if fullscreen: screen = pygame.display.set_mode([sizex, sizey], pygame.FULLSCREEN) else: screen = pygame.display.set_mode([sizex, sizey]) screen.fill(bgcolor) pygame.display.set_caption("Graphics Window") bgSurface = screen.copy() pygame.display.update()
def Refresh(self): self.screen.fill((255,255,255)) self.App.Refresh() pygame.display.update() if not pygame.key.get_pressed()[pygame.K_LCTRL]: self.flag = False if not pygame.key.get_pressed()[pygame.K_LCTRL]: self.flag = False if pygame.key.get_pressed()[pygame.K_LCTRL] and pygame.key.get_pressed()[pygame.K_s] and not self.flag: self.flag = True name = str( time.time() )+ ".png" pygame.image.save(self.screen , str( time.time() )+ ".png") print "screenshot ",name," saved" if pygame.key.get_pressed()[ pygame.K_F11 ] and not self.lastpresssed: self.lastpresssed = True if self.fullscreen == 0: self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT),pygame.FULLSCREEN) self.fullscreen = 1 else: self.fullscreen = 0 self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT)) if not pygame.key.get_pressed()[pygame.K_F11]: self.lastpresssed = False
def __init__(self): # Resolution self.width = 800 self.height = 600 self.resolution = (self.width,self.height) #self.fullscreen = pygame.FULLSCREEN pygame.init() # Makes pygame work # Set the resolution self.screen = pygame.display.set_mode(self.resolution) # Set Title self.caption = pygame.display.set_caption('Main Menu') # Set default font self.font = pygame.font.Font(None, 30) self.Rects = Rects(self)
def init_display(): """ set up the pygame display, full screen """ # Check which frame buffer drivers are available # Start with fbcon since directfb hangs with composite output drivers = ['fbcon', 'directfb', 'svgalib', 'directx', 'windib'] 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: pygame.display.init() except pygame.error: # logging.warn('Driver: %s failed.' % driver) continue found = True logging.debug('using %s driver', driver) break if not found: raise Exception('No suitable video driver found!') size = (pygame.display.Info().current_w, pygame.display.Info().current_h) pygame.mouse.set_visible(0) if driver != 'directx': # debugging hack runs in a window on Windows screen = pygame.display.set_mode(size, pygame.FULLSCREEN) else: logging.info('running in windowed mode') # set window origin for windowed usage os.putenv('SDL_VIDEO_WINDOW_POS', '0,0') # size = (size[0]-10, size[1] - 30) screen = pygame.display.set_mode(size, pygame.NOFRAME) logging.debug('display size: %d x %d', size[0], size[1]) # Clear the screen to start screen.fill(BLACK) return screen, size
def check_keydown_events(settings, event, screen, tile_map): """Respond to key down events""" player = tile_map.player if event.key == pygame.K_ESCAPE: sys.exit() if event.key == pygame.K_a: generate_new_random_blob(settings, screen, settings.image_res.enemy_blob_images, tile_map) if event.key == pygame.K_r: reset_game(tile_map) if event.key == pygame.K_LEFT: if not player.idle_top: if player.dx == 0.0: player.dx = -1 * settings.player_dx player.facing_left = True if event.key == pygame.K_RIGHT: if not player.idle_top: if player.dx == 0.0: player.dx = settings.player_dx player.facing_left = False if event.key == pygame.K_F9: if settings.fullscreen == True: settings.fullscreen = False pygame.display.set_mode((800, 600)) else: settings.fullscreen = True pygame.display.set_mode((800, 600), pygame.FULLSCREEN)
def init_pygame(self): pygame.init() self.size = (pygame.display.Info().current_w, pygame.display.Info().current_h) print "Initialised PyGame: Screen Width " + str(self.size[0]) + " x Height " + str(self.size[1]) pygame.display.set_caption('Photo Booth') pygame.mouse.set_visible(False) # Hide the mouse cursor self.screen = pygame.display.set_mode(self.size, pygame.FULLSCREEN)
def __init__(self, background = None): # Init framebuffer/touchscreen environment variables os.putenv('SDL_VIDEODRIVER', 'fbcon') os.putenv('SDL_FBDEV', '/dev/fb1') os.putenv('SDL_MOUSEDRV', 'TSLIB') os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen') self._backlight_on = True self.on() # Init pygame and screen print "Initting..." pygame.init() print "Setting Mouse invisible..." pygame.mouse.set_visible(False) print "Setting fullscreen..." modes = pygame.display.list_modes(16) self._screen = pygame.display.set_mode(modes[0], pygame.FULLSCREEN, 16) self._needs_update = True # Load background self._background = pygame.image.load(background) self._screen.fill(0) self._screen.blit(self._background, (0, 0)) pygame.display.update() # Load font self._font = pygame.font.SysFont("Arial", 24) self._images = [] self._buttons = [] self._status_lines = [] self.update()
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_ESCAPE: self.effect.timeStartDarken = self.effect.time self.effect.timeEndDarken = self.effect.time + self.dt self.audio.state = "exit" if event.key == pg.K_UP: self.arrow.moveUp() if event.key == pg.K_DOWN: self.arrow.moveDown() if self.arrow.index == 0: if event.key == pg.K_RIGHT: self.backgroundSetting.next() if event.key == pg.K_LEFT: self.backgroundSetting.previous() if event.key == pg.K_RETURN: if self.backgroundSetting.index == 0: self.render.flip(True, False) if self.backgroundSetting.index == 1: self.render.flip(False, True) if self.arrow.index == 1: if event.key == pg.K_RIGHT: self.fullscreenSetting.next() if event.key == pg.K_LEFT: self.fullscreenSetting.previous() if event.key == pg.K_RETURN: if self.fullscreenSetting.index == 0: pg.display.set_mode((settings.WIDTH, settings.HEIGHT)) if self.fullscreenSetting.index == 1: pg.display.set_mode((settings.WIDTH, settings.HEIGHT), pg.FULLSCREEN) self.messageMenu("screen") self.messageScene("screen") self.messageCutScene("screen")
def __initScreen(self): pygame.init() self.screen = pygame.display.set_mode([1920, 1200], pygame.FULLSCREEN) pygame.display.update() self.outputScreen = OutputScreen(self.screen)
def setup(self): self.font = pygame.font.Font(None, 30) if self.cfg is not None: self.parse_games_cfg(self.cfg) else: self.parse_games() if self.windowed: flags = 0 else: flags = pygame.FULLSCREEN info = pygame.display.Info() self.w = info.current_w self.h = info.current_h self.screen = pygame.display.set_mode((self.w, self.h), flags) pygame.mouse.set_visible(False)
def __init__(self, resolution=(640, 480), cmdline=""): self.color = (0,0,0) self.resolution = resolution if "--fullscreen" in cmdline: self.window = \ pygame.display.set_mode(self.resolution, pygame.FULLSCREEN) else: self.window = pygame.display.set_mode(self.resolution) # pygame.display.set_mode() verändert die Größe des Fensters # Über das zweite Argument, pygame.FULLSCREEN, kann das Fenster # in den Vollbildmodus versetzt werden pygame.display.set_caption('A Simple Yet Insightful Pygame Example') # Verändert die Beschriftung des Fensters pygame.mouse.set_visible(0) # Verhindert, dass die Maus gezeigt wird self.screen = pygame.display.get_surface() # Generiert ein Surface des Fensters # Siehe: Allgemeines über Surfaces self.screen.fill(self.color) # Füllt das Surface self.screen mit der übergebenen Farbe # Siehe: Allgemeines über Farben self.screen_rect = self.screen.get_rect() # Rectangle des Fensters # Siehe: Allgemeines über Rectangles
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)
def __init__(self): if config.fullscreen: config.set_max_resolution() self.surface = pygame.display.set_mode(config.resolution, pygame.FULLSCREEN) else: self.surface = pygame.display.set_mode(config.resolution) self.background = pygame.Surface(self.surface.get_size()) self.background = self.background.convert() self.background.fill(config.table_color) self.surface.blit(self.background, (0, 0))
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'])
def main(): pg.init() screen = pg.display.set_mode((1920,1200), pg.FULLSCREEN|pg.DOUBLEBUF|pg.HWSURFACE) lock = image.DellImage("lock_https.gif") packet = cnc_packet.build_upload_packet(cnc_packet.build_image_blob(lock, 50, 50)) display_packet(packet, screen) while True: x, y = pg.mouse.get_pos() packet = cnc_packet.build_cursor_packet(x, y) display_packet(packet, screen)
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)
def __init__(self, device, server, fullscreen, width, height): #init pygame pygame.init() #load font font = pygame.font.SysFont(FONT, FONTSIZE) #setup the screen #set the screen caption pygame.display.set_caption("Blue Dot") #create the screen screenflags = 0 if fullscreen: screenflags = pygame.FULLSCREEN if width == None and height == None: display_info = pygame.display.Info() width = display_info.current_w height = display_info.current_h if width == None: width = DEFAULTSIZE[0] if height == None: height = DEFAULTSIZE[1] screen = pygame.display.set_mode((width, height), screenflags) #has a server been specified? If so connected directly if server: button_screen = ButtonScreen(screen, font, device, server, width, height) button_screen.run() else: #start the devices screen devices_screen = DevicesScreen(screen, font, device, width, height) devices_screen.run() pygame.quit()
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
def toggle_fullscreen(self, key): if key == pg.K_F1: screen_size = pg.display.get_surface().get_size() self.fullscreen = not self.fullscreen if self.fullscreen: self.screen = pg.display.set_mode(screen_size, pg.FULLSCREEN) else: self.screen = pg.display.set_mode(screen_size)
def main(): pg.init() pg.mouse.set_visible(False) # hide the pointer #screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pg.FULLSCREEN) # windows screen = pg.display.set_mode((1920, 1080), pg.NOFRAME) # linux game = Game(screen) game.create_sprites() game.update_calendar() game.update_weather() game.change_state() game.run() exit(0)
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
def screen(w, h, fullscreen=False): screen_info.resolution = [w, h] if fullscreen: screen_info.screen = pygame.display.set_mode([w, h], pygame.FULLSCREEN) else: screen_info.screen = pygame.display.set_mode([w, h]) # Create surface for turtle drawings create_pen_surface() # Get screen center CENTER.x = screen_info.resolution[0] / 2 CENTER.y = screen_info.resolution[1] / 2
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 = []
def __init__(self): "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) os.putenv('SDL_FBDEV', '/dev/fb1') # Select frame buffer driver # Make sure that SDL_VIDEODRIVER is set driver = 'fbcon' if not os.getenv('SDL_VIDEODRIVER'): os.putenv('SDL_VIDEODRIVER', driver) try: pygame.display.init() except pygame.error: print 'Driver: {0} failed.'.format(driver) exit(0) size = (pygame.display.Info().current_w, pygame.display.Info().current_h) self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN) # Clear the screen to start self.screen.fill((0, 0, 0)) # Initialise font support pygame.font.init() # Render the screen pygame.display.update()
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()
def __init__(self): if platform.system() == "Windows": pygame.display.init() pygame.display.set_caption("pySokoban") self.size = (800,600) self.screen = pygame.display.set_mode(self.size) elif self.getUserInterface() == "graphics": pygame.display.init() pygame.display.set_caption("pySokoban") self.size = (800,600) self.screen = pygame.display.set_mode(self.size) else: "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'] 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: 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!') self.size = (pygame.display.Info().current_w, pygame.display.Info().current_h) print "Framebuffer size: %d x %d" % (self.size[0], self.size[1]) self.screen = pygame.display.set_mode(self.size, pygame.FULLSCREEN) # Clear the screen to start self.screen.fill((0, 0, 0)) # Initialise font support pygame.font.init() # Disable mouse pygame.mouse.set_visible(False) # Render the screen pygame.display.update()
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
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
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)
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
def main(): DISPLAYSURF = pygame.display.set_mode((0,0),pygame.FULLSCREEN) pygame.display.set_caption('Agario') FPSCLOCK = pygame.time.Clock() FOODAMOUNT = 300 FPS = 1000 world_map = ContinuousMap(DISPLAYSURF,MAP_LENGTH,MAP_LENGTH) world_map.speed = 10 world_map.character.radius = 100 for _ in range(FOODAMOUNT): world_map.add_object(random.randint(0,MAP_LENGTH),random.randint(0,MAP_LENGTH)) f = pygame.font.Font(None, 64) while True: for e in pygame.event.get(): if e.type == KEYDOWN: if e.key == K_ESCAPE: pygame.quit() sys.exit() k = pygame.key.get_pressed() if k[K_UP]: world_map.character_move(Directions.UP) if k[K_DOWN]: world_map.character_move(Directions.DOWN) if k[K_LEFT]: world_map.character_move(Directions.LEFT) if k[K_RIGHT]: world_map.character_move(Directions.RIGHT) if k[K_p]: world_map.character.radius += 1 if k[K_l]: world_map.character.radius -= 1 #world_map.animate() world_map.draw() FPSCLOCK.tick(FPS) UPDATE() if world_map.has_lost(): DISPLAYSURF.blit(f.render("GAME OVER", True, (255, 255, 255)), (0,0)) """ while not any(e.type == KEYDOWN and e.key == K_ESCAPE for e in pygame.event.get()): pass pygame.quit() sys.exit() """
def screensaver(screenresolution = (640,480), fullscreen = False): # -*- coding: utf-8 -*- """very simple test "game" or screensaver. all the user have to do is press ESC or SPACE. the "game" paint random circles. the "game" accept a screen resolution tuple as argument. the "game" returns the time passed until the user pressed space""" pygame.init() #initialize pygame if fullscreen: screen=pygame.display.set_mode((screenresolution[0],screenresolution[1]), pygame.FULLSCREEN) # set screensize of pygame window else: screen=pygame.display.set_mode((screenresolution[0],screenresolution[1])) # set screensize of pygame window background = pygame.Surface(screen.get_size()) #create empty pygame surface background.fill((255,255,255)) #fill the background white color (red,green,blue) background = background.convert() #convert Surface object to make blitting faster screen.blit(background, (0,0)) #draw the background on screen clock = pygame.time.Clock() #create a pygame clock object mainloop = True FPS = 30 # desired framerate in frames per second. try out other values ! playtime = 0.0 # how many seconds the "game" is played while mainloop: milliseconds = clock.tick(FPS) # do not go faster than this framerate playtime += milliseconds / 1000.0 # add seconds to playtime # paint random circles color = (random.randint(0,255), random.randint(0,255), random.randint(0,255)) pygame.draw.circle(screen, color, (random.randint(0,screenresolution[0]), random.randint(0,screenresolution[1])), random.randint(1, min(screenresolution[0], screenresolution[1])), random.randint(0,1)) for event in pygame.event.get(): if event.type == pygame.QUIT: mainloop = False # pygame window closed by user elif event.type == pygame.KEYDOWN: print "event key:", event.key if event.key == pygame.K_ESCAPE: mainloop = False # user pressed ESC if event.key == pygame.K_SPACE: mainloop = False # user pressed ESC pygame.display.set_caption("press ESC to quit. FPS: %.2f (%ix%i), time: %.2f seonds" % (clock.get_fps(), screenresolution[0], screenresolution[1], playtime)) pygame.display.flip() # flip the screen like in a flip book print "This 'game' was played for %.2f seconds" % playtime pygame.quit() return playtime # in seconds
def initscreen(width, height) : #Initialisation pygame.init() if headless: #will not anymore be enabled as pygame will not init the screen if headless os.putenv('SDL_VIDEODRIVER', 'dummy') screen = pygame.display.set_mode((1,1)) size = (pygame.display.Info().current_w, pygame.display.Info().current_h) print "Pygame interface started in dummy mode, framebuffer size: %d x %d" % (size[0], size[1]) else: #init screen / window or fullscreen if windowed: #window mode with w and h submitted to the function screen = pygame.display.set_mode((width,height),0,32) pygame.display.set_caption(mytitle) size = (pygame.display.Info().current_w, pygame.display.Info().current_h) print "Pygame interface started in window mode, framebuffer size: %d x %d" % (size[0], size[1]) else: #if FS PUT fb1 as the framebuffer device => pitft, res, 320 x 240 # 29.03.2015... not working anymore on the pitft... with PRE "export SDL_FBDEV=/dev/fb1" IT WORKS! os.environ["SDL_FBDEV"] = "/dev/fb1" os.environ["SDL_MOUSEDRV"] = "TSLIB" os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen" #os.putenv('SDL_VIDEODRIVER', 'fbcon') #os.putenv('SDL_FBDEV' , '/dev/fb1') #os.putenv('SDL_MOUSEDRV' , 'TSLIB') #os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen') #screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) #not working anymore... screen = pygame.display.set_mode([320, 240], pygame.FULLSCREEN) #try like so OR without FS Flag? size = (pygame.display.Info().current_w, pygame.display.Info().current_h) print "Pygame interface started in fullscreen mode, framebuffer size: %d x %d" % (size[0], size[1]) return screen