本文整理汇总了Python中pygame.DOUBLEBUF属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.DOUBLEBUF属性的具体用法?Python pygame.DOUBLEBUF怎么用?Python pygame.DOUBLEBUF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pygame
的用法示例。
在下文中一共展示了pygame.DOUBLEBUF属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_pygame
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def main_pygame():
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()
on_frame()
# 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()
示例2: _init_renderer
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def _init_renderer(self):
"""Initialize the birdeye view renderer.
"""
pygame.init()
self.display = pygame.display.set_mode(
(self.display_size * 3, self.display_size),
pygame.HWSURFACE | pygame.DOUBLEBUF)
pixels_per_meter = self.display_size / self.obs_range
pixels_ahead_vehicle = (self.obs_range/2 - self.d_behind) * pixels_per_meter
birdeye_params = {
'screen_size': [self.display_size, self.display_size],
'pixels_per_meter': pixels_per_meter,
'pixels_ahead_vehicle': pixels_ahead_vehicle
}
self.birdeye_render = BirdeyeRender(self.world, birdeye_params)
示例3: start_screen
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def start_screen(self, resolution, aspect_ratio, scale=1):
self._resolution = resolution
self._aspect_ratio = aspect_ratio
self._scale = scale
size = (resolution[0] * aspect_ratio[0], resolution[1] * aspect_ratio[1])
self._screen = pygame.display.set_mode((size[0] * scale, size[1] * scale), pygame.DOUBLEBUF)
# self._screen.set_alpha(None)
pygame.display.set_caption("Human/Machine - Driving Software")
self._camera_surfaces = []
for i in range(aspect_ratio[0] * aspect_ratio[1]):
camera_surface = pygame.surface.Surface(resolution, 0, 24).convert()
self._camera_surfaces.append(camera_surface)
示例4: todo_test_flip
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
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()
示例5: game_loop
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def game_loop(args):
try:
# Init Pygame
pygame.init()
display = pygame.display.set_mode(
(args.width, args.height),
pygame.HWSURFACE | pygame.DOUBLEBUF)
pygame.display.set_caption(args.description)
font = pygame.font.Font(pygame.font.get_default_font(), 20)
text_surface = font.render('Rendering map...', True, COLOR_WHITE)
display.blit(text_surface, text_surface.get_rect(center=(args.width / 2, args.height / 2)))
pygame.display.flip()
# Init modules
input_module = ModuleInput(MODULE_INPUT)
hud_module = ModuleHUD(MODULE_HUD, args.width, args.height)
world_module = ModuleWorld(MODULE_WORLD, args, timeout=2.0)
# Register Modules
module_manager.register_module(world_module)
module_manager.register_module(hud_module)
module_manager.register_module(input_module)
module_manager.start_modules()
clock = pygame.time.Clock()
while True:
clock.tick_busy_loop(60)
module_manager.tick(clock)
module_manager.render(display)
pygame.display.flip()
except KeyboardInterrupt:
print('\nCancelled by user. Bye!')
finally:
if world_module is not None:
world_module.destroy()
示例6: game_loop
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def game_loop(args):
pygame.init()
pygame.font.init()
world = None
try:
client = carla.Client(args.host, args.port)
client.set_timeout(2.0)
display = pygame.display.set_mode(
(args.width, args.height),
pygame.HWSURFACE | pygame.DOUBLEBUF)
hud = HUD(args.width, args.height)
world = WorldSR(client.get_world(), hud, args)
controller = KeyboardControl(world, args.autopilot)
clock = pygame.time.Clock()
while True:
clock.tick_busy_loop(60)
if controller.parse_events(client, world, clock):
return
if not world.tick(clock):
return
world.render(display)
pygame.display.flip()
finally:
if (world and world.recording_enabled):
client.stop_recorder()
if world is not None:
world.destroy()
pygame.quit()
# ==============================================================================
# -- main() --------------------------------------------------------------------
# ==============================================================================
示例7: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def __init__(self, parent):
self.quit = False
self._parent = parent
self._width = 800
self._height = 600
self._throttle_delta = 0.05
self._steering_delta = 0.01
self._surface = None
pygame.init()
pygame.font.init()
self._clock = pygame.time.Clock()
self._display = pygame.display.set_mode((self._width, self._height), pygame.HWSURFACE | pygame.DOUBLEBUF)
pygame.display.set_caption("Human Agent")
示例8: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
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")
示例9: run_task
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def run_task(self, sample):
try:
pygame.init()
pygame.font.init()
self.hud = HUD(*self.display_dim)
self.display = pygame.display.set_mode(
self.display_dim,
pygame.HWSURFACE | pygame.DOUBLEBUF
)
# print("[carla_task] Setting up world.")
if self.client.get_world().get_map().name == self.world_map:
self.world = World(self.client.get_world(), self.hud,
cam_transform=self.cam_transform)
else:
self.world = World(self.client.load_world(self.world_map),
self.hud, cam_transform=self.cam_transform)
# print("[carla_task] World setup complete.")
self.use_sample(sample)
self.world.restart()
self.timestep = 0
while self.timestep < self.n_sim_steps:
self.step_world()
self.timestep += 1
traj = self.trajectory_definition()
finally:
self.world.destroy()
pygame.quit()
return traj
示例10: get_display
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def get_display(window_size, mode=pygame.HWSURFACE | pygame.DOUBLEBUF):
"""Returns a display used to render images and text.
:param window_size: a tuple (width: int, height: int)
:param mode: pygame rendering mode. Default: pygame.HWSURFACE | pygame.DOUBLEBUF
:return: a pygame.display instance.
"""
return pygame.display.set_mode(window_size, mode)
示例11: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def __init__(self, ai_settings: Settings, stats: GameStats, **kwargs: game_items_types):
"""Initialize with default items unless specified in kwargs."""
# Default initializations for game items.
# Initialize screen.
flags = pygame.HWSURFACE | pygame.DOUBLEBUF # | pygame.FULLSCREEN
self.screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height), flags)
pygame.display.set_caption("Alien Invasion Game")
# Initialize ship.
self.ship = Ship(ai_settings, self.screen)
# Initialize aliens group.
self.aliens = Group()
# Initialize bullets group.
self.bullets = Group()
# Initialize buttons.
self.play_button = Button(self.screen, "Play!")
# TODO implement Restart and Cancel buttons.
# self.restart_button = Button(self.screen, "Restart")
# self.cancel_button = Button(self.screen, "Cancel", (255, 0, 0, 80))
# self.set_button_pos()
# Initialize scorecard.
self.sb = Scorecard(ai_settings, stats, self.screen)
# Set the game items for those default values are given.
for game_item in kwargs:
if game_item in self.acceptable_game_items:
self.__setattr__(game_item, kwargs[game_item])
示例12: _make_context
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def _make_context(self, width, height):
"""Create the ModernGL context."""
glconfig = {
'GL_CONTEXT_MAJOR_VERSION': 4,
'GL_CONTEXT_PROFILE_MASK': pygame.GL_CONTEXT_PROFILE_CORE,
}
for k, v in glconfig.items():
k = getattr(pygame, k)
pygame.display.gl_set_attribute(k, v)
dims = width, height
flags = pygame.OPENGL | pygame.DOUBLEBUF
if self.fullscreen:
# SDL's detection for "legacy" fullscreen seems to fail on
# Ubuntu 16.04 at least. Set an environment variable so that it
# asks the Window Manager for full screen mode instead.
# https://github.com/spurious/SDL-mirror/blob/c8b01e282dfd49ea8bbf1faec7fd65d869ea547f/src/video/x11/SDL_x11window.c#L1468
os.environ['SDL_VIDEO_X11_LEGACY_FULLSCREEN'] = "0"
flags |= pygame.FULLSCREEN
if not self._scaler:
self._scaler = 'linear'
dims = 0, 0
elif self._scaler:
flags |= pygame.SCALED
pygame.display.set_mode(
dims,
flags=flags,
depth=24
)
ctx = moderngl.create_context(require=410)
self._real_size = pygame.display.get_window_size()
if self._real_size != (width, height):
self.drawer = self._make_scaler(ctx, (width, height))
return ctx
示例13: setWindowSize
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def setWindowSize(self, width, height):
self.screenSize = (width, height)
self.displayFlags = pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE
self.screen = pygame.display.set_mode( self.screenSize, self.displayFlags )
# implement by extending class
示例14: game_loop
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def game_loop(args):
pygame.init()
pygame.font.init()
world = None
try:
client = carla.Client(args.host, args.port)
client.set_timeout(2.0)
display = pygame.display.set_mode(
(args.width, args.height),
pygame.HWSURFACE | pygame.DOUBLEBUF)
hud = HUD(args.width, args.height)
world = World(client.get_world(), hud)
controller = KeyboardControl(world, args.autopilot)
clock = pygame.time.Clock()
while True:
clock.tick_busy_loop(60)
if controller.parse_events(world, clock):
return
world.tick(clock)
world.render(display)
pygame.display.flip()
finally:
if world is not None:
world.destroy()
pygame.quit()
# ==============================================================================
# -- main() --------------------------------------------------------------------
# ==============================================================================
示例15: multi_view_render
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import DOUBLEBUF [as 别名]
def multi_view_render(images, unit_dimension, actor_configs):
"""Render images based on pygame > 1.9.4
Args:
images (dict):
unit_dimension (list): window size, e.g., [84, 84]
actor_configs (dict): configs of actors
Returns:
N/A.
"""
global i
pygame.init()
surface_seq = ()
poses, window_dim = get_surface_poses(
len(images), unit_dimension, images.keys())
# Get all surfaces.
for actor_id, im in images.items():
if not actor_configs[actor_id]["render"]:
continue
surface = pygame.surfarray.make_surface(im.swapaxes(0, 1) * 128 + 128)
surface_seq += ((surface, (poses[actor_id][1], poses[actor_id][0])), )
display = pygame.display.set_mode((window_dim[0], window_dim[1]),
pygame.HWSURFACE | pygame.DOUBLEBUF)
display.blits(blit_sequence=surface_seq, doreturn=1)
pygame.display.flip()
# save to disk
# pygame.image.save(display,
# "/mnt/DATADRIVE1/pygame_surfs/" + str(i) + ".jpeg")
i += 1