File: pygamers.rst

package info (click to toggle)
pysdl2 0.9.7%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,824 kB
  • sloc: python: 17,244; makefile: 195; sh: 32
file content (374 lines) | stat: -rw-r--r-- 16,386 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
PySDL2 for Pygamers
===================

Care to move to a newer SDL with your Pygame knowledge? Then you should
know one thing or two about PySDL2 before hacking code, since it is
completely different from Pygame. Do not let that fact scare you away,
the basics with graphics and sound are still the same (as they are
fundamental), but you will not find many similarities to the Pygame API
within PySDL2.

.. todo::

   More details, examples, etc.

Technical differences
---------------------
Pygame is implemented as a mixture of Python, C and Assembler code,
wrapping 3rd party libraries with CPython API interfaces. PySDL2 in
contrast is written in pure Python, using :mod:`ctypes` to interface
with the C interfaces of 3rd party libraries.

API differences
---------------

.. _pygamers_pygame:

pygame
^^^^^^
======================= =================================================
pygame                  sdl2
======================= =================================================
``init()``              :func:`sdl2.SDL_Init()` where appropriate
``quit()``              :func:`sdl2.SDL_Quit()` where appropriate
``error``               No equivalent
``get_error()``         :func:`sdl2.SDL_GetError()`
``set_error()``         :func:`sdl2.SDL_SetError()`
``get_sdl_version()``   :func:`sdl2.SDL_GetVersion()`
``get_sdl_byteorder()`` :data:`sdl2.SDL_BYTEORDER`
``register_quit()``     No equivalent planned
``encode_string()``     No equivalent planned
``encode_file_path()``  No equivalent planned
======================= =================================================

:func:`sdl2.ext.init()` initializes only the video subsystem. By comparison,
:func:`pygame.init()` initializes all Pygame submodules (which includes
initializing other SDL subsystems).

pygame.cdrom
^^^^^^^^^^^^
PySDL2 does not feature any CD-ROM related interfaces. They were
removed in SDL2 and PySDL2 does not provide its own facilities.

pygame.Color
^^^^^^^^^^^^
You can find a similar class in :class:`sdl2.ext.Color`. It does
not feature a ``set_length()`` or ``correct_gamma()`` method, though.

pygame.cursors
^^^^^^^^^^^^^^
PySDL2 does not feature any pre-defined cursor settings at the moment.

pygame.display
^^^^^^^^^^^^^^
======================= =================================================
pygame.display          sdl2
======================= =================================================
``init()``              :func:`sdl2.ext.init()`
``quit()``              :func:`sdl2.ext.quit()`
``get_init()``          :func:`sdl2.SDL_WasInit()`
``set_mode()``          :class:`sdl2.ext.Window`
``get_surface()``       :meth:`sdl2.ext.Window.get_surface()`
``flip()``              :meth:`sdl2.ext.Window.refresh()`
``update()``            :meth:`sdl2.ext.Window.refresh()`
``get_driver()``        :func:`sdl2.SDL_GetCurrentVideoDriver()`
``Info``                No equivalent
``get_wm_info()``       :func:`sdl2.SDL_GetWindowWMInfo()`
``list_modes()``        :func:`sdl2.SDL_GetNumDisplayModes()`
``mode_ok()``           :func:`sdl2.SDL_GetClosestDisplayMode()`
``gl_get_attribute()``  :func:`sdl2.SDL_GL_GetAttribute()`
``gl_set_attribute()``  :func:`sdl2.SDL_GL_SetAttribute()`
``get_active()``        No equivalent
``iconify()``           :meth:`sdl2.ext.Window.minimize()`
``toggle_fullscreen()`` :func:`sdl2.SDL_SetWindowFullscreen()`
``set_gamma()``         :func:`sdl2.SDL_SetWindowBrightness()`
``set_gamma_ramp()``    :func:`sdl2.SDL_SetWindowGammaRamp.()`
``set_icon()``          :func:`sdl2.SDL_SetWindowIcon()`
``set_caption()``       :attr:`sdl2.ext.Window.title`
``get_caption()``       :attr:`sdl2.ext.Window.title`
``set_palette()``       :func:`sdl2.SDL_SetSurfacePalette()`
======================= =================================================

pygame.draw
^^^^^^^^^^^
Drawing primitives can be accessed through either the
``sdl2.SDL_RenderDraw*()`` and ``sdl2.SDL_RenderFill*()`` functions or
the more powerful :mod:`sdl2.sdlgfx` module,

