annotate docs/tut/DisplayModes.html @ 3172:d1b367fc08bc tests-returncode

Use a return code of 1 when the tests fail.
author Thomas Kluyver <takowl@gmail.com>
date Wed, 09 Jan 2013 10:13:57 +0000
parents cdd953a70167
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
1 <!--
89
a4ffbbd1d9c5 tutorial fixes
pygame
parents: 26
diff changeset
2 TUTORIAL:Choosing and Configuring Display Modes
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
3 --><html><head>
764cf3e30779 no message
pygame
parents: 16
diff changeset
4
764cf3e30779 no message
pygame
parents: 16
diff changeset
5 <title>Pygame Tutorials - Setting Display Modes</title>
764cf3e30779 no message
pygame
parents: 16
diff changeset
6 </head><body>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
7
790be231ba1a documentation boost
pygame
parents:
diff changeset
8 <h1 align=center><font size=-1>Pygame Tutorials</font><br>Setting Display Modes</h1>
790be231ba1a documentation boost
pygame
parents:
diff changeset
9 <h2 align=center>by Pete Shinners<br><font size=-1>pete@shinners.org</font></h2>
384
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
10 <h3 align=center>Revision 1.1, May 21, 2002</h3>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
11 <br><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
12
790be231ba1a documentation boost
pygame
parents:
diff changeset
13 <h2>Introduction</h2>
790be231ba1a documentation boost
pygame
parents:
diff changeset
14 Setting the display mode in <i>pygame</i> creates a visible image surface
790be231ba1a documentation boost
pygame
parents:
diff changeset
15 on the monitor. This surface can either cover the full screen, or be windowed
790be231ba1a documentation boost
pygame
parents:
diff changeset
16 on platforms that support a window manager. The display surface is nothing
790be231ba1a documentation boost
pygame
parents:
diff changeset
17 more than a standard <i>pygame</i> surface object. There are special functions
790be231ba1a documentation boost
pygame
parents:
diff changeset
18 needed in the <u>pygame.display</u> module to keep the image surface contents
790be231ba1a documentation boost
pygame
parents:
diff changeset
19 updated on the monitor.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
20 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
21 Setting the display mode in <i>pygame</i> is an easier task than with most
790be231ba1a documentation boost
pygame
parents:
diff changeset
22 graphic libraries. The advantage is if your display mode is not available,
790be231ba1a documentation boost
pygame
parents:
diff changeset
23 <i>pygame</i> will emulate the display mode that you asked for. <i>Pygame</i>
790be231ba1a documentation boost
pygame
parents:
diff changeset
24 will select a display resolution and color depth that best matches the settings
790be231ba1a documentation boost
pygame
parents:
diff changeset
25 you have requested, then allow you to access the display with the format
790be231ba1a documentation boost
pygame
parents:
diff changeset
26 you have requested. In reality, since the <u>pygame.display</u> module is
790be231ba1a documentation boost
pygame
parents:
diff changeset
27 a binding around the SDL library, SDL is really doing all this work.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
28 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
29 There are advantages and disadvantages to setting the display mode in this
790be231ba1a documentation boost
pygame
parents:
diff changeset
30 manner. The advantage is that if your game requires a specific display mode,
790be231ba1a documentation boost
pygame
parents:
diff changeset
31 your game will run on platforms that do not support your requirements. It
790be231ba1a documentation boost
pygame
parents:
diff changeset
32 also makes life easier when your getting something started, it is always easy
790be231ba1a documentation boost
pygame
parents:
diff changeset
33 to go back later and make the mode selection a little more particular. The
790be231ba1a documentation boost
pygame
parents:
diff changeset
34 disadvantage is that what you request is not always what you will get. There
790be231ba1a documentation boost
pygame
parents:
diff changeset
35 is also a performance penalty when the display mode must be emulated. This
790be231ba1a documentation boost
pygame
parents:
diff changeset
36 tutorial will help you understand the different methods for querying the platforms
790be231ba1a documentation boost
pygame
parents:
diff changeset
37 display capabilities, and setting the display mode for your game.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
38 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
39 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
40
790be231ba1a documentation boost
pygame
parents:
diff changeset
41 <h2>Setting Basics</h2>
790be231ba1a documentation boost
pygame
parents:
diff changeset
42 The first thing to learn about is how to actually set the current display
790be231ba1a documentation boost
pygame
parents:
diff changeset
43 mode. The display mode may be set at anytime after the <u>pygame.display</u>
790be231ba1a documentation boost
pygame
parents:
diff changeset
44 module has been initialized. If you have previously set the display mode,
790be231ba1a documentation boost
pygame
parents:
diff changeset
45 setting it again will change the current mode. Setting the display mode is
384
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
46 handled with the function <u><tt>pygame.display.set_mode((width, height), flags, depth)</tt></u>.
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
47 The only required argument in this function is a sequence containing
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
48 the width and height of the new display mode. The depth flag is the requested
790be231ba1a documentation boost
pygame
parents:
diff changeset
49 bits per pixel for the surface. If the given depth is 8, <i>pygame</i> will
790be231ba1a documentation boost
pygame
parents:
diff changeset
50 create a color-mapped surface. When given a higher bit depth, <i>pygame</i>
790be231ba1a documentation boost
pygame
parents:
diff changeset
51 will use a packed color mode. Much more information about depths and color
790be231ba1a documentation boost
pygame
parents:
diff changeset
52 modes can be found in the documentation for the display and surface modules.
790be231ba1a documentation boost
pygame
parents:
diff changeset
53 The default value for depth is 0. When given an argument of 0, <i>pygame</i>
790be231ba1a documentation boost
pygame
parents:
diff changeset
54 will select the best bit depth to use, usually the same as the system's
790be231ba1a documentation boost
pygame
parents:
diff changeset
55 current bit depth. The flags argument lets you control extra features for
790be231ba1a documentation boost
pygame
parents:
diff changeset
56 the display mode. You can create the display surface in hardware memory with
790be231ba1a documentation boost
pygame
parents:
diff changeset
57 the HWSURFACE flag. Again, more information about this is found in the <i>
790be231ba1a documentation boost
pygame
parents:
diff changeset
58 pygame</i> reference documents.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
59 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
60 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
61
790be231ba1a documentation boost
pygame
parents:
diff changeset
62 <h2>How to Decide</h2>
790be231ba1a documentation boost
pygame
parents:
diff changeset
63 So how do you select a display mode that is going to work best with your
790be231ba1a documentation boost
pygame
parents:
diff changeset
64 graphic resources and the platform your game is running on? There are several
790be231ba1a documentation boost
pygame
parents:
diff changeset
65 methods for gathering information about the display device. All of these methods
790be231ba1a documentation boost
pygame
parents:
diff changeset
66 must be called after the display module has been initialized, but you likely
790be231ba1a documentation boost
pygame
parents:
diff changeset
67 want to call them before setting the display mode. First, <u><tt>pygame.display.get_info()</tt></u>
790be231ba1a documentation boost
pygame
parents:
diff changeset
68 will return a special object type of VidInfo, which can tell you a lot about
790be231ba1a documentation boost
pygame
parents:
diff changeset
69 the graphics driver capabilities. The function <u><tt>pygame.display.list_modes(depth,
790be231ba1a documentation boost
pygame
parents:
diff changeset
70 flags)</tt></u> can be used to find the supported graphic modes by the system.
384
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
71 <u><tt>Pygame.display.mode_ok((width, height), flags, depth)</tt></u> takes the same
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
72 arguments as <u><tt>set_mode()</tt></u>, but returns the closest matching bit depth
790be231ba1a documentation boost
pygame
parents:
diff changeset
73 to the one you request. Lastly, <u><tt>pygame.display.get_driver()</tt></u> will return
790be231ba1a documentation boost
pygame
parents:
diff changeset
74 the name of the graphics driver selected by <i>pygame</i>.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
75 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
76 Just remember the golden rule. <i>Pygame</i> will work with pretty much
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
77 any display mode you request. Some display modes will need to be emulated,
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
78 which will slow your game down, since <i>pygame</i> will need to convert
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
79 every update you make to the "real" display mode. The best bet is to
764cf3e30779 no message
pygame
parents: 16
diff changeset
80 always let <i>pygame</i> choose the best bit depth, and convert all
764cf3e30779 no message
pygame
parents: 16
diff changeset
81 your graphic resources to that format when they are loaded. You let
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
82 <i>pygame</i> choose it's bit depth by calling set_mode() with no depth argument
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
83 or a depth of 0, or you can call mode_ok() to find a closest matching
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
84 bit depth to what you need.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
85 <br>
384
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
86 When your display mode is windowed, you usually must math the same
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
87 bit depth as the desktop. When you are fullscreen, some platforms can switch
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
88 to any bit depth that best suits your needs. You can find the depth of the
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
89 current desktop if you get a VidInfo object before ever setting your display
764cf3e30779 no message
pygame
parents: 16
diff changeset
90 mode.<br>
764cf3e30779 no message
pygame
parents: 16
diff changeset
91 <br>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
92 After setting the display mode, you can find out information about it's
384
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
93 settings by getting a VidInfo object, or by calling any of the Surface.get*
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
94 methods on the display surface.<br>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
95 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
96 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
97
790be231ba1a documentation boost
pygame
parents:
diff changeset
98 <h2>Functions</h2>
790be231ba1a documentation boost
pygame
parents:
diff changeset
99 These are the routines you can use to determine the most appropriate display
790be231ba1a documentation boost
pygame
parents:
diff changeset
100 mode. You can find more information about these functions in the display module
790be231ba1a documentation boost
pygame
parents:
diff changeset
101 documentation. <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
102 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
103
384
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
104 <blockquote><u><tt>pygame.display.mode_ok(size, flags, depth)</tt></u><br>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
105
790be231ba1a documentation boost
pygame
parents:
diff changeset
106 <blockquote> This function takes the exact same arguments as pygame.display.set_mode().
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
107 It returns the best available bit depth for the mode you have described.
764cf3e30779 no message
pygame
parents: 16
diff changeset
108 If this returns zero, then the desired display mode is not available
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
109 without emulation.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
110 </blockquote>
790be231ba1a documentation boost
pygame
parents:
diff changeset
111 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
112 <u><tt>pygame.display.list_modes(depth, flags)</tt></u><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
113
790be231ba1a documentation boost
pygame
parents:
diff changeset
114 <blockquote> Returns a list of supported display modes with the requested
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
115 depth and flags. An empty list is returned when there are no modes.
764cf3e30779 no message
pygame
parents: 16
diff changeset
116 The flags argument defaults to FULLSCREEN. If you specify your own flags
764cf3e30779 no message
pygame
parents: 16
diff changeset
117 without FULLSCREEN, you will likely get a return value of -1. This
764cf3e30779 no message
pygame
parents: 16
diff changeset
118 means that any display size is fine, since the display will be windowed. Note
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
119 that the listed modes are sorted largest to smallest.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
120 </blockquote>
790be231ba1a documentation boost
pygame
parents:
diff changeset
121 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
122 <u><tt>pygame.display.get_info()</tt></u><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
123
790be231ba1a documentation boost
pygame
parents:
diff changeset
124 <blockquote> This function returns an object with many members describing
790be231ba1a documentation boost
pygame
parents:
diff changeset
125 the display devic. Printing the VidInfo object will quickly show you all the
790be231ba1a documentation boost
pygame
parents:
diff changeset
126 members and values for this object. <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
127
790be231ba1a documentation boost
pygame
parents:
diff changeset
128 <blockquote><tt> &gt;&gt;&gt; <b>import pygame.display</b><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
129 &gt;&gt;&gt; <b>pygame.display.init()</b><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
130 &gt;&gt;&gt; <b>info = pygame.display.get_info()</b><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
131 &gt;&gt;&gt; <b>print info</b><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
132 &lt;VideoInfo(hw = 1, wm = 1,video_mem = 27354<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
133 blit_hw = 1, blit_hw_CC = 1, blit_hw_A = 0,<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
134 blit_sw = 1, blit_sw_CC = 1, blit_sw_A = 0,<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
135 bitsize = 32, bytesize = 4,<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
136 masks = (16711680, 65280, 255, 0),<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
137 shifts = (16, 8, 0, 0),<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
138 losses = (0, 0, 0, 8)&gt;</tt><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
139 </blockquote>
790be231ba1a documentation boost
pygame
parents:
diff changeset
140 You can test all these flags as simply members of the VidInfo object. The
790be231ba1a documentation boost
pygame
parents:
diff changeset
141 different blit flags tell if hardware acceleration is supported when blitting
790be231ba1a documentation boost
pygame
parents:
diff changeset
142 from the various types of surfaces to a hardware surface.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
143 </blockquote>
790be231ba1a documentation boost
pygame
parents:
diff changeset
144 </blockquote>
790be231ba1a documentation boost
pygame
parents:
diff changeset
145 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
146 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
147
790be231ba1a documentation boost
pygame
parents:
diff changeset
148 <h2>Examples</h2>
790be231ba1a documentation boost
pygame
parents:
diff changeset
149 Here are some examples of different methods to init the graphics display.
790be231ba1a documentation boost
pygame
parents:
diff changeset
150 They should help you get an idea of how to go about setting your display mode.<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
151 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
152
790be231ba1a documentation boost
pygame
parents:
diff changeset
153 <blockquote><tt> &gt;&gt;&gt; #give me the best depth with a 640
790be231ba1a documentation boost
pygame
parents:
diff changeset
154 x 480 windowed display<br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
155 &gt;&gt;&gt; <b>pygame.display.set_mode((640, 480))</b><br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
156 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
157 &gt;&gt;&gt; #give me the biggest 16bit display available<br>
384
f4e6726b7d1d docs updates
pygame
parents: 89
diff changeset
158 &gt;&gt;&gt; <b>modes = pygame.display.list_modes(16)</b><br>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
159 &gt;&gt;&gt; <b>if not modes:</b><br>
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
160 ... <b>&nbsp;&nbsp;&nbsp;&nbsp;print '16bit not supported'</b><br>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
161 ... <b>else:</b><br>
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
162 ... <b>&nbsp;&nbsp;&nbsp;&nbsp;print 'Found Resolution:', modes[0]</b><br>
897
cdd953a70167 typo - fix from Jens Rantil
brian
parents: 412
diff changeset
163 ... <b>&nbsp;&nbsp;&nbsp;&nbsp;pygame.display.set_mode(modes[0], FULLSCREEN, 16)</b><br>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
164 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
165 &gt;&gt;&gt; #need an 8bit surface, nothing else will do<br>
412
8ff8a2a75512 docs update
pygame
parents: 384
diff changeset
166 &gt;&gt;&gt; <b>if pygame.display.mode_ok((800, 600), 0, 8) != 8:</b><br>
19
764cf3e30779 no message
pygame
parents: 16
diff changeset
167 ... <b>&nbsp;&nbsp;&nbsp;&nbsp;print 'Can only work with an 8bit display, sorry'</b><br>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
168 ... <b>else:</b><br>
412
8ff8a2a75512 docs update
pygame
parents: 384
diff changeset
169 ... <b>&nbsp;&nbsp;&nbsp;&nbsp;pygame.display.set_mode((800, 600), 0, 8)</b><br>
16
790be231ba1a documentation boost
pygame
parents:
diff changeset
170 <br>
790be231ba1a documentation boost
pygame
parents:
diff changeset
171 </tt></blockquote>
790be231ba1a documentation boost
pygame
parents:
diff changeset
172
790be231ba1a documentation boost
pygame
parents:
diff changeset
173 </body>
790be231ba1a documentation boost
pygame
parents:
diff changeset
174 </html>