annotate docs/html/guidevideo.html @ 612:0648505b1f8b

Fixed video intitialization problem on Qtopia (thanks David!)
author Sam Lantinga <slouken@libsdl.org>
date Tue, 15 Apr 2003 16:04:31 +0000
parents 55f1f1b3e27d
children 355632dca928
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 <HTML
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 ><HEAD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
3 ><TITLE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4 >Graphics and Video</TITLE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 ><META
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 NAME="GENERATOR"
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.64
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 "><LINK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9 REL="HOME"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 TITLE="SDL Library Documentation"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 HREF="index.html"><LINK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 REL="UP"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 TITLE="SDL Guide"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14 HREF="guide.html"><LINK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 REL="PREVIOUS"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 TITLE="Initializing SDL"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 HREF="guidebasicsinit.html"><LINK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18 REL="NEXT"
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
19 TITLE="Using OpenGL With SDL"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
20 HREF="guidevideoopengl.html"></HEAD
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 ><BODY
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22 CLASS="CHAPTER"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 BGCOLOR="#FFF8DC"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 TEXT="#000000"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 LINK="#0000ee"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 VLINK="#551a8b"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 ALINK="#ff0000"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 ><DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 CLASS="NAVHEADER"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 ><TABLE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 WIDTH="100%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 BORDER="0"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 CELLPADDING="0"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 CELLSPACING="0"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 ><TR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 ><TH
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 COLSPAN="3"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 ALIGN="center"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 >SDL Library Documentation</TH
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 ></TR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 ><TR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 WIDTH="10%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 ALIGN="left"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 VALIGN="bottom"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 ><A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 HREF="guidebasicsinit.html"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 >Prev</A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 ></TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 WIDTH="80%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 ALIGN="center"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 VALIGN="bottom"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 ></TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 WIDTH="10%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 ALIGN="right"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 VALIGN="bottom"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 ><A
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
60 HREF="guidevideoopengl.html"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 >Next</A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 ></TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 ></TR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 ></TABLE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 ><HR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 ALIGN="LEFT"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 WIDTH="100%"></DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 ><DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 CLASS="CHAPTER"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 ><H1
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 ><A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 NAME="GUIDEVIDEO"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 >Chapter 2. Graphics and Video</A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74 ></H1
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 ><DIV
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
76 CLASS="TOC"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
77 ><DL
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
78 ><DT
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
79 ><B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
80 >Table of Contents</B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
81 ></DT
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
82 ><DT
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
83 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
84 HREF="guidevideo.html#GUIDEVIDEOINTRO"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
85 >Introduction to SDL Video</A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
86 ></DT
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
87 ><DT
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
88 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
89 HREF="guidevideoopengl.html"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
90 >Using OpenGL With SDL</A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
91 ></DT
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
92 ></DL
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
93 ></DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
94 ><DIV
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 CLASS="SECT1"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 ><H1
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 CLASS="SECT1"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 ><A
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
99 NAME="GUIDEVIDEOINTRO"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
100 >Introduction to SDL Video</A
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 ></H1
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 ><P
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
103 >Video is probably the most common thing that SDL is used for, and
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
104 so it has the most complete subsystem. Here are a few
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
105 examples to demonstrate the basics.</P
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 ><DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 CLASS="SECT2"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
108 ><H2
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109 CLASS="SECT2"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 ><A
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
111 NAME="AEN68"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
112 >Initializing the Video Display</A
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 ></H2
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114 ><P
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
115 >This is what almost all SDL programs have to do in one way or
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
116 another.</P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
117 ><DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
118 CLASS="EXAMPLE"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
119 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
120 NAME="AEN71"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 ></A
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
122 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
123 ><B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
124 >Example 2-1. Initializing the Video Display</B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
125 ></P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
126 ><PRE
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 CLASS="PROGRAMLISTING"
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
128 > SDL_Surface *screen;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
130 /* Initialize the SDL library */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
131 if( SDL_Init(SDL_INIT_VIDEO) &#60; 0 ) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
132 fprintf(stderr,
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
133 "Couldn't initialize SDL: %s\n", SDL_GetError());
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
134 exit(1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
137 /* Clean up on exit */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
138 atexit(SDL_Quit);
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
139
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 /*
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
141 * Initialize the display in a 640x480 8-bit palettized mode,
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
142 * requesting a software surface
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 */
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
144 screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
145 if ( screen == NULL ) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
146 fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
147 SDL_GetError());
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
148 exit(1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 }</PRE
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
150 ></DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
151 ></DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
152 ><DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
153 CLASS="SECT2"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
154 ><H2
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
155 CLASS="SECT2"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
156 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
157 NAME="AEN74"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
158 >Initializing the Best Video Mode</A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
159 ></H2
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
160 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
161 >If you have a preference for a certain pixel depth but will accept any
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
162 other, use SDL_SetVideoMode with SDL_ANYFORMAT as below. You can also
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
163 use SDL_VideoModeOK() to find the native video mode that is closest to
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
164 the mode you request.</P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
165 ><DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
166 CLASS="EXAMPLE"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
167 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
168 NAME="AEN77"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
169 ></A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
170 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
171 ><B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
172 >Example 2-2. Initializing the Best Video Mode</B
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 ></P
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
174 ><PRE
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
175 CLASS="PROGRAMLISTING"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
176 > /* Have a preference for 8-bit, but accept any depth */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
177 screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE|SDL_ANYFORMAT);
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
178 if ( screen == NULL ) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
179 fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
180 SDL_GetError());
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
181 exit(1);
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
182 }
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
183 printf("Set 640x480 at %d bits-per-pixel mode\n",
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
184 screen-&#62;format-&#62;BitsPerPixel);</PRE
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
185 ></DIV
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 ></DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 ><DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 CLASS="SECT2"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 ><H2
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 CLASS="SECT2"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 ><A
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
192 NAME="AEN80"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
193 >Loading and Displaying a BMP File</A
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 ></H2
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 ><P
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
196 >The following function loads and displays a BMP file given as
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
197 argument, once SDL is initialised and a video mode has been set.</P
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 ><DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 CLASS="EXAMPLE"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 ><A
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
201 NAME="AEN83"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 ></A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 ><P
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 ><B
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
205 >Example 2-3. Loading and Displaying a BMP File</B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
206 ></P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
207 ><PRE
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
208 CLASS="PROGRAMLISTING"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
209 >void display_bmp(char *file_name)
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
210 {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
211 SDL_Surface *image;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
212
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
213 /* Load the BMP file into a surface */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
214 image = SDL_LoadBMP(file_name);
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
215 if (image == NULL) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
216 fprintf(stderr, "Couldn't load %s: %s\n", file_name, SDL_GetError());
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
217 return;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
218 }
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
219
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
220 /*
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
221 * Palettized screen modes will have a default palette (a standard
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
222 * 8*8*4 colour cube), but if the image is palettized as well we can
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
223 * use that palette for a nicer colour matching
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
224 */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
225 if (image-&#62;format-&#62;palette &#38;&#38; screen-&#62;format-&#62;palette) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
226 SDL_SetColors(screen, image-&#62;format-&#62;palette-&#62;colors, 0,
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
227 image-&#62;format-&#62;palette-&#62;ncolors);
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
228 }
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
229
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
230 /* Blit onto the screen surface */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
231 if(SDL_BlitSurface(image, NULL, screen, NULL) &#60; 0)
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
232 fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
233
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
234 SDL_UpdateRect(screen, 0, 0, image-&#62;w, image-&#62;h);
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
235
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
236 /* Free the allocated BMP surface */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
237 SDL_FreeSurface(image);
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
238 }</PRE
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
239 ></DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
240 ></DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
241 ><DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
242 CLASS="SECT2"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
243 ><H2
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
244 CLASS="SECT2"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
245 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
246 NAME="AEN86"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
247 >Drawing Directly to the Display</A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
248 ></H2
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
249 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
250 >The following two functions can be used to get and set single
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
251 pixels of a surface. They are carefully written to work with any depth
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
252 currently supported by SDL. Remember to lock the surface before
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
253 calling them, and to unlock it before calling any other SDL
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
254 functions.</P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
255 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
256 >To convert between pixel values and their red, green, blue
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
257 components, use SDL_GetRGB() and SDL_MapRGB().</P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
258 ><DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
259 CLASS="EXAMPLE"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
260 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
261 NAME="AEN90"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
262 ></A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
263 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
264 ><B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
265 >Example 2-4. getpixel()</B
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 ></P
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 ><PRE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268 CLASS="PROGRAMLISTING"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 >/*
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
270 * Return the pixel value at (x, y)
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
271 * NOTE: The surface must be locked before calling this!
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 */
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
273 Uint32 getpixel(SDL_Surface *surface, int x, int y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 {
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
275 int bpp = surface-&#62;format-&#62;BytesPerPixel;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
276 /* Here p is the address to the pixel we want to retrieve */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
277 Uint8 *p = (Uint8 *)surface-&#62;pixels + y * surface-&#62;pitch + x * bpp;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
278
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
279 switch(bpp) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
280 case 1:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
281 return *p;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
283 case 2:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
284 return *(Uint16 *)p;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
286 case 3:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
287 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
288 return p[0] &#60;&#60; 16 | p[1] &#60;&#60; 8 | p[2];
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
289 else
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
290 return p[0] | p[1] &#60;&#60; 8 | p[2] &#60;&#60; 16;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
291
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
292 case 4:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
293 return *(Uint32 *)p;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
295 default:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
296 return 0; /* shouldn't happen, but avoids warnings */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
297 }
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
298 }</PRE
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
299 ></DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
300 ><DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
301 CLASS="EXAMPLE"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
302 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
303 NAME="AEN93"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
304 ></A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
305 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
306 ><B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
307 >Example 2-5. putpixel()</B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
308 ></P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
309 ><PRE
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
310 CLASS="PROGRAMLISTING"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
311 >/*
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
312 * Set the pixel at (x, y) to the given value
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
313 * NOTE: The surface must be locked before calling this!
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
314 */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
315 void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
316 {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
317 int bpp = surface-&#62;format-&#62;BytesPerPixel;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
318 /* Here p is the address to the pixel we want to set */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
319 Uint8 *p = (Uint8 *)surface-&#62;pixels + y * surface-&#62;pitch + x * bpp;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
320
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
321 switch(bpp) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
322 case 1:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
323 *p = pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 break;
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
325
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
326 case 2:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
327 *(Uint16 *)p = pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 break;
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
329
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
330 case 3:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
331 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
332 p[0] = (pixel &#62;&#62; 16) &#38; 0xff;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
333 p[1] = (pixel &#62;&#62; 8) &#38; 0xff;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
334 p[2] = pixel &#38; 0xff;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
335 } else {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
336 p[0] = pixel &#38; 0xff;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
337 p[1] = (pixel &#62;&#62; 8) &#38; 0xff;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
338 p[2] = (pixel &#62;&#62; 16) &#38; 0xff;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
339 }
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
340 break;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
341
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
342 case 4:
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
343 *(Uint32 *)p = pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 }
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
346 }</PRE
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
347 ></DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
348 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
349 >The following code uses the putpixel() function above to set a
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
350 yellow pixel in the middle of the screen.</P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
351 ><DIV
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
352 CLASS="EXAMPLE"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
353 ><A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
354 NAME="AEN97"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
355 ></A
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
356 ><P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
357 ><B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
358 >Example 2-6. Using putpixel()</B
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
359 ></P
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
360 ><PRE
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
361 CLASS="PROGRAMLISTING"
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
362 >&#13; /* Code to set a yellow pixel at the center of the screen */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
364 int x, y;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
365 Uint32 yellow;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
366
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
367 /* Map the color yellow to this display (R=0xff, G=0xFF, B=0x00)
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
368 Note: If the display is palettized, you must set the palette first.
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
369 */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
370 yellow = SDL_MapRGB(screen-&#62;format, 0xff, 0xff, 0x00);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
372 x = screen-&#62;w / 2;
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
373 y = screen-&#62;h / 2;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
374
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
375 /* Lock the screen for direct access to the pixels */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
376 if ( SDL_MUSTLOCK(screen) ) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
377 if ( SDL_LockSurface(screen) &#60; 0 ) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
378 fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError());
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
379 return;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
383 putpixel(screen, x, y, yellow);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
385 if ( SDL_MUSTLOCK(screen) ) {
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
386 SDL_UnlockSurface(screen);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 }
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
388 /* Update just the part of the display that we've changed */
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
389 SDL_UpdateRect(screen, x, y, 1, 1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
391 return;&#13;</PRE
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 ></DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 ></DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 ></DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 ></DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396 ><DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 CLASS="NAVFOOTER"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 ><HR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 ALIGN="LEFT"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 WIDTH="100%"><TABLE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 WIDTH="100%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 BORDER="0"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 CELLPADDING="0"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 CELLSPACING="0"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 ><TR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 WIDTH="33%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 ALIGN="left"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 VALIGN="top"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410 ><A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 HREF="guidebasicsinit.html"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 >Prev</A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413 ></TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 WIDTH="34%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
416 ALIGN="center"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417 VALIGN="top"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418 ><A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
419 HREF="index.html"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
420 >Home</A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421 ></TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
423 WIDTH="33%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
424 ALIGN="right"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425 VALIGN="top"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
426 ><A
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
427 HREF="guidevideoopengl.html"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
428 >Next</A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
429 ></TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
430 ></TR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
431 ><TR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
432 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
433 WIDTH="33%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
434 ALIGN="left"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
435 VALIGN="top"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
436 >Initializing SDL</TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
437 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
438 WIDTH="34%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439 ALIGN="center"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
440 VALIGN="top"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
441 ><A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
442 HREF="guide.html"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
443 >Up</A
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
444 ></TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445 ><TD
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 WIDTH="33%"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
447 ALIGN="right"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
448 VALIGN="top"
55
55f1f1b3e27d Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
449 >Using OpenGL With SDL</TD
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 ></TR
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
451 ></TABLE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
452 ></DIV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
453 ></BODY
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
454 ></HTML
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
455 >