22
33PySDL2 FAQ
44==========
5- This is a list of Frequently Asked Questions about PySDL2. If you think,
6- something is missing , please suggest it !
5+ This is a list of Frequently Asked Questions about PySDL2. If there are any
6+ questions and answers you would like added here , please let us know on GitHub !
77
88On importing...
99---------------
1010... my script fails and complains that a SDL2 library could not be found!
1111
12- Do you have the libraries properly installed? If on macOS or Windows,
13- try running ``pip install pysdl2-dll `` and opening a fresh terminal
14- to fix the problem. If on Linux or similar, did you follow the operating
15- system's way of installing or registering libraries? If you placed the
16- libraries in some folder, make sure that the ``PYSDL2_DLL_PATH ``
17- environment variable points to the correct location.
12+ Do you have the libraries properly installed? On most platforms, you can
13+ install them easily using ``pip install pysdl2-dll ``. On ARM64 macOS, you
14+ can install native SDL2 binaries using the Homebrew package manager. For
15+ BSD, Linux on exotic architectures (not x86 or ARM64), and other Unix-like
16+ platforms, install the SDL2 binaries using your system's package manager. On
17+ all platforms, you can manually set the path of your SDL2 binaries using
18+ the ``PYSDL2_DLL_PATH `` environment variable.
1819
1920... my script fails complaining that the *found * SDL2 library can't be used!
2021
21- Do you use a 64-bit operating system? Please make sure, that the Python
22+ Do you use a 64-bit operating system? Please make sure that the Python
2223 interpreter *and * that the SDL2 libraries are either 64-bit ones *or *
2324 32-bit ones. A 32-bit Python interpreter can't deal with a 64-bit library
2425 and vice versa.
@@ -28,28 +29,34 @@ Using...
2829
2930... the sdl2 API is weird. Why do you use the SDL\_ prefix all the time?
3031
31- The low-level APIs for SDL2, SDL2\_ mixer, SDL2\_ ttf, ... shall represent a
32- clean wrapping around the original C API calls. Thus, if you have to search
33- for documentation or want to make a Python to C conversion (or C to Python),
34- most of the code cleanly maps to the original API naming and layout and you
35- do not have to think about whether you had to use SDL\_ or TTF\_ or whatever
36- as prefix or suffix.
32+ PySDL2 offers 1-to-1 bindings for most of the SDL2 API, keeping the same
33+ function names and arguments as the original SDL2, SDL2\_ mixer, SDL2\_ ttf,
34+ SDL2\_ image, and SDL2\_ gfx libraries. This makes the package much easier to
35+ maintain, but also makes it easy to reference the SDL2 documentation and
36+ adapt C SDL2 examples into Python code. For a friendlier, more Pythonic
37+ wrapper around the SDL2 API, take a look at PySDL2's :mod: `sdl2.ext `
38+ module.
3739
38- ... the sdl2 API is does not comply to PEP-8. Please make it PEP-8 compatible.
40+ ... the sdl2 API does not comply to PEP-8. Please make it PEP-8 compatible.
3941
40- Most of the API is PEP-8 compatible. The low-level bindings to SDL2 and
41- related libraries however use the exact naming (including capital letters)
42- as the functions or structures, they map to. See the previous entry for
43- the reason of that.
42+ Most of the API is PEP-8 compatible. However, the low-level bindings to SDL2
43+ and its addon libraries use the exact same function/structure/constant naming
44+ as their C counterparts, meaning that PySDL2 will necessarily diverge from
45+ PEP-8 in some places. The :mod: `sdl2.ext ` module should theoretically be
46+ fully PEP-8 compliant.
4447
4548How do I...
4649-----------
4750
4851... save my surfaces as image files?
4952
50- You can use :func: `sdl2.SDL_SaveBMP() ` to save them as bitmap files. Other
51- formats are currently unsupported, but might be added to
52- the :mod: `sdl2.ext ` package in the future.
53+ You can use :func: `sdl2.ext.save_bmp() ` to save them as bitmap files, or the
54+ low-level :func: `sdl2.sdlimage.IMG_SavePNG() ` function to save them to PNG on
55+ systems with SDL\_ image installed. For a wider range of formats, you can use
56+ the :func: `~sdl2.ext.surface_to_ndarray ` function to convert an SDL surface
57+ into a Numpy array, open the array with the Pillow library using
58+ ``Image.from_array() ``, and then save it to any export format supported by
59+ Pillow.
5360
5461
5562Font handling...
@@ -59,10 +66,7 @@ Font handling...
5966
6067 The :mod: `sdl2.sdlttf ` API does not know about platform-specific font
6168 locations and is unable to resolve font paths based on e.g. the font name
62- or typeface. It's not its job and PySDL2 likewise does not provide such
63- functionality. If you need improved font detection support, you might want
64- to take a look at the sysfont module of the python-utils project, which can
65- be found at https://bitbucket.org/marcusva/python-utils/. That said, it's
66- usually a bad idea for a projects to rely on system fonts that may not be
67- available on every computer: finding a free-use font you like and bundling
68- it with your code is much safer.
69+ or typeface. Additionally, it's usually a bad idea for a projects to rely
70+ on system fonts that may not be available on every computer: finding a
71+ free-use font you like and bundling it with your project is almost always
72+ the better option.
0 commit comments