GlStencilOp: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Removed protection from "GlStencilOp")
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''_glStencilOp:''' set front and back stencil test actions
{{DISPLAYTITLE:_glStencilOp}}
The '''_glStencilOp''' statement sets the stencil test actions.




{{PageSyntax}}
{{PageSyntax}}
: [[_glStencilOp]] GLenum {{Parameter|fail}}, GLenum {{Parameter|zfail}}, GLenum {{Parameter|zpass}}


  SUB _glStencilOp (BYVAL fail AS _UNSIGNED LONG, BYVAL zfail AS _UNSIGNED LONG, BYVAL zpass AS _UNSIGNED LONG)
  void '''_glStencilOp'''(GLenum {{Parameter|sfail}}, GLenum {{Parameter|dpfail}}, GLenum {{Parameter|dppass}});


 
{{PageParameters}}
; sfail
* OpenGL is using its own set of variable types to describe its command parameters.
: Specifies the action to take when the stencil test fails. Eight symbolic constants are accepted: {{KW|_GL_KEEP}}, {{KW|_GL_ZERO}}, {{KW|_GL_REPLACE}}, {{KW|_GL_INCR}}, {{KW|_GL_INCR_WRAP}}, {{KW|_GL_DECR}}, {{KW|_GL_DECR_WRAP}}, and {{KW|_GL_INVERT}}. The initial value is {{KW|_GL_KEEP}}.
* Use the following table to find the respective QB64 [[Variable Types]].
; dpfail
{{OpenGLTypesPlugin}}
: Specifies the stencil action when the stencil test passes, but the depth test fails. {{Parameter|dpfail}} accepts the same symbolic constants as {{Parameter|sfail}}. The initial value is {{KW|_GL_KEEP}}.
; dppass
: Specifies the stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled. {{Parameter|dppass}} accepts the same symbolic constants as {{Parameter|sfail}}. The initial value is {{KW|_GL_KEEP}}.




{{PageDescription}}
{{PageDescription}}
 
* OpenGL's documentation is available in several places, so we won't reproduce it here for another time.
Stenciling, like depth-buffering, enables and disables drawing on a per-pixel basis. You draw into the stencil planes using GL drawing primitives, then render geometry and images, using the stencil planes to mask out portions of the screen. Stenciling is typically used in multipass rendering algorithms to achieve special effects, such as decals, outlining, and constructive solid geometry rendering.
* The full description for this command can be found at [https://learn.microsoft.com/en-us/windows/win32/opengl/glstencilop Microsoft Docs] and is also valid for QB64 usage.
 
The stencil test conditionally eliminates a pixel based on the outcome of a comparison between the value in the stencil buffer and a reference value. To enable and disable the test, call {{KW|_glEnable}} and {{KW|_glDisable}} with argument {{KW|_GL_STENCIL_TEST}}; to control it, call {{KW|_glStencilFunc}} or {{KW|_glStencilFuncSeparate}}.
 
There can be two separate sets of {{Parameter|sfail}}, {{Parameter|dpfail}}, and {{Parameter|dppass}} parameters; one affects back-facing polygons, and the other affects front-facing polygons as well as other non-polygon primitives. {{KW|_glStencilOp}} sets both front and back stencil state to the same values. Use {{KW|_glStencilOpSeparate}} to set front and back stencil state to different values.
 
'''_glStencilOp''' takes three arguments that indicate what happens to the stored stencil value while stenciling is enabled. If the stencil test fails, no change is made to the pixel's color or depth buffers, and {{Parameter|sfail}} specifies what happens to the stencil buffer contents. The following eight actions are possible.
 
; {{KW|_GL_KEEP}}
: Keeps the current value.
; {{KW|_GL_ZERO}}
: Sets the stencil buffer value to 0.
; {{KW|_GL_REPLACE}}
: Sets the stencil buffer value to ''ref'', as specified by {{KW|_glStencilFunc}}.
; {{KW|_GL_INCR}}
: Increments the current stencil buffer value. Clamps to the maximum representable unsigned value.
; {{KW|_GL_INCR_WRAP}}
: Increments the current stencil buffer value. Wraps stencil buffer value to zero when incrementing the maximum representable unsigned value.
; {{KW|_GL_DECR}}
: Decrements the current stencil buffer value. Clamps to 0.
; {{KW|_GL_DECR_WRAP}}
: Decrements the current stencil buffer value. Wraps stencil buffer value to the maximum representable unsigned value when decrementing a stencil buffer value of zero.
; {{KW|_GL_INVERT}}
: Bitwise inverts the current stencil buffer value.
Stencil buffer values are treated as unsigned integers. When incremented and decremented, values are clamped to 0 and 2<sup>n</sup> - 1, where ''n'' is the value returned by querying {{KW|_GL_STENCIL_BITS}}.
 
The other two arguments to '''_glStencilOp''' specify stencil buffer actions that depend on whether subsequent depth buffer tests succeed ({{Parameter|dppass}}) or fail ({{Parameter|dpfail}}) (see {{KW|_glDepthFunc}}). The actions are specified using the same eight symbolic constants as {{Parameter|sfail}}. Note that {{Parameter|dpfail}} is ignored when there is no depth buffer, or when the depth buffer is not enabled. In these cases, {{Parameter|sfail}} and {{Parameter|dppass}} specify stencil action when the stencil test fails and passes, respectively.
 
 
{{PageNotes}}
 
Initially the stencil test is disabled. If there is no stencil buffer, no stencil modification can occur and it is as if the stencil tests always pass, regardless of any call to '''_glStencilOp'''.
 
{{KW|_glStencilOp}} is the same as calling {{KW|_glStencilOpSeparate}} with {{Parameter|face}} set to {{KW|_GL_FRONT_AND_BACK}}.
 
 
{{PageErrors}}
 
{{KW|_GL_INVALID_ENUM}} is generated if {{Parameter|sfail}}, {{Parameter|dpfail}}, or {{Parameter|dppass}} is any value other than the defined constant values.
 
 
{{PageUseWith}}
 
{{KW|_glGet}} with argument {{KW|_GL_STENCIL_FAIL}}, {{KW|_GL_STENCIL_PASS_DEPTH_PASS}}, {{KW|_GL_STENCIL_PASS_DEPTH_FAIL}}, {{KW|_GL_STENCIL_BACK_FAIL}}, {{KW|_GL_STENCIL_BACK_PASS_DEPTH_PASS}}, {{KW|_GL_STENCIL_BACK_PASS_DEPTH_FAIL}}, or {{KW|_GL_STENCIL_BITS}}
 
{{KW|_glIsEnabled}} with argument {{KW|_GL_STENCIL_TEST}}




{{PageSeeAlso}}
{{PageSeeAlso}}
 
* [[_GL|SUB _GL]]
[[_GL|SUB _GL]]
* [[_glAlphaFunc]], [[_glBegin]], [[_glBlendFunc]], [[_glDepthFunc]]
{{KW|_glBlendFunc}}, {{KW|_glDepthFunc}}, {{KW|_glEnable}}, {{KW|_glLogicOp}}, {{KW|_glStencilFunc}}, {{KW|_glStencilFuncSeparate}}, {{KW|_glStencilMask}}, {{KW|_glStencilMaskSeparate}}, {{KW|_glStencilOpSeparate}}
* [[_glEnable]], [[_glEnd]], [[_glIsEnabled]], [[_glLogicOp]]
 
* [[_glStencilFunc]]
 
{{PageCopyright}}




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 01:38, 28 January 2023

The _glStencilOp statement sets the stencil test actions.


Syntax

_glStencilOp GLenum fail, GLenum zfail, GLenum zpass


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