我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用pygame.HWSURFACE。
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()
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): #window setup pygame.display.set_caption('Game Of Life') # initiate the clock and screen self.clock = pygame.time.Clock() self.last_tick = pygame.time.get_ticks() self.screen_res = [740, 490] self.font = pygame.font.SysFont("Impact", 19) self.sprites = pygame.sprite.Group() self.cells = [] self.generation = 0 self.population = 0 self.screen = pygame.display.set_mode(self.screen_res, pygame.HWSURFACE, 32) self.running = False self.createGrid() while 1: self.Loop()
def test_freetype_Font_render_mono(self): font = self._TEST_FONTS['sans'] color = pygame.Color('black') colorkey = pygame.Color('white') text = "." save_antialiased = font.antialiased font.antialiased = False try: surf, r = font.render(text, color, size=24) self.assertEqual(surf.get_bitsize(), 8) flags = surf.get_flags() self.assertTrue(flags & pygame.SRCCOLORKEY) self.assertFalse(flags & (pygame.SRCALPHA | pygame.HWSURFACE)) self.assertEqual(surf.get_colorkey(), colorkey) self.assertTrue(surf.get_alpha() is None) translucent_color = pygame.Color(*color) translucent_color.a = 55 surf, r = font.render(text, translucent_color, size=24) self.assertEqual(surf.get_bitsize(), 8) flags = surf.get_flags() self.assertTrue(flags & (pygame.SRCCOLORKEY | pygame.SRCALPHA)) self.assertFalse(flags & pygame.HWSURFACE) self.assertEqual(surf.get_colorkey(), colorkey) self.assertEqual(surf.get_alpha(), translucent_color.a) surf, r = font.render(text, color, colorkey, size=24) self.assertEqual(surf.get_bitsize(), 32) finally: font.antialiased = save_antialiased
def __init__(self): pygame.init() # Used to manage how fast the screen updates self._clock = pygame.time.Clock() # Loop until the user clicks the close button. self._done = False # Used to manage how fast the screen updates self._clock = pygame.time.Clock() # Kinect runtime object, we want only color and body frames self._kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Infrared) # back buffer surface for getting Kinect infrared frames, 8bit grey, width and height equal to the Kinect color frame size self._frame_surface = pygame.Surface((self._kinect.infrared_frame_desc.Width, self._kinect.infrared_frame_desc.Height), 0, 24) # here we will store skeleton data self._bodies = None # Set the width and height of the screen [width, height] self._infoObject = pygame.display.Info() self._screen = pygame.display.set_mode((self._kinect.infrared_frame_desc.Width, self._kinect.infrared_frame_desc.Height), pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE, 32) pygame.display.set_caption("Kinect for Windows v2 Infrared")
def run(self): # -------- Main Program Loop ----------- while not self._done: # --- Main event loop for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close self._done = True # Flag that we are done so we exit this loop elif event.type == pygame.VIDEORESIZE: # window resized self._screen = pygame.display.set_mode(event.dict['size'], pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE, 32) # --- Getting frames and drawing if self._kinect.has_new_infrared_frame(): frame = self._kinect.get_last_infrared_frame() self.draw_infrared_frame(frame, self._frame_surface) frame = None self._screen.blit(self._frame_surface, (0,0)) pygame.display.update() # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() # --- Limit to 60 frames per second self._clock.tick(60) # Close our Kinect sensor, close the window and quit. self._kinect.close() pygame.quit()
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("Kinect for Windows v2 Body Game") # Loop until the user clicks the close button. self._done = False # Used to manage how fast the screen updates self._clock = pygame.time.Clock() # Kinect runtime object, we want only color and body frames self._kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Color | PyKinectV2.FrameSourceTypes_Body) # 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((self._kinect.color_frame_desc.Width, self._kinect.color_frame_desc.Height), 0, 32) # here we will store skeleton data self._bodies = None
def __init__(self): pygame.init() pygame.mixer.init() self.beep_sound = pygame.mixer.Sound('audio\\beep.ogg') self.buzz_sound = pygame.mixer.Sound('audio\\buzz.ogg') 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("Kinect Game Framework Test") self.finished = False self._clock = pygame.time.Clock() self._kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Color | PyKinectV2.FrameSourceTypes_Body) self._frame_surface = pygame.Surface((self._kinect.color_frame_desc.Width, self._kinect.color_frame_desc.Height), 0, 32) self._bodies = None self.score = 0 self.vocab_dict = {"beach":"playa", "desert":"desierto", "forest":"bosque", "jungle":"selva", "hill":"loma", "island":"isla", "lake":"lago", "mountain":"montaña", "ocean":"oceano", "river":"rio", "valley":"valle", "basin":"cuenca", "volcano":"volcano", "waterfall":"cascada", "creek":"arroyo"} self._frame_surface.fill((255, 255, 255))
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 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 __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)
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 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)
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
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 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 run(self): # -------- Main Program Loop ----------- while not self._done: # --- Main event loop for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close self._done = True # Flag that we are done so we exit this loop elif event.type == pygame.VIDEORESIZE: # window resized self._screen = pygame.display.set_mode(event.dict['size'], pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE, 32) # --- Game logic should go here # --- Getting frames and drawing # --- Woohoo! We've got a color frame! Let's fill out back buffer surface with frame's data if self._kinect.has_new_color_frame(): frame = self._kinect.get_last_color_frame() self.draw_color_frame(frame, self._frame_surface) frame = None # --- Cool! We have a body frame, so can get skeletons if self._kinect.has_new_body_frame(): self._bodies = self._kinect.get_last_body_frame() # --- draw skeletons to _frame_surface if self._bodies is not None: for i in range(0, self._kinect.max_body_count): body = self._bodies.bodies[i] if not body.is_tracked: continue joints = body.joints # convert joint coordinates to color space joint_points = self._kinect.body_joints_to_color_space(joints) self.draw_body(joints, joint_points, SKELETON_COLORS[i]) # --- copy back buffer surface pixels to the screen, resize it if needed and keep aspect ratio # --- (screen size may be different from Kinect's color frame size) h_to_w = float(self._frame_surface.get_height()) / self._frame_surface.get_width() target_height = int(h_to_w * self._screen.get_width()) surface_to_draw = pygame.transform.scale(self._frame_surface, (self._screen.get_width(), target_height)); self._screen.blit(surface_to_draw, (0,0)) surface_to_draw = None pygame.display.update() # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() # --- Limit to 60 frames per second self._clock.tick(60) # Close our Kinect sensor, close the window and quit. self._kinect.close() pygame.quit()
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 __init__(self, host, port,camtype="webcam",ID=0,image_name='lena.png',change=True,Debug=True): self.host = host self.port = port self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind((self.host, self.port)) self.comThreads = [] self.alive = True; self.RGB0 = []; self.Depth = []; self.Body = []; self.camtype = camtype; self.ret = False; self.log = "test" self.HDRGB = []; self.imageName = image_name; self.change = change; self.sys_random = random.SystemRandom(); #Assuming 8bit pic self.cnt = 0; self.trip = 0; self.Debug = Debug self.send_counter = 0; self.rgb_cnt = 0; #Locks self.Lock = threading.Lock() if self.Debug: self.img = cv2.imread(self.imageName); #This one will be altered! self.orig_img = cv2.imread(self.imageName); #This one will be the same self.ImageT = threading.Thread(target=self.imagechanger) self.ImageT.start() self.height,self.width,self.channel = self.img.shape; self.x_pos = random.randint(10,self.width); self.y_pos = random.randint(10,self.height); if self.ImageT.isAlive(): self.log = "height: " + str(self.height) if Kinect: pygame.init() #Used to manage how fast the screen updates self._clock = pygame.time.Clock() self._done = False; 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) # Kinect runtime object, we want only color and body frames self._kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Color | PyKinectV2.FrameSourceTypes_Body | PyKinectV2.FrameSourceTypes_Depth | PyKinectV2.FrameSourceTypes_Infrared) # 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((self._kinect.color_frame_desc.Width, self._kinect.color_frame_desc.Height), 0, 32) # here we will store skeleton data self._bodies = None if camtype == "webcam": self.cap = cv2.VideoCapture(ID)
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)