Python pygame.OPENGL Examples

The following are 18 code examples of pygame.OPENGL(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygame , or try the search function .
Example #1
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #2
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #3
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #4
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #5
Source File: integrations_all_in_one.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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() 
Example #6
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #7
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #8
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #9
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #10
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #11
Source File: display_test.py    From fxxkpython with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #12
Source File: gl_display_context.py    From MCEdit-Unified with ISC License 5 votes vote down vote up
def displayMode():
        return pygame.OPENGL | pygame.RESIZABLE | pygame.DOUBLEBUF 
Example #13
Source File: window.py    From moderngl-window with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        super().__init__(**kwargs)

        pygame.display.init()

        pygame.display.gl_set_attribute(pygame.GL_CONTEXT_MAJOR_VERSION, self.gl_version[0])
        pygame.display.gl_set_attribute(pygame.GL_CONTEXT_MINOR_VERSION, self.gl_version[1])
        pygame.display.gl_set_attribute(pygame.GL_CONTEXT_PROFILE_MASK, pygame.GL_CONTEXT_PROFILE_CORE)
        pygame.display.gl_set_attribute(pygame.GL_CONTEXT_FORWARD_COMPATIBLE_FLAG, 1)
        pygame.display.gl_set_attribute(pygame.GL_DOUBLEBUFFER, 1)
        pygame.display.gl_set_attribute(pygame.GL_DEPTH_SIZE, 24)

        if self.samples > 1:
            pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLEBUFFERS, 1)
            pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLESAMPLES, self.samples)

        self._depth = 24
        self._flags = pygame.OPENGL | pygame.DOUBLEBUF
        if self.fullscreen:
            self._flags |= pygame.FULLSCREEN

            info = pygame.display.Info()
            desktop_size = info.current_w, info.current_h
            self._width, self._height = desktop_size
            self._buffer_width, self._buffer_height = self._width, self._height
        else:
            if self.resizable:
                self._flags |= pygame.RESIZABLE

        self._set_mode()
        self.title = self._title
        self.cursor = self._cursor
        self.init_mgl_context()
        self.set_default_viewport() 
Example #14
Source File: Base.py    From three.py with MIT License 5 votes vote down vote up
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 
Example #15
Source File: scene.py    From wasabi2d with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 
Example #16
Source File: main.py    From python-examples with MIT License 4 votes vote down vote up
def display_cube():
    WINDOW_WIDTH = 800
    WINDOW_HEIGHT = 600

    pygame.init()
    pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), pygame.DOUBLEBUF | pygame.OPENGL)
    
    OpenGL.GLU.gluPerspective(45, (WINDOW_WIDTH/WINDOW_HEIGHT), 0.1, 50.0)
    OpenGL.GL.glTranslatef(0.0, 0.0, -10)
    
    show_cube_1 = True
    show_cube_2 = True
    show_lines = True
    
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    running = False
                elif event.key == pygame.K_1:
                    show_cube_1 = not show_cube_1
                elif event.key == pygame.K_2:
                    show_cube_2 = not show_cube_2
                elif event.key == pygame.K_0:
                    show_lines = not show_lines
                    
                    
        OpenGL.GL.glRotate(1, 3, 10, 10) # (angle,x,y,z)
        OpenGL.GL.glClear(OpenGL.GL.GL_COLOR_BUFFER_BIT | OpenGL.GL.GL_DEPTH_BUFFER_BIT)

        if show_cube_1:
            cube(vertices1, edges) # large cube
        if show_cube_2:
            cube(vertices2, edges) # small cube
        if show_lines:
            lines(vertices1, vertices2)
        
        pygame.display.flip()
        pygame.time.wait(10)

    pygame.quit()

# --- 
Example #17
Source File: gl_display_context.py    From GDMC with ISC License 4 votes vote down vote up
def displayMode():
        return pygame.OPENGL | pygame.RESIZABLE | pygame.DOUBLEBUF 
Example #18
Source File: integrations_pygame.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def main():
    pygame.init()
    size = 800, 600

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

    imgui.create_context()
    impl = PygameRenderer()

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

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

            impl.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()
        impl.render(imgui.get_draw_data())

        pygame.display.flip()