pygame.event
^^^^^^^^^^^^
================= =================================================
pygame.event      sdl2
================= =================================================
``pump()``        :func:`sdl2.SDL_PumpEvents()`
``get()``         :func:`sdl2.SDL_PollEvent()` or :func:`sdl2.ext.get_events()`
``poll()``        :func:`sdl2.SDL_PollEvent()`
``wait()``        :func:`sdl2.SDL_WaitEvent()`
``peek()``        :func:`sdl2.SDL_PeepEvents()`
``clear()``       :func:`sdl2.SDL_FlushEvents()`
``event_name()``  No equivalent
``set_blocked()`` :func:`sdl2.SDL_EventState()`
``get_blocked()`` :func:`sdl2.SDL_EventState()`
``set_allowed()`` :func:`sdl2.SDL_EventState()`
``set_grab()``    :func:`sdl2.SDL_SetWindowGrab()`
``get_grab()``    :func:`sdl2.SDL_GetWindowGrab()`
``post()``        :func:`sdl2.SDL_PeepEvents()`
``Event``         :class:`sdl2.SDL_Event`
================= =================================================

pygame.font
^^^^^^^^^^^
====================== =================================================
pygame.font            sdl2
====================== =================================================
``init()``             :func:`sdl2.sdlttf.TTF_Init()`
``quit()``             :func:`sdl2.sdlttf.TTF_Quit()`
``get_init()``         :func:`sdl2.sdlttf.TTF_WasInit()`
``get_default_font()`` No equivalent planned [#f1]_
``get_fonts()``        No equivalent planned [#f1]_
``match_font()``       No equivalent planned [#f1]_
``SysFont``            No equivalent planned [#f1]_
``Font``               No equivalent planned [#f1]_
====================== =================================================

pygame.freetype
^^^^^^^^^^^^^^^
PySDL2 does not feature direct FreeType support.

pygame.gfxdraw
^^^^^^^^^^^^^^
PySDL2 offers SDL_gfx support through the :mod:`sdl2.sdlgfx` module.

pygame.image
^^^^^^^^^^^^
================== =================================================
pygame.image       sdl2
================== =================================================
``load()``         :func:`sdl2.sdlimage.IMG_Load()`,
                   :func:`sdl2.ext.load_image()`
``save()``         :func:`sdl2.surface.SDL_SaveBMP()`,
                   :func:`sdl2.sdlimage.IMG_SavePNG()`
``get_extended()`` :func:`sdl2.sdlimage.IMG_isBMP()` et al.
``tostring()``     No equivalent yet
``fromstring()``   No equivalent yet
``frombuffer()``   No equivalent yet
================== =================================================

pygame.joystick
^^^^^^^^^^^^^^^
================== ========================================================
pygame.joystick    sdl2
================== ========================================================
``init()``         :func:`sdl2.SDL_Init()`
``quit()``         :func:`sdl2.SDL_Quit()`
``get_init()``     :func:`sdl2.SDL_WasInit()`
``get_count()``    :func:`sdl2.joystick.SDL_NumJoysticks()`
``Joystick()``     :class:`sdl2.joystick.SDL_Joystick` and related
                   functions
================== ========================================================

pygame.key
^^^^^^^^^^
================== ========================================================
pygame.key         sdl2
================== ========================================================
``get_focused()``  :func:`sdl2.keyboard.SDL_GetKeyboardFocus()`
``get_pressed()``  :func:`sdl2.keyboard.SDL_GetKeyboardState()`
``get_mods()``     :func:`sdl2.keyboard.SDL_GetModState()`
``set_mods()``     :func:`sdl2.keyboard.SDL_SetModState()`
``set_repeat()``   Based on the OS/WM settings, no equivalent
``get_repeat()``   Based on the OS/WM settings, no equivalent
``name()``         :func:`sdl2.keyboard.SDL_GetKeyName()`
================== ========================================================

pygame.locals
^^^^^^^^^^^^^
Constants in PySDL2 are spread across the different packages and
modules, depending on where they originate from.

pygame.mixer
^^^^^^^^^^^^
====================== ====================================================
pygame.mixer           sdl2
====================== ====================================================
``init()``             :func:`sdl2.sdlmixer.Mix_Init()`
``quit()``             :func:`sdl2.sdlmixer.Mix_Quit()`
``get_init()``         No equivalent planned
``stop()``             :func:`sdl2.sdlmixer.Mix_HaltChannel()`,
                       :func:`sdl2.sdlmixer.Mix_HaltGroup()`,
                       :func:`sdl2.sdlmixer.Mix_HaltMusic()`
``pause()``            :func:`sdl2.sdlmixer.Mix_Pause()`,
                       :func:`sdl2.sdlmixer.Mix_PauseMusic()`
``unpause()``          :func:`sdl2.sdlmixer.Mix_Resume()`,
                       :func:`sdl2.sdlmixer.Mix_ResumeMusic()`
``fadeout()``          :func:`sdl2.sdlmixer.Mix_FadeOutChannel()`,
                       :func:`sdl2.sdlmixer.Mix_FadeOutGroup()`,
                       :func:`sdl2.sdlmixer.Mix_FadeOutMusic()`
``set_num_channels()`` :func:`sdl2.sdlmixer.Mix_AllocateChannels()`
``get_num_channels()`` :func:`sdl2.sdlmixer.Mix_AllocateChannels()`
``set_reserved()``     :func:`sdl2.sdlmixer.Mix_ReserveChannels()`
``find_channel()``     No equivalent planned
``get_busy()``         :func:`sdl2.sdlmixer.Mix_ChannelFinished`
``Sound``              :class:`sdl2.sdlmixer.Mix_Chunk`
``Channel``            No equivalent, use the channel functions instead
====================== ====================================================

pygame.mixer.music
^^^^^^^^^^^^^^^^^^
See `pygame.mixer`_.

pygame.mouse
^^^^^^^^^^^^
================= ====================================================
pygame.mouse      sdl2
================= ====================================================
``get_pressed()`` :func:`sdl2.mouse.SDL_GetMouseState()`
``get_pos()``     :func:`sdl2.mouse.SDL_GetMouseState()`
``get_rel()``     :func:`sdl2.mouse.SDL_GetRelativeMouseState()`
``set_pos()``     :func:`sdl2.mouse.SDL_WarpMouseInWindow()`
``set_visible()`` :func:`sdl2.mouse.SDL_ShowCursor()`
``get_focused()`` :func:`sdl2.mouse.SDL_GetMouseFocus()`
``set_cursor()``  :func:`sdl2.mouse.SDL_GetCursor()`
``get_cursor()``  :func:`sdl2.mouse.SDL_SetCursor()`
================= ====================================================

pygame.movie
^^^^^^^^^^^^
No such module is planned for PySDL2.

pygame.Overlay
^^^^^^^^^^^^^^
You can work with YUV overlays by using the :mod:`sdl2.render` module
with :class:`sdl2.render.SDL_Texture` objects.

pygame.PixelArray
^^^^^^^^^^^^^^^^^
You can access pixel data of sprites and surfaces directly via the
:class:`sdl2.ext.PixelView` class. It does not feature comparison or
extractions methods.

pygame.Rect
^^^^^^^^^^^
No such functionality is available for PySDL2. Rectangles are represented
via :class:`sdl2.rect.SDL_Rect` for low-level SDL2 wrappers or 4-value
tuples.

pygame.scrap
^^^^^^^^^^^^
PySDL2 offers basic text-based clipboard access via the
:mod:`sdl2.clipboard` module. A feature-rich clipboard API as for Pygame
does not exist yet.

pygame.sndarray
^^^^^^^^^^^^^^^
No such module is available for PySDL2 yet.

pygame.sprite
^^^^^^^^^^^^^
PySDL2 uses a different approach of rendering and managing sprite
objects via a component-based system and the :class:`sdl2.ext.Sprite`
class. A sprite module as for Pygame is not planned.

pygame.Surface
^^^^^^^^^^^^^^
======================= =====================================================
pygame.Surface          sdl2
======================= =====================================================
``blit()``              :meth:`sdl2.surface.SDL_BlitSurface()`,
                        :class:`sdl2.ext.SpriteRenderSystem`
``convert()``           :func:`sdl2.surface.SDL_ConvertSurface()`
``convert_alpha()``     :func:`sdl2.surface.SDL_ConvertSurface()`
``copy()``              :func:`sdl2.surface.SDL_ConvertSurface()`
``fill()``              :func:`sdl2.surface.SDL_FillRect()`,
                        :func:`sdl2.surface.SDL_FillRects()`,
                        :func:`sdl2.ext.fill()`
``scroll()``            No equivalent planned
``set_colorkey()``      :func:`sdl2.surface.SDL_SetColorKey()`
``get_colorkey()``      :func:`sdl2.surface.SDL_GetColorKey()`
``set_alpha()``         :func:`sdl2.surface.SDL_SetSurfaceAlphaMod()`
``get_alpha()``         :func:`sdl2.surface.SDL_GetSurfaceAlphaMod()`
``lock()``              :func:`sdl2.surface.SDL_LockSurface()`
``unlock()``            :func:`sdl2.surface.SDL_UnlockSurface()`
``mustlock()``          :func:`sdl2.surface.SDL_MUSTLOCK()`
``get_locked()``        :attr:`sdl2.surface.SDL_Surface.locked`
``get_locks()``         No equivalent planned
``get_at()``            Direct access to the pixels for surfaces can be
                        achieved via the :class:`sdl2.ext.PixelView` class
``set_at()``            Direct access to the pixels for surfaces can be
                        achieved via the :class:`sdl2.ext.PixelView` class
``get_at_mapped()``     No equivalent planned
``get_palette()``       via :attr:`sdl2.surface.SDL_Surface.format` and the
                        :attr:`sdl2.pixels.SDL_PixelFormat.palette`
                        attribute
``get_palette_at()``    ``sdl2.pixels.SDL_Palette.colors[offset]``
``set_palette()``       :func:`sdl2.surface.SDL_SetSurfacePalette()`
``set_palette_at()``    ``sdl2.pixels.SDL_Palette.colors[offset]``
``map_rgb()``           :func:`sdl2.pixels.SDL_MapRGB()`
``unmap_rgb()``         :func:`sdl2.pixels.SDL_GetRGB()`
``set_clip()``          :func:`sdl2.surface.SDL_SetClipRect()`
``get_clip()``          :func:`sdl2.surface.SDL_GetClipRect()`
``subsurface()``        :func:`sdl2.ext.subsurface()`
``get_parent()``        No equivalent yet
``get_abs_parent()``    As for ``get_parent``
``get_offset()``        As for ``get_parent``
``get_abs_offset()``    As for ``get_parent``
``get_size()``          :attr:`sdl2.ext.Sprite.size`,
                        :attr:`sdl2.surface.SDL_Surface.w`,
                        :attr:`sdl2.surface.SDL_Surface.h`
``get_width()``         ``sdl2.ext.Sprite.size[0]``,
                        :attr:`sdl2.surface.SDL_Surface.w`,
``get_height()``        ``sdl2.ext.Sprite.size[1]``,
                        :attr:`sdl2.surface.SDL_Surface.h`
``get_rect()``          No equivalent planned
``get_bitsize()``       :attr:`sdl2.pixels.SDL_PixelFormat.BitsPerPixel`
``get_bytesize()``      :attr:`sdl2.pixels.SDL_PixelFormat.BytesPerPixel`
``get_flags()``         :attr:`sdl2.surface.SDL_Surface.flags`
``get_pitch()``         :attr:`sdl2.surface.SDL_Surface.pitch`
``get_masks()``         :attr:`sdl2.pixels.SDL_PixelFormat.Rmask`, ...
``get_shifts()``        :attr:`sdl2.pixels.SDL_PixelFormat.Rshift`, ...
``get_losses()``        :attr:`sdl2.pixels.SDL_PixelFormat.Rloss`, ...
``get_bounding_rect()`` No equivalent planned
``get_view()``          :class:`sdl2.ext.PixelView`
``get_buffer()``        :class:`sdl2.ext.PixelView` or
                        :attr:`sdl2.surface.SDL_Surface.pixels`
======================= =====================================================

pygame.surfarray
^^^^^^^^^^^^^^^^
2D and 3D pixel access can be achieved via the
:class:`sdl2.ext.PixelView` class in environments without
numpy. Simplified numpy-array creation with direct pixel access (similar
to ``pygame.surfarray.pixels2d()`` and ``pygame.surfarray.pixels3d()``)
is available via :func:`sdl2.ext.pixels2d()` and
:func:`sdl2.ext.pixels3d()`.

pygame.time
^^^^^^^^^^^
=============== =================================================
pygame.time     sdl2
=============== =================================================
``get_ticks()`` :func:`sdl2.timer.SDL_GetTicks()`
``wait()``      :func:`sdl2.timer.SDL_Delay()`
``delay()``     :func:`sdl2.timer.SDL_Delay()`
``Clock``       No equivalent planned
=============== =================================================

pygame.transform
^^^^^^^^^^^^^^^^
The are no transformation helpers in PySDL2 at moment. Those might be
implemented later on via numpy helpers, the Python Imaging Library or
other 3rd party packages.

pygame.version
^^^^^^^^^^^^^^
=============== =================================================
pygame.version  sdl2
=============== =================================================
``ver``         :attr:`sdl2.__version__`
``vernum``      :attr:`sdl2.version_info`
=============== =================================================

.. rubric:: Footnotes

.. [#f1] Check https://bitbucket.org/marcusva/python-utils for an easy
         to use system font detection module