~pygame/pygame/trunk

« back to all changes in this revision

Viewing changes to docs/reST/ref/display.rst

  • Committer: pygame
  • Date: 2017-01-10 00:31:42 UTC
  • Revision ID: git-v1:2eea4f299a2e791f884608d7ed601558634af73c
commit 1639c41a8cb3433046882ede92c80ce69d59016b
Author: Thomas Kluyver <takowl@gmail.com>
Date:   Sun Jan 8 18:46:46 2017 +0000

    Build newer versions of libogg and libvorbis into Linux base images

    Closes #317
    Closes #323

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.. include:: common.txt
 
2
 
 
3
:mod:`pygame.display`
 
4
=====================
 
5
 
 
6
.. module:: pygame.display
 
7
   :synopsis: pygame module to control the display window and screen
 
8
 
 
9
| :sl:`pygame module to control the display window and screen`
 
10
 
 
11
This module offers control over the pygame display. Pygame has a single display
 
12
Surface that is either contained in a window or runs full screen. Once you
 
13
create the display you treat it as a regular Surface. Changes are not
 
14
immediately visible onscreen; you must choose one of the two flipping functions
 
15
to update the actual display.
 
16
 
 
17
The origin of the display, where x = 0 and y = 0, is the top left of the
 
18
screen. Both axes increase positively towards the bottom right of the screen.
 
19
 
 
20
The pygame display can actually be initialized in one of several modes. By
 
21
default, the display is a basic software driven framebuffer. You can request
 
22
special modules like hardware acceleration and OpenGL support. These are
 
23
controlled by flags passed to ``pygame.display.set_mode()``.
 
24
 
 
25
Pygame can only have a single display active at any time. Creating a new one
 
26
with ``pygame.display.set_mode()`` will close the previous display. If precise
 
27
control is needed over the pixel format or display resolutions, use the
 
28
functions ``pygame.display.mode_ok()``, ``pygame.display.list_modes()``, and
 
29
``pygame.display.Info()`` to query information about the display.
 
30
 
 
31
Once the display Surface is created, the functions from this module affect the
 
32
single existing display. The Surface becomes invalid if the module is
 
33
uninitialized. If a new display mode is set, the existing Surface will
 
34
automatically switch to operate on the new display.
 
35
 
 
36
When the display mode is set, several events are placed on the pygame event
 
37
queue. ``pygame.QUIT`` is sent when the user has requested the program to
 
38
shutdown. The window will receive ``pygame.ACTIVEEVENT`` events as the display
 
39
gains and loses input focus. If the display is set with the
 
40
``pygame.RESIZABLE`` flag, ``pygame.VIDEORESIZE`` events will be sent when the
 
41
user adjusts the window dimensions. Hardware displays that draw direct to the
 
42
screen will get ``pygame.VIDEOEXPOSE`` events when portions of the window must
 
43
be redrawn.
 
44
 
 
45
Some display environments have an option for automatically stretching all
 
46
windows. When this option is enabled, this automatic stretching distorts the
 
47
appearance of the pygame window. In the pygame examples directory, there is
 
48
example code (prevent_display_stretching.py) which shows how to disable this
 
49
automatic stretching of the pygame display on Microsoft Windows (Vista or newer
 
50
required).
 
51
 
 
52
.. function:: init
 
53
 
 
54
   | :sl:`Initialize the display module`
 
55
   | :sg:`init() -> None`
 
56
 
 
57
   Initializes the pygame display module. The display module cannot do anything
 
58
   until it is initialized. This is usually handled for you automatically when
 
59
   you call the higher level ``pygame.init()``.
 
60
 
 
61
   Pygame will select from one of several internal display backends when it is
 
62
   initialized. The display mode will be chosen depending on the platform and
 
63
   permissions of current user. Before the display module is initialized the
 
64
   environment variable ``SDL_VIDEODRIVER`` can be set to control which backend
 
65
   is used. The systems with multiple choices are listed here.
 
66
 
 
67
   ::
 
68
 
 
69
      Windows : windib, directx
 
70
      Unix    : x11, dga, fbcon, directfb, ggi, vgl, svgalib, aalib
 
71
 
 
72
   On some platforms it is possible to embed the pygame display into an already
 
73
   existing window. To do this, the environment variable ``SDL_WINDOWID`` must
 
74
   be set to a string containing the window id or handle. The environment
 
75
   variable is checked when the pygame display is initialized. Be aware that
 
