我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用pygame.OPENGL。
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_gl_set_attribute(self): # __doc__ (as of 2008-08-02) for pygame.display.gl_set_attribute: # pygame.display.gl_set_attribute(flag, value): return None # request an opengl display attribute for the display mode # # When calling pygame.display.set_mode() with the pygame.OPENGL flag, # Pygame automatically handles setting the OpenGL attributes like # color and doublebuffering. OpenGL offers several other attributes # you may want control over. Pass one of these attributes as the flag, # and its appropriate value. This must be called before # pygame.display.set_mode() # # The OPENGL flags are; # GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_ACCUM_RED_SIZE, # GL_ACCUM_GREEN_SIZE, GL_ACCUM_BLUE_SIZE, GL_ACCUM_ALPHA_SIZE, # GL_MULTISAMPLEBUFFERS, GL_MULTISAMPLESAMPLES, GL_STEREO self.fail()
def todo_test_gl_get_attribute(self): # __doc__ (as of 2008-08-02) for pygame.display.gl_get_attribute: # pygame.display.gl_get_attribute(flag): return value # get the value for an opengl flag for the current display # # After calling pygame.display.set_mode() with the pygame.OPENGL flag, # it is a good idea to check the value of any requested OpenGL # attributes. See pygame.display.gl_set_attribute() for a list of # valid flags. # self.fail()
def display_openGL(w, h): pygame.display.set_mode((w,h), pygame.OPENGL|pygame.DOUBLEBUF) glClearColor(0.0, 0.0, 0.0, 1.0) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) gluOrtho2D(0, w, 0, h)
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)
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()
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 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()