[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Pygame for SDL 2, and how it may look.
- To: Pygame Mail List <pygame-users@xxxxxxxx>
- Subject: [pygame] Pygame for SDL 2, and how it may look.
- From: Lenard Lindstrom <len-l@xxxxxxxxx>
- Date: Thu, 13 Apr 2017 14:25:55 -0700
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Thu, 13 Apr 2017 17:26:01 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telus.net; s=neo; t=1492118757; bh=PU9c9U50SoY97nWLQb1fDAhDkOIbFOYz41VYGFn36Pg=; h=To:From:Subject:Date; b=mtI9UvbHimu7Fu3Y3bFNPCJ60CwY2hhyDrhkOAn0D09ssf/MUa+LnW7k21HPMQFHU mx+DLIkVPrjZUUMaH9XQ11eLCu2tsOAHwm1xphXFNaQ5OeAxPowwSqymB7bYoF2OIX nlqwPkJYBBkxxA0uLM01VekyE4xgYgIpEyyza7Qo4HgquFyTNUZsqWd25FPMrw/kf3 zy+Kl0U+LLtJbcG1jwQsHMTVX12Tqkfv3P2+SYaowgCYp5eAq2EMsz3OLAQPnizbLF 1Y4er8j3m3vl+pbRSSk9kIBl1HU85fsOw+JjJ2PpugbIxrsXXbMzq64XjHiq2lKehB 5l3vFkvarxX0A==
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
Hello everyone,
I have written some proof-of-concept code on how SDL 2 windows and
renderers may be incorporated into the Pygame Python API. Here is the
latest incarnation of a previous post
(http://archives.seul.org/pygame/users/Mar-2017/msg00139.html) as a
pygame.example program:
"""Render an image to a window
This is adapted from the SDL 2 example at
<http://www.willusher.io/sdl2%20tutorials/2013/08/17/lesson-1-hello-world>.
"""
import pygame
from pygame.display import RendererWindow
import os
def get_resource_path():
my_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(my_dir, 'data')
def run():
pygame.display.init()
title = "Hello World!"
rect = (100, 100, 640, 480)
flags = RendererWindow.SHOWN
with RendererWindow(title, rect, flags) as win:
ren = win.renderer
flags = (ren.ACCELERATED |
ren.PRESENTVSYNC )
ren.open(flags)
image_path = os.path.join(get_resource_path(), 'hello.bmp')
bmp = pygame.image.load(image_path)
tex = ren.new_texture_from_surface(bmp)
for i in range(3):
ren.clear()
tex.copy_to_renderer()
ren.update()
pygame.time.delay(1000)
pygame.quit()
if __name__ == '__main__':
run()
A window with renderer and a window with surface are implemented as
distinct subclasses of a standard Window extension type. Each Window
instance is an open window on the display. Window updates are perform by
methods on the corresponding renderer or surface. Window and renderer
specific constants, such as SDL_WINDOW_SHOWN and
SDL_RENDERER_ACCELERATED are class attributes, though they could also be
included in pygame.locals.
This is preliminary design work, so feedback is not only welcome but
also necessary.
Lenard Lindstrom