GlReadPixels: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''_glReadPixels:''' read a block of pixels from the frame buffer
{{DISPLAYTITLE:_glReadPixels}}
The '''_glReadPixels''' statement reads a block of pixels from the framebuffer.




{{PageSyntax}}
{{PageSyntax}}
: [[_glReadPixels]] GLint {{Parameter|x}}, GLint {{Parameter|y}}, GLsizei {{Parameter|width}}, GLsizei {{Parameter|height}}, GLenum {{Parameter|format}}, GLenum {{Parameter|type}}, GLvoid {{Parameter|*pixels}}


  SUB _glReadPixels (BYVAL x AS LONG, BYVAL y AS LONG, BYVAL width AS LONG, BYVAL height AS LONG, BYVAL format AS _UNSIGNED LONG, BYVAL type AS _UNSIGNED LONG, pixels AS _OFFSET)
  void '''_glReadPixels'''(GLint {{Parameter|x}}, GLint {{Parameter|y}}, GLsizei {{Parameter|width}}, GLsizei {{Parameter|height}}, GLenum {{Parameter|format}}, GLenum {{Parameter|type}}, GLvoid * {{Parameter|data}});


 
{{PageParameters}}
; x, y
* OpenGL is using its own set of variable types to describe its command parameters.
: Specify the window coordinates of the first pixel that is read from the frame buffer. This location is the lower left corner of a rectangular block of pixels.
* Use the following table to find the respective QB64 [[Variable Types]].
; width, height
{{OpenGLTypesPlugin}}
: Specify the dimensions of the pixel rectangle. {{Parameter|width}} and {{Parameter|height}} of one correspond to a single pixel.
{{Template:Glapi pixeltransferupparams|read=|}}




{{PageDescription}}
{{PageDescription}}
 
* OpenGL's documentation is available in several places, so we won't reproduce it here for another time.
'''_glReadPixels''' returns pixel data from the frame buffer, starting with the pixel whose lower left corner is at location ({{Parameter|x}}, {{Parameter|y}}), into client memory starting at location {{Parameter|data}}. Several parameters control the processing of the pixel data before it is placed into client memory. These parameters are set with {{KW|_glPixelStore}}. This reference page describes the effects on '''_glReadPixels''' of most, but not all of the parameters specified by these three commands.
* The full description for this command can be found at [https://learn.microsoft.com/en-us/windows/win32/opengl/glreadpixels Microsoft Docs] and is also valid for QB64 usage.
 
If a non-zero named buffer object is bound to the {{KW|_GL_PIXEL_PACK_BUFFER}} target (see {{KW|_glBindBuffer}}) while a block of pixels is requested, {{Parameter|data}} is treated as a byte offset into the buffer object's data store rather than a pointer to client memory.
 
'''_glReadPixels''' returns values from each pixel with lower left corner at (''x'' + ''i'', ''y'' + ''j'') for 0 <= ''i'' < ''width'' and 0 <= ''j'' < ''height''. This pixel is said to be the ''i''th pixel in the ''j''th row. Pixels are returned in row order from the lowest to the highest row, left to right in each row.
 
{{Parameter|format}} specifies the format for the returned pixel values; accepted values are:
 
; {{KW|_GL_STENCIL_INDEX}}
: Stencil values are read from the stencil buffer. Each index is converted to fixed point, shifted left or right depending on the value and sign of {{KW|_GL_INDEX_SHIFT}}, and added to {{KW|_GL_INDEX_OFFSET}}. If {{KW|_GL_MAP_STENCIL}} is {{KW|_GL_TRUE}}, indices are replaced by their mappings in the table {{KW|_GL_PIXEL_MAP_S_TO_S}}.
; {{KW|_GL_DEPTH_COMPONENT}}
: Depth values are read from the depth buffer. Each component is converted to floating point such that the minimum depth value maps to 0 and the maximum value maps to 1. Each component is then multiplied by {{KW|_GL_DEPTH_SCALE}}, added to {{KW|_GL_DEPTH_BIAS}}, and finally clamped to the range [0, 1].
; {{KW|_GL_DEPTH_STENCIL}}
: Values are taken from both the depth and stencil buffers. The {{Parameter|type}} parameter must be {{KW|_GL_UNSIGNED_INT_24_8}} or {{KW|_GL_FLOAT_32_UNSIGNED_INT_24_8_REV}}.
; {{KW|_GL_RED}}
; {{KW|_GL_GREEN}}
; {{KW|_GL_BLUE}}
; {{KW|_GL_RGB}}
; {{KW|_GL_BGR}}
; {{KW|_GL_RGBA}}
; {{KW|_GL_BGRA}}
: Finally, the indices or components are converted to the proper format, as specified by {{Parameter|type}}. If {{Parameter|format}} is {{KW|_GL_STENCIL_INDEX}} and {{Parameter|type}} is not {{KW|_GL_FLOAT}}, each index is masked with the mask value given in the following table. If {{Parameter|type}} is {{KW|_GL_FLOAT}}, then each integer index is converted to single-precision floating-point format.
 
If {{Parameter|format}} is {{KW|_GL_RED}}, {{KW|_GL_GREEN}}, {{KW|_GL_BLUE}}, {{KW|_GL_RGB}}, {{KW|_GL_BGR}}, {{KW|_GL_RGBA}}, or {{KW|_GL_BGRA}} and {{Parameter|type}} is not {{KW|_GL_FLOAT}}, each component is multiplied by the multiplier shown in the following table. If type is {{KW|_GL_FLOAT}}, then each component is passed as is (or converted to the client's single-precision floating-point format if it is different from the one used by the GL).
 
{| class="wikitable"
|+
! {{Parameter|type}}
! '''Index Mask'''
! '''Component Conversion'''
|+
| {{KW|_GL_UNSIGNED_BYTE}}
| 2<sup>8</sup> - 1
| <math>(2^8 - 1)c</math>
|+
| {{KW|_GL_BYTE}}
| 2<sup>7</sup> - 1
| <math>\tfrac{(2^8 - 1)c - 1}{2}</math>
|+
| {{KW|_GL_UNSIGNED_SHORT}}
| 2<sup>16</sup> - 1
| <math>(2^{16} - 1)c</math>
|+
| {{KW|_GL_SHORT}}
| 2<sup>15</sup> - 1
| <math>\tfrac{(2^{16} - 1)c - 1}{2}</math>
|+
| {{KW|_GL_UNSIGNED_INT}}
| 2<sup>32</sup> - 1
| <math>(2^{32} - 1)c</math>
|+
| {{KW|_GL_INT}}
| 2<sup>31</sup> - 1
| <math>\tfrac{(2^{32} - 1)c - 1}{2}</math>
|+
| {{KW|_GL_HALF_FLOAT}}
| none
| ''c''
|+
| {{KW|_GL_FLOAT}}
| none
| ''c''
|+
| {{KW|_GL_UNSIGNED_BYTE_3_3_2}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_BYTE_2_3_3_REV}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_SHORT_5_6_5}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_SHORT_5_6_5_REV}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_SHORT_4_4_4_4}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_SHORT_4_4_4_4_REV}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_SHORT_5_5_5_1}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_SHORT_1_5_5_5_REV}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_INT_8_8_8_8}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_INT_8_8_8_8_REV}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_INT_10_10_10_2}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_INT_2_10_10_10_REV}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_INT_24_8}}
| 2<sup>N</sup> - 1
| <math>(2^N - 1)c</math>
|+
| {{KW|_GL_UNSIGNED_INT_10F_11F_11F_REV}}
| --
| Special
|+
| {{KW|_GL_UNSIGNED_INT_5_9_9_9_REV}}
| --
| Special
|+
| {{KW|_GL_FLOAT_32_UNSIGNED_INT_24_8_REV}}
| none
| ''c'' (Depth Only)
|}
 
Return values are placed in memory as follows. If {{Parameter|format}} is {{KW|_GL_STENCIL_INDEX}}, {{KW|_GL_DEPTH_COMPONENT}}, {{KW|_GL_RED}}, {{KW|_GL_GREEN}}, or {{KW|_GL_BLUE}}, a single value is returned and the data for the ''i''th pixel in the ''j''th row is placed in location ''j'' * ''width'' + ''i''. {{KW|_GL_RGB}} and {{KW|_GL_BGR}} return three values, {{KW|_GL_RGBA}} and {{KW|_GL_BGRA}} return four values for each pixel, with all values corresponding to a single pixel occupying contiguous space in {{Parameter|data}}. Storage parameters set by {{KW|_glPixelStore}}, such as {{KW|_GL_PACK_LSB_FIRST}} and {{KW|_GL_PACK_SWAP_BYTES}}, affect the way that data is written into memory. See {{KW|_glPixelStore}} for a description.
 
 
{{PageNotes}}
 
Values for pixels that lie outside the window connected to the current GL context are undefined.
 
If an error is generated, no change is made to the contents of {{Parameter|data}}.
 
 
{{PageErrors}}
 
{{KW|_GL_INVALID_ENUM}} is generated if {{Parameter|format}} or {{Parameter|type}} is not an accepted value.
 
{{KW|_GL_INVALID_VALUE}} is generated if either {{Parameter|width}} or {{Parameter|height}} is negative.
 
{{KW|_GL_INVALID_OPERATION}} is generated if {{Parameter|format}} is {{KW|_GL_STENCIL_INDEX}} and there is no stencil buffer.
 
{{KW|_GL_INVALID_OPERATION}} is generated if {{Parameter|format}} is {{KW|_GL_DEPTH_COMPONENT}} and there is no depth buffer.
 
{{KW|_GL_INVALID_OPERATION}} is generated if {{Parameter|format}} is {{KW|_GL_DEPTH_STENCIL}} and there is no depth buffer or if there is no stencil buffer.
 
{{KW|_GL_INVALID_ENUM}} is generated if {{Parameter|format}} is {{KW|_GL_DEPTH_STENCIL}} and {{Parameter|type}} is not {{KW|_GL_UNSIGNED_INT_24_8}} or {{KW|_GL_FLOAT_32_UNSIGNED_INT_24_8_REV}}.
 
{{KW|_GL_INVALID_OPERATION}} is generated if {{Parameter|type}} is one of {{KW|_GL_UNSIGNED_BYTE_3_3_2}}, {{KW|_GL_UNSIGNED_BYTE_2_3_3_REV}}, {{KW|_GL_UNSIGNED_SHORT_5_6_5}}, or {{KW|_GL_UNSIGNED_SHORT_5_6_5_REV}} and {{Parameter|format}} is not {{KW|_GL_RGB}}.
 
{{KW|_GL_INVALID_OPERATION}} is generated if {{Parameter|type}} is one of {{KW|_GL_UNSIGNED_SHORT_4_4_4_4}}, {{KW|_GL_UNSIGNED_SHORT_4_4_4_4_REV}}, {{KW|_GL_UNSIGNED_SHORT_5_5_5_1}}, {{KW|_GL_UNSIGNED_SHORT_1_5_5_5_REV}}, {{KW|_GL_UNSIGNED_INT_8_8_8_8}}, {{KW|_GL_UNSIGNED_INT_8_8_8_8_REV}}, {{KW|_GL_UNSIGNED_INT_10_10_10_2}}, or {{KW|_GL_UNSIGNED_INT_2_10_10_10_REV}} and {{Parameter|format}} is neither {{KW|_GL_RGBA}} nor {{KW|_GL_BGRA}}.
 
{{KW|_GL_INVALID_OPERATION}} is generated if a non-zero buffer object name is bound to the {{KW|_GL_PIXEL_PACK_BUFFER}} target and the buffer object's data store is currently mapped.
 
{{KW|_GL_INVALID_OPERATION}} is generated if a non-zero buffer object name is bound to the {{KW|_GL_PIXEL_PACK_BUFFER}} target and the data would be packed to the buffer object such that the memory writes required would exceed the data store size.
 
{{KW|_GL_INVALID_OPERATION}} is generated if a non-zero buffer object name is bound to the {{KW|_GL_PIXEL_PACK_BUFFER}} target and {{Parameter|data}} is not evenly divisible into the number of bytes needed to store in memory a datum indicated by {{Parameter|type}}.
 
{{KW|_GL_INVALID_OPERATION}} is generated if {{KW|_GL_READ_FRAMEBUFFER_BINDING}} is non-zero, the read framebuffer is complete, and the value of {{KW|_GL_SAMPLE_BUFFERS}} for the read framebuffer is greater than zero.
 
 
{{PageUseWith}}
 
{{KW|_glGet}} with argument {{KW|_GL_INDEX_MODE}}
 
{{KW|_glGet}} with argument {{KW|_GL_PIXEL_PACK_BUFFER_BINDING}}




{{PageSeeAlso}}
{{PageSeeAlso}}
* [[_GL|SUB _GL]]
* [[_glBegin]], [[_glCopyPixels]], [[_glDrawPixels]], [[_glEnd]]
* [https://learn.microsoft.com/en-us/windows/win32/opengl/glpixelmap _glPixelMap], [https://learn.microsoft.com/en-us/windows/win32/opengl/glpixelstore-functions _glPixelStore], [https://learn.microsoft.com/en-us/windows/win32/opengl/glpixeltransfer _glPixelTransfer], [[_glReadBuffer]]


[[_GL|SUB _GL]]
{{KW|_glBindFramebuffer}}, {{KW|_glClampColor}}, {{KW|_glDrawBuffers}}, {{KW|_glDrawBuffers}}, {{KW|_glPixelStore}}
[[Pixel Transfer]], [[Pixel Buffer Object]]
{{PageCopyright}}


Copyright 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see [http://oss.sgi.com/projects/FreeB/ http://oss.sgi.com/projects/FreeB/].
{{PageNavigation}}

Latest revision as of 01:33, 28 January 2023

The _glReadPixels statement reads a block of pixels from the framebuffer.


Syntax

_glReadPixels GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels


Parameters

  • OpenGL is using its own set of variable types to describe its command parameters.
  • Use the following table to find the respective QB64 Variable Types.
   Table 2: Relations between the OpenGL variable types vs. C/C++ and QB64.
 ┌──────────────┬────────────────┬──────────────────────────────────────────┐
 │    OpenGLC/C++QB64                                 │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLenum       │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLboolean    │ unsigned char  │ _UNSIGNED _BYTE                          │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLbitfield   │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLbyte       │ signed char    │ _BYTE                                    │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLshort      │ short          │ INTEGER                                  │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLint        │ int            │ LONG                                     │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLsizei      │ int            │ LONG                                     │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLubyte      │ unsigned char  │ _UNSIGNED _BYTE                          │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLushort     │ unsigned short │ _UNSIGNED INTEGER                        │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLuint       │ unsigned int   │ _UNSIGNED LONG                           │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLfloat      │ float          │ SINGLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLclampf     │ float          │ SINGLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLdouble     │ double         │ DOUBLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLclampd     │ double         │ DOUBLE                                   │
 ├──────────────┼────────────────┼──────────────────────────────────────────┤
 │ GLvoid   (1) │ void           │ _OFFSET(any fixed lenght string or _BYTE │
 │              │                │         array element)                   │
 └──────────────┴────────────────┴──────────────────────────────────────────┘
 Note: If a parameter has an asterisk (*) in front, then it's a pointer to
       the designated OpenGL variable type, rather than a value of that type.
       Those must be passed using the _OFFSET(...) notation.

 E.g.  GLuint *anyParam is actually the offset of a _UNSIGNED LONG (~&)
       variable or array, which must be passed as _OFFSET(anyVar~&) or
       _OFFSET(anyArr~&()) respectively.

  (1)  This type is regularly only used for pointers (with asterisk (*)) to
       any byte sized memory data, hence _BYTE or fixed length strings.


Description

  • OpenGL's documentation is available in several places, so we won't reproduce it here for another time.
  • The full description for this command can be found at Microsoft Docs and is also valid for QB64 usage.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link