76
   there can be many strange side effects when running in an embedded display.
 
77
 
 
78
   It is harmless to call this more than once, repeated calls have no effect.
 
79
 
 
80
   .. ## pygame.display.init ##
 
81
 
 
82
.. function:: quit
 
83
 
 
84
   | :sl:`Uninitialize the display module`
 
85
   | :sg:`quit() -> None`
 
86
 
 
87
   This will shut down the entire display module. This means any active
 
88
   displays will be closed. This will also be handled automatically when the
 
89
   program exits.
 
90
 
 
91
   It is harmless to call this more than once, repeated calls have no effect.
 
92
 
 
93
   .. ## pygame.display.quit ##
 
94
 
 
95
.. function:: get_init
 
96
 
 
97
   | :sl:`Returns True if the display module has been initialized`
 
98
   | :sg:`get_init() -> bool`
 
99
 
 
100
   Returns True if the :mod:`pygame.display` module is currently initialized.
 
101
 
 
102
   .. ## pygame.display.get_init ##
 
103
 
 
104
.. function:: set_mode
 
105
 
 
106
   | :sl:`Initialize a window or screen for display`
 
107
   | :sg:`set_mode(resolution=(0,0), flags=0, depth=0) -> Surface`
 
108
 
 
109
   This function will create a display Surface. The arguments passed in are
 
110
   requests for a display type. The actual created display will be the best
 
111
   possible match supported by the system.
 
112
 
 
113
   The resolution argument is a pair of numbers representing the width and
 
114
   height. The flags argument is a collection of additional options. The depth
 
115
   argument represents the number of bits to use for color.
 
116
 
 
117
   The Surface that gets returned can be drawn to like a regular Surface but
 
118
   changes will eventually be seen on the monitor.
 
119
 
 
120
   If no resolution is passed or is set to (0, 0) and pygame uses ``SDL``
 
121
   version 1.2.10 or above, the created Surface will have the same size as the
 
122
   current screen resolution. If only the width or height are set to 0, the
 
123
   Surface will have the same width or height as the screen resolution. Using a
 
124
   ``SDL`` version prior to 1.2.10 will raise an exception.
 
125
 
 
126
   It is usually best to not pass the depth argument. It will default to the
 
127
   best and fastest color depth for the system. If your game requires a
 
128
   specific color format you can control the depth with this argument. Pygame
 
129
   will emulate an unavailable color depth which can be slow.
 
130
 
 
131
   When requesting fullscreen display modes, sometimes an exact match for the
 
132
   requested resolution cannot be made. In these situations pygame will select
 
133
   the closest compatible match. The returned surface will still always match
 
134
   the requested resolution.
 
135
 
 
136
   The flags argument controls which type of display you want. There are
 
137
   several to choose from, and you can even combine multiple types using the
 
138
   bitwise or operator, (the pipe "|" character). If you pass 0 or no flags
 
139
   argument it will default to a software driven window. Here are the display
 
140
   flags you will want to choose from:
 
141
 
 
142
   ::
 
143
 
 
144
      pygame.FULLSCREEN    create a fullscreen display
 
145
      pygame.DOUBLEBUF     recommended for HWSURFACE or OPENGL
 
146
      pygame.HWSURFACE     hardware accelerated, only in FULLSCREEN
 
147
      pygame.OPENGL        create an OpenGL renderable display
 
148
      pygame.RESIZABLE     display window should be sizeable
 
149
      pygame.NOFRAME       display window will have no border or controls
 
150
 
 
151
   For example:
 
152
    
 
153
   ::
 
154
    
 
155
        # Open a window on the screen
 
156
        screen_width=700
 
157
        screen_height=400
 
158
        screen=pygame.display.set_mode([screen_width,screen_height])
 
159
    
 
160
   .. ## pygame.display.set_mode ##
 
161
 
 
162
.. function:: get_surface
 
163
 
 
164
   | :sl:`Get a reference to the currently set display surface`
 
165
   | :sg:`get_surface() -> Surface`
 
166
 
 
167
   Return a reference to the currently set display Surface. If no display mode
 
168
   has been set this will return None.
 
169
 
 
170
   .. ## pygame.display.get_surface ##
 
171
 
 
172
.. function:: flip
 
173
 
 
174
   | :sl:`Update the full display Surface to the screen`
 
175
   | :sg:`flip() -> None`
 
176
 
 
177
   This will update the contents of the entire display. If your display mode is
 
