1GLDRAWPIXELS(3G) GLDRAWPIXELS(3G)
2
3
4
6 glDrawPixels - write a block of pixels to the frame buffer
7
8
10 void glDrawPixels( GLsizei width,
11 GLsizei height,
12 GLenum format,
13 GLenum type,
14 const GLvoid *pixels )
15
16
18 width, height Specify the dimensions of the pixel rectangle to be writ‐
19 ten into the frame buffer.
20
21 format Specifies the of the pixel data. Symbolic constants
22 GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT,
23 GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_RED, GL_GREEN,
24 GL_BLUE, GL_ALPHA, GL_LUMINANCE, and GL_LUMINANCE_ALPHA
25 are accepted.
26
27 type Specifies the data type for pixels. Symbolic constants
28 GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT,
29 GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT,
30 GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
31 GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV,
32 GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV,
33 GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
34 GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,
35 GL_UNSIGNED_INT_10_10_10_2, and
36 GL_UNSIGNED_INT_2_10_10_10_REV are accepted.
37
38 pixels Specifies a pointer to the pixel data.
39
41 glDrawPixels reads pixel data from memory and writes it into the frame
42 buffer
43 relative to the current raster position, provided that the raster posi‐
44 tion is valid. Use
45 glRasterPos to set the current raster position; use glGet with argument
46 GL_CURRENT_RASTER_POSITION_VALID to determine if the specified raster
47 position is valid, and glGet with argument GL_CURRENT_RASTER_POSITION
48 to query the raster position.
49
50 Several parameters define the encoding of pixel data in memory and con‐
51 trol the processing of the pixel data before it is placed in the frame
52 buffer. These parameters are set with four commands: glPixelStore,
53 glPixelTransfer, glPixelMap, and glPixelZoom. This reference page
54 describes the effects on glDrawPixels of many, but not all, of the
55 parameters specified by these four commands.
56
57 Data is read from pixels as a sequence of signed or unsigned bytes,
58 signed or unsigned shorts, signed or unsigned integers, or single-pre‐
59 cision floating-point values, depending on type. When type is one of
60 GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT,
61 GL_UNSIGNED_INT, GL_INT, or GL_FLOAT each of these bytes, shorts, inte‐
62 gers, or floating-point values is interpreted as one color or depth
63 component, or one index, depending on format. When type is one of
64 GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_SHORT_5_6_5,
65 GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_5_5_5_1,
66 GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_10_10_10_2, each unsigned
67 value is interpreted as containing all the components for a single
68 pixel, with the color components arranged according to format. When
69 type is one of GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5_REV,
70 GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_1_5_5_5_REV,
71 GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_2_10_10_10_REV, each
72 unsigned value is interpreted as containing all color components, spec‐
73 ified by format, for a single pixel in a reversed order. Indices are
74 always treated individually. Color components are treated as groups of
75 one, two, three, or four values, again based on format. Both individual
76 indices and groups of components are referred to as pixels. If type is
77 GL_BITMAP, the data must be unsigned bytes, and format must be either
78 GL_COLOR_INDEX or GL_STENCIL_INDEX. Each unsigned byte is treated as
79 eight 1-bit pixels, with bit ordering determined by GL_UNPACK_LSB_FIRST
80 (see glPixelStore).
81
82 width×height pixels are read from memory, starting at location pixels.
83 By default, these pixels are taken from adjacent memory locations,
84 except that after all width pixels are read, the read pointer is
85 advanced to the next four-byte boundary. The four-byte row alignment
86 is specified by glPixelStore with argument GL_UNPACK_ALIGNMENT, and it
87 can be set to one, two, four, or eight bytes. Other pixel store param‐
88 eters specify different read pointer advancements, both before the
89 first pixel is read and after all width pixels are read. See the
90 glPixelStore reference page for details on these options.
91
92 The width×height pixels that are read from memory are each operated on
93 in the same way, based on the values of several parameters specified by
94 glPixelTransfer and glPixelMap. The details of these operations, as
95 well as the target buffer into which the pixels are drawn, are specific
96 to the of the pixels, as specified by format. format can assume one
97 of 13 symbolic values:
98
99 GL_COLOR_INDEX
100 Each pixel is a single value, a color index. It is converted
101 to fixed-point , with an unspecified number of bits to the
102 right of the binary point, regardless of the memory data
103 type. Floating-point values convert to true fixed-point val‐
104 ues. Signed and unsigned integer data is converted with all
105 fraction bits set to 0. Bitmap data convert to either 0 or
106 1.
107
108 Each fixed-point index is then shifted left by GL_INDEX_SHIFT
109 bits and added to GL_INDEX_OFFSET. If GL_INDEX_SHIFT is neg‐
110 ative, the shift is to the right. In either case, zero bits
111 fill otherwise unspecified bit locations in the result.
112
113 If the GL is in RGBA mode, the resulting index is converted
114 to an RGBA pixel with the help of the GL_PIXEL_MAP_I_TO_R,
115 GL_PIXEL_MAP_I_TO_G, GL_PIXEL_MAP_I_TO_B, and
116 GL_PIXEL_MAP_I_TO_A tables. If the GL is in color index
117 mode, and if GL_MAP_COLOR is true, the index is replaced with
118 the value that it references in lookup table
119 GL_PIXEL_MAP_I_TO_I. Whether the lookup replacement of the
120 index is done or not, the integer part of the index is then
121 ANDed with 2b−1, where b is the number of bits in a color
122 index buffer.
123
124 The GL then converts the resulting indices or RGBA colors to
125 fragments by attaching the current raster position z coordi‐
126 nate and texture coordinates to each pixel, then assigning x
127 and y window coordinates to the nth fragment such that
128
129 xn=xr+nmodwidth
130
131 yn=yr+⌊n/width⌋
132
133
134 where (xr,yr) is the current raster position. These pixel
135 fragments are then treated just like the fragments generated
136 by rasterizing points, lines, or polygons. Texture mapping,
137 fog, and all the fragment operations are applied before the
138 fragments are written to the frame buffer.
139
140 GL_STENCIL_INDEX
141 Each pixel is a single value, a stencil index. It is con‐
142 verted to fixed-point , with an unspecified number of bits to
143 the right of the binary point, regardless of the memory data
144 type. Floating-point values convert to true fixed-point val‐
145 ues. Signed and unsigned integer data is converted with all
146 fraction bits set to 0. Bitmap data convert to either 0 or
147 1.
148
149 Each fixed-point index is then shifted left by GL_INDEX_SHIFT
150 bits, and added to GL_INDEX_OFFSET. If GL_INDEX_SHIFT is
151 negative, the shift is to the right. In either case, zero
152 bits fill otherwise unspecified bit locations in the result.
153 If GL_MAP_STENCIL is true, the index is replaced with the
154 value that it references in lookup table GL_PIXEL_MAP_S_TO_S.
155 Whether the lookup replacement of the index is done or not,
156 the integer part of the index is then ANDed with 2b−1, where
157 b is the number of bits in the stencil buffer. The resulting
158 stencil indices are then written to the stencil buffer such
159 that the nth index is written to location
160
161 xn=xr+nmodwidth
162
163 yn=yr+⌊n/width⌋
164
165
166 where (xr,yr) is the current raster position. Only the pixel
167 ownership test, the scissor test, and the stencil writemask
168 affect these write operations.
169
170 GL_DEPTH_COMPONENT
171 Each pixel is a single-depth component. Floating-point data is
172 converted directly to an internal floating-point
173 with unspecified precision. Signed integer data is mapped lin‐
174 early to the internal floating-point
175 such that the most positive representable integer value maps to
176 1.0, and the most negative representable value maps to -1.0.
177 Unsigned integer data is mapped similarly: the largest integer
178 value maps to 1.0, and 0 maps to 0.0. The resulting floating-
179 point depth value is then multiplied by GL_DEPTH_SCALE and added
180 to GL_DEPTH_BIAS. The result is clamped to the range [0,1].
181
182 The GL then converts the resulting depth components to fragments
183 by attaching the current raster position color or color index
184 and texture coordinates to each pixel, then assigning x and y
185 window coordinates to the nth fragment such that
186
187 xn=xr+nmodwidth
188
189 yn=yr+⌊n/width⌋
190
191
192 where (xr,yr) is the current raster position. These pixel frag‐
193 ments are then treated just like the fragments generated by ras‐
194 terizing points, lines, or polygons. Texture mapping, fog, and
195 all the fragment operations are applied before the fragments are
196 written to the frame buffer.
197
198 GL_RGBA
199
200 GL_BGRA
201 Each pixel is a four-component group: for GL_RGBA, the red com‐
202 ponent is first, followed by green, followed by blue, followed
203 by alpha; for GL_BGRA the order is blue, green, red and then
204 alpha. Floating-point values are converted directly to an
205 internal floating-point
206 with unspecified precision. Signed integer values are mapped
207 linearly to the internal floating-point
208 such that the most positive representable integer value maps to
209 1.0, and the most negative representable value maps to -1.0.
210 (Note that this mapping does not convert 0 precisely to 0.0.)
211 Unsigned integer data is mapped similarly: the largest integer
212 value maps to 1.0, and 0 maps to 0.0. The resulting floating-
213 point color values are then multiplied by GL_c_SCALE and added
214 to GL_c_BIAS, where c is RED, GREEN, BLUE, and ALPHA for the
215 respective color components. The results are clamped to the
216 range [0,1].
217
218 If GL_MAP_COLOR is true, each color component is scaled by the
219 size of lookup table GL_PIXEL_MAP_c_TO_c, then replaced by the
220 value that it references in that table. c is R, G, B, or A
221 respectively.
222
223 The GL then converts the resulting RGBA colors to fragments by
224 attaching the current raster position z coordinate and texture
225 coordinates to each pixel, then assigning x and y window coordi‐
226 nates to the nth fragment such that
227
228 xn=xr+nmodwidth
229
230 yn=yr+⌊n/width⌋
231
232
233 where (xr,yr) is the current raster position. These pixel frag‐
234 ments are then treated just like the fragments generated by ras‐
235 terizing points, lines, or polygons. Texture mapping, fog, and
236 all the fragment operations are applied before the fragments are
237 written to the frame buffer.
238
239 GL_RED Each pixel is a single red component. This component is con‐
240 verted to the internal floating-point in the same way the red
241 component of an RGBA pixel is. It is then converted to an RGBA
242 pixel with green and blue set to 0, and alpha set to 1. After
243 this conversion, the pixel is treated as if it had been read as
244 an RGBA pixel.
245
246 GL_GREEN
247 Each pixel is a single green component. This component is con‐
248 verted to the internal floating-point in the same way the green
249 component of an RGBA pixel is. It is then converted to an RGBA
250 pixel with red and blue set to 0, and alpha set to 1. After
251 this conversion, the pixel is treated as if it had been read as
252 an RGBA pixel.
253
254 GL_BLUE
255 Each pixel is a single blue component. This component is con‐
256 verted to the internal floating-point in the same way the blue
257 component of an RGBA pixel is. It is then converted to an RGBA
258 pixel with red and green set to 0, and alpha set to 1. After
259 this conversion, the pixel is treated as if it had been read as
260 an RGBA pixel.
261
262 GL_ALPHA
263 Each pixel is a single alpha component. This component is con‐
264 verted to the internal floating-point in the same way the alpha
265 component of an RGBA pixel is. It is then converted to an RGBA
266 pixel with red, green, and blue set to 0. After this conver‐
267 sion, the pixel is treated as if it had been read as an RGBA
268 pixel.
269
270 GL_RGB
271
272 GL_BGR Each pixel is a three-component group: red first, followed by
273 green, followed by blue; for GL_BGR, the first component is
274 blue, followed by green and then red. Each component is con‐
275 verted to the internal floating-point in the same way the red,
276 green, and blue components of an RGBA pixel are. The color
277 triple is converted to an RGBA pixel with alpha set to 1. After
278 this conversion, the pixel is treated as if it had been read as
279 an RGBA pixel.
280
281 GL_LUMINANCE
282 Each pixel is a single luminance component. This component is
283 converted to the internal floating-point in the same way the
284 red component of an RGBA pixel is. It is then converted to an
285 RGBA pixel with red, green, and blue set to the converted lumi‐
286 nance value, and alpha set to 1. After this conversion, the
287 pixel is treated as if it had been read as an RGBA pixel.
288
289 GL_LUMINANCE_ALPHA
290 Each pixel is a two-component group: luminance first, followed
291 by alpha. The two components are converted to the internal
292 floating-point in the same way the red component of an RGBA
293 pixel is. They are then converted to an RGBA pixel with red,
294 green, and blue set to the converted luminance value, and alpha
295 set to the converted alpha value. After this conversion, the
296 pixel is treated as if it had been read as an RGBA pixel.
297
298 The following table summarizes the meaning of the valid constants for
299 the type parameter:
300
301
302
303──────────────────────────────────────────────────────────────────────────────────────────
305──────────────────────────────────────────────────────────────────────────────────────────
326──────────────────────────────────────────────────────────────────────────────────────────
327
328
329 The rasterization described so far assumes pixel zoom factors of 1. If
330 glPixelZoom is used to change the x and y pixel zoom factors, pixels
331 are converted to fragments as follows. If (xr, yr) is the current
332 raster position, and a given pixel is in the nth column and mth row of
333 the pixel rectangle, then fragments are generated for pixels whose cen‐
334 ters are in the rectangle with corners at
335
336 (xr+zoomxn, yr+zoomym)
337
338 (xr+zoomx(n+1), yr+zoomy(m+1))
339
340
341 where zoomx is the value of GL_ZOOM_X and zoomy is the value of
342 GL_ZOOM_Y.
343
345 GL_BGR and GL_BGRA are only valid for format if the GL version is 1.2
346 or greater.
347
348 GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
349 GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV,
350 GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV,
351 GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
352 GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,
353 GL_UNSIGNED_INT_10_10_10_2, and GL_UNSIGNED_INT_2_10_10_10_REV are only
354 valid for type if the GL version is 1.2 or greater.
355
357 GL_INVALID_VALUE is generated if either width or height is negative.
358
359 GL_INVALID_ENUM is generated if format or type is not one of the
360 accepted values.
361
362 GL_INVALID_OPERATION is generated if format is GL_RED, GL_GREEN,
363 GL_BLUE, GL_ALPHA, GL_RGB, GL_RGBA, GL_BGR, GL_BGRA, GL_LUMINANCE, or
364 GL_LUMINANCE_ALPHA, and the GL is in color index mode.
365
366 GL_INVALID_ENUM is generated if type is GL_BITMAP and format is not
367 either GL_COLOR_INDEX or GL_STENCIL_INDEX.
368
369 GL_INVALID_OPERATION is generated if format is GL_STENCIL_INDEX and
370 there is no stencil buffer.
371
372 GL_INVALID_OPERATION is generated if glDrawPixels is executed between
373 the execution of glBegin and the corresponding execution of glEnd.
374
375 GL_INVALID_OPERATION is generated if format is one
376 GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
377 GL_UNSIGNED_SHORT_5_6_5, of GL_UNSIGNED_SHORT_5_6_5_REV and format is
378 not GL_RGB.
379
380 GL_INVALID_OPERATION is generated if format is one of
381 GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV,
382 GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
383 GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,
384 GL_UNSIGNED_INT_10_10_10_2, or GL_UNSIGNED_INT_2_10_10_10_REV and for‐
385 mat is neither GL_RGBA nor GL_BGRA.
386
388 glGet with argument GL_CURRENT_RASTER_POSITION
389 glGet with argument GL_CURRENT_RASTER_POSITION_VALID
390
392 glAlphaFunc(3G), glBlendFunc(3G), glCopyPixels(3G), glDepthFunc(3G),
393 glLogicOp(3G), glPixelMap(3G), glPixelStore(3G), glPixelTransfer(3G),
394 glPixelZoom(3G), glRasterPos(3G), glReadPixels(3G), glScissor(3G),
395 glStencilFunc(3G)
396
397
398
399 GLDRAWPIXELS(3G)