178
   using the flags ``pygame.HWSURFACE`` and ``pygame.DOUBLEBUF``, this will
 
179
   wait for a vertical retrace and swap the surfaces. If you are using a
 
180
   different type of display mode, it will simply update the entire contents of
 
181
   the surface.
 
182
 
 
183
   When using an ``pygame.OPENGL`` display mode this will perform a gl buffer
 
184
   swap.
 
185
 
 
186
   .. ## pygame.display.flip ##
 
187
 
 
188
.. function:: update
 
189
 
 
190
   | :sl:`Update portions of the screen for software displays`
 
191
   | :sg:`update(rectangle=None) -> None`
 
192
   | :sg:`update(rectangle_list) -> None`
 
193
 
 
194
   This function is like an optimized version of ``pygame.display.flip()`` for
 
195
   software displays. It allows only a portion of the screen to updated,
 
196
   instead of the entire area. If no argument is passed it updates the entire
 
197
   Surface area like ``pygame.display.flip()``.
 
198
 
 
199
   You can pass the function a single rectangle, or a sequence of rectangles.
 
200
   It is more efficient to pass many rectangles at once than to call update
 
201
   multiple times with single or a partial list of rectangles. If passing a
 
202
   sequence of rectangles it is safe to include None values in the list, which
 
203
   will be skipped.
 
204
 
 
205
   This call cannot be used on ``pygame.OPENGL`` displays and will generate an
 
206
   exception.
 
207
 
 
208
   .. ## pygame.display.update ##
 
209
 
 
210
.. function:: get_driver
 
211
 
 
212
   | :sl:`Get the name of the pygame display backend`
 
213
   | :sg:`get_driver() -> name`
 
214
 
 
215
   Pygame chooses one of many available display backends when it is
 
216
   initialized. This returns the internal name used for the display backend.
 
217
   This can be used to provide limited information about what display
 
218
   capabilities might be accelerated. See the ``SDL_VIDEODRIVER`` flags in
 
219
   ``pygame.display.set_mode()`` to see some of the common options.
 
220
 
 
221
   .. ## pygame.display.get_driver ##
 
222
 
 
223
.. function:: Info
 
224
 
 
225
   | :sl:`Create a video display information object`
 
226
   | :sg:`Info() -> VideoInfo`
 
227
 
 
228
   Creates a simple object containing several attributes to describe the
 
229
   current graphics environment. If this is called before
 
230
   ``pygame.display.set_mode()`` some platforms can provide information about
 
231
   the default display mode. This can also be called after setting the display
 
232
   mode to verify specific display options were satisfied. The VidInfo object
 
233
   has several attributes:
 
234
 
 
235
   ::
 
236
 
 
237
     hw:         True if the display is hardware accelerated
 
238
     wm:         True if windowed display modes can be used
 
239
     video_mem:  The megabytes of video memory on the display. This is 0 if unknown
 
240
     bitsize:    Number of bits used to store each pixel
 
241
     bytesize:   Number of bytes used to store each pixel
 
242
     masks:      Four values used to pack RGBA values into pixels
 
243
     shifts:     Four values used to pack RGBA values into pixels
 
244
     losses:     Four values used to pack RGBA values into pixels
 
245
     blit_hw:    True if hardware Surface blitting is accelerated
 
246
     blit_hw_CC: True if hardware Surface colorkey blitting is accelerated
 
247
     blit_hw_A:  True if hardware Surface pixel alpha blitting is accelerated
 
248
     blit_sw:    True if software Surface blitting is accelerated
 
249
     blit_sw_CC: True if software Surface colorkey blitting is accelerated
 
250
     blit_sw_A:  True if software Surface pixel alpha blitting is acclerated
 
251
     current_h, current_h:  Width and height of the current video mode, or of the
 
252
       desktop mode if called before the display.set_mode is called.
 
253
       (current_h, current_w are available since SDL 1.2.10, and pygame 1.8.0)
 
254
       They are -1 on error, or if an old SDL is being used.
 
255
 
 
256
   .. ## pygame.display.Info ##
 
257
 
 
258
.. function:: get_wm_info
 
259
 
 
260
   | :sl:`Get information about the current windowing system`
 
261
   | :sg:`get_wm_info() -> dict`
 
262
 
 
263
   Creates a dictionary filled with string keys. The strings and values are
 
264
   arbitrarily created by the system. Some systems may have no information and
 
265
   an empty dictionary will be returned. Most platforms will return a "window"
 
266
   key with the value set to the system id for the current display.
 
267
 
 
268
   New with pygame 1.7.1
 
269
 
 
270
   .. ## pygame.display.get_wm_info ##
 
271
 
 
272
.. function:: list_modes
 
273
 
 
274
   | :sl:`Get list of available fullscreen modes`
 
275
   | :sg:`list_modes(depth=0, flags=pygame.FULLSCREEN) -> list`
 
276
 
 
277
   This function returns a list of possible dimensions for a specified color
 
278
   depth. The return value will be an empty list if no display modes are
 
279
   available with the given arguments. A return value of -1 means that any
 
280
   requested resolution should work (this is likely the case for windowed
 
281
   modes). Mode sizes are sorted from biggest to smallest.
 
282
 
 
283
   If depth is 0, ``SDL`` will choose the current/best color depth for the
 
284
   display. The flags defaults to ``pygame.FULLSCREEN``, but you may need to
 
285
   add additional flags for specific fullscreen modes.
 
286
 
 
287
   .. ## pygame.display.list_modes ##
 
288
 
 
289
.. function:: mode_ok
 
290
 
 
291
   | :sl:`Pick the best color depth for a display mode`
 
292
   | :sg:`mode_ok(size, flags=0, depth=0) -> depth`
 
293
 
 
294
   This function uses the same arguments as ``pygame.display.set_mode()``. It
 
295
   is used to determine if a requested display mode is available. It will
 
296
   return 0 if the display mode cannot be set. Otherwise it will return a pixel
 
297
   depth that best matches the display asked for.
 
298
 
 
299
   Usually the depth argument is not passed, but some platforms can support
 
300
   multiple display depths. If passed it will hint to which depth is a better
 
301
   match.
 
302
 
 
303
   The most useful flags to pass will be ``pygame.HWSURFACE``,
 
304
   ``pygame.DOUBLEBUF``, and maybe ``pygame.FULLSCREEN``. The function will
 
305
   return 0 if these display flags cannot be set.
 
306
 
 
307
   .. ## pygame.display.mode_ok ##
 
308
 
 
309
.. function:: gl_get_attribute
 
310
 
 
311
   | :sl:`Get the value for an OpenGL flag for the current display`
 
312
   | :sg:`gl_get_attribute(flag) -> value`
 
313
 
 
314
   After calling ``pygame.display.set_mode()`` with the ``pygame.OPENGL`` flag,
 
315
   it is a good idea to check the value of any requested OpenGL attributes. See
 
316
   ``pygame.display.gl_set_attribute()`` for a list of valid flags.
 
317
 
 
318
   .. ## pygame.display.gl_get_attribute ##
 
319
 
 
320
.. function:: gl_set_attribute
 
321
 
 
322
   | :sl:`Request an OpenGL display attribute for the display mode`
 
323
   | :sg:`gl_set_attribute(flag, value) -> None`
 
324
 
 
325
   When calling ``pygame.display.set_mode()`` with the ``pygame.OPENGL`` flag,
 
326
   Pygame automatically handles setting the OpenGL attributes like color and
 
327
   doublebuffering. OpenGL offers several other attributes you may want control
 
328
   over. Pass one of these attributes as the flag, and its appropriate value.
 
329
   This must be called before ``pygame.display.set_mode()``
 
330
 
 
331
   The ``OPENGL`` flags are;
 
332
 
 
333
   ::
 
334
 
 
335
     GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_ACCUM_RED_SIZE,
 
336
     GL_ACCUM_GREEN_SIZE,  GL_ACCUM_BLUE_SIZE, GL_ACCUM_ALPHA_SIZE,
 
337
     GL_MULTISAMPLEBUFFERS, GL_MULTISAMPLESAMPLES, GL_STEREO
 
338
 
 
339
   .. ## pygame.display.gl_set_attribute ##
 
340
 
 
341
.. function:: get_active
 
342
 
 
343
   | :sl:`Returns True when the display is active on the display`
 
344
   | :sg:`get_active() -> bool`
 
345
 
 
346
   After ``pygame.display.set_mode()`` is called the display Surface will be
 
347
   visible on the screen. Most windowed displays can be hidden by the user. If
 
348
   the display Surface is hidden or iconified this will return False.
 
349
 
 
350
   .. ## pygame.display.get_active ##
 
351
 
 
352
.. function:: iconify
 
353
 
 
354
   | :sl:`Iconify the display surface`
 
355
   | :sg:`iconify() -> bool`
 
356
 
 
357
   Request the window for the display surface be iconified or hidden. Not all
 
358
   systems and displays support an iconified display. The function will return
 
359
   True if successful.
 
360
 
 
361
   When the display is iconified ``pygame.display.get_active()`` will return
 
362
   False. The event queue should receive a ``ACTIVEEVENT`` event when the
 
363
   window has been iconified.
 
364
 
 
365
   .. ## pygame.display.iconify ##
 
366
 
 
367
.. function:: toggle_fullscreen
 
368
 
 
369
   | :sl:`Switch between fullscreen and windowed displays`
 
370
   | :sg:`toggle_fullscreen() -> bool`
 
371
 
 
372
   Switches the display window between windowed and fullscreen modes. This
 
373
   function only works under the unix x11 video driver. For most situations it
 
374
   is better to call ``pygame.display.set_mode()`` with new display flags.
 
375
 
 
376
   .. ## pygame.display.toggle_fullscreen ##
 
377
 
 
378
.. function:: set_gamma
 
379
 
 
380
   | :sl:`Change the hardware gamma ramps`
 
381
   | :sg:`set_gamma(red, green=None, blue=None) -> bool`
 
382
 
 
383
   Set the red, green, and blue gamma values on the display hardware. If the
 
384
   green and blue arguments are not passed, they will both be the same as red.
 
385
   Not all systems and hardware support gamma ramps, if the function succeeds
 
386
   it will return True.
 
387
 
 
388
   A gamma value of 1.0 creates a linear color table. Lower values will darken
 
389
   the display and higher values will brighten.
 
390
 
 
391
   .. ## pygame.display.set_gamma ##
 
392
 
 
393
.. function:: set_gamma_ramp
 
394
 
 
395
   | :sl:`Change the hardware gamma ramps with a custom lookup`
 
396
   | :sg:`set_gamma_ramp(red, green, blue) -> bool`
 
397
 
 
398
   Set the red, green, and blue gamma ramps with an explicit lookup table. Each
 
399
   argument should be sequence of 256 integers. The integers should range
 
400
   between 0 and 0xffff. Not all systems and hardware support gamma ramps, if
 
401
   the function succeeds it will return True.
 
402
 
 
403
   .. ## pygame.display.set_gamma_ramp ##
 
404
 
 
405
.. function:: set_icon
 
406
 
 
407
   | :sl:`Change the system image for the display window`
 
408
   | :sg:`set_icon(Surface) -> None`
 
409
 
 
410
   Sets the runtime icon the system will use to represent the display window.
 
411
   All windows default to a simple pygame logo for the window icon.
 
412
 
 
413
   You can pass any surface, but most systems want a smaller image around
 
414
   32x32. The image can have colorkey transparency which will be passed to the
 
415
   system.
 
416
 
 
417
   Some systems do not allow the window icon to change after it has been shown.
 
418
   This function can be called before ``pygame.display.set_mode()`` to create
 
419
   the icon before the display mode is set.
 
420
 
 
421
   .. ## pygame.display.set_icon ##
 
422
 
 
423
.. function:: set_caption
 
424
 
 
425
   | :sl:`Set the current window caption`
 
426
   | :sg:`set_caption(title, icontitle=None) -> None`
 
427
 
 
428
   If the display has a window title, this function will change the name on the
 
429
   window. Some systems support an alternate shorter title to be used for
 
430
   minimized displays.
 
431
 
 
432
   .. ## pygame.display.set_caption ##
 
433
 
 
434
.. function:: get_caption
 
435
 
 
436
   | :sl:`Get the current window caption`
 
437
   | :sg:`get_caption() -> (title, icontitle)`
 
438
 
 
439
   Returns the title and icontitle for the display Surface. These will often be
 
440
   the same value.
 
441
 
 
442
   .. ## pygame.display.get_caption ##
 
443
 
 
444
.. function:: set_palette
 
445
 
 
446
   | :sl:`Set the display color palette for indexed displays`
 
447
   | :sg:`set_palette(palette=None) -> None`
 
448
 
 
449
   This will change the video display color palette for 8bit displays. This
 
450
   does not change the palette for the actual display Surface, only the palette
 
451
   that is used to display the Surface. If no palette argument is passed, the
 
452
   system default palette will be restored. The palette is a sequence of
 
453
   ``RGB`` triplets.
 
454
 
 
455
   .. ## pygame.display.set_palette ##
 
456
 
 
457
.. ## pygame.display ##