GlStencilFunc: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Removed protection from "GlStencilFunc")
No edit summary
Line 1: Line 1:
'''_glStencilFunc:''' set front and back function and reference value for stencil testing
{{DISPLAYTITLE:_glStencilFunc}}
The '''_glStencilFunc''' statement sets the function and reference value for stencil testing.




{{PageSyntax}}
{{PageSyntax}}
: '''_glStencilFunc''' GLenum {{Parameter|func}}, GLint {{Parameter|ref}}, GLuint {{Parameter|mask}}


  SUB _glStencilFunc (BYVAL func AS _UNSIGNED LONG, BYVAL ref AS LONG, BYVAL mask AS _UNSIGNED LONG)
  void '''_glStencilFunc'''(GLenum {{Parameter|func}}, GLint {{Parameter|ref}}, GLuint {{Parameter|mask}});


 
{{PageParameters}}
; func
* OpenGL is using its own set of variable types to describe its command parameters.
: Specifies the test function. Eight symbolic constants are valid: {{KW|_GL_NEVER}}, {{KW|_GL_LESS}}, {{KW|_GL_LEQUAL}}, {{KW|_GL_GREATER}}, {{KW|_GL_GEQUAL}}, {{KW|_GL_EQUAL}}, {{KW|_GL_NOTEQUAL}}, and {{KW|_GL_ALWAYS}}. The initial value is {{KW|_GL_ALWAYS}}.
* Use the following table to find the respective QB64 [[Variable Types]].
; ref
{{OpenGLTypesPlugin}}
: Specifies the reference value for the stencil test. {{Parameter|ref}} is clamped to the range [0, 2<sup>n</sup> - 1, where ''n'' is the number of bitplanes in the stencil buffer. The initial value is 0.
; mask
: Specifies a mask that is ANDed with both the reference value and the stored stencil value when the test is done. The initial value is all 1's.




{{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. Stencil planes are first drawn into using GL drawing primitives, then geometry and images are rendered 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://docs.microsoft.com/en-us/windows/win32/opengl/glstencilfunc 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 reference value and the value in the stencil buffer. To enable and disable the test, call {{KW|_glEnable}} and {{KW|_glDisable}} with argument {{KW|_GL_STENCIL_TEST}}. To specify actions based on the outcome of the stencil test, call {{KW|_glStencilOp}} or {{KW|_glStencilOpSeparate}}.
 
There can be two separate sets of {{Parameter|func}}, {{Parameter|ref}}, and {{Parameter|mask}} parameters; one affects back-facing polygons, and the other affects front-facing polygons as well as other non-polygon primitives. {{KW|_glStencilFunc}} sets both front and back stencil state to the same values. Use {{KW|_glStencilFuncSeparate}} to set front and back stencil state to different values.
 
{{Parameter|func}} is a symbolic constant that determines the stencil comparison function. It accepts one of eight values, shown in the following list. {{Parameter|ref}} is an integer reference value that is used in the stencil comparison. It is clamped to the range [0, 2<sup>n</sup> - 1], where ''n'' is the number of bitplanes in the stencil buffer. {{Parameter|mask}} is bitwise ANDed with both the reference value and the stored stencil value, with the ANDed values participating in the comparison.
 
If ''stencil'' represents the value stored in the corresponding stencil buffer location, the following list shows the effect of each comparison function that can be specified by {{Parameter|func}}. Only if the comparison succeeds is the pixel passed through to the next stage in the rasterization process (see {{KW|_glStencilOp}}). All tests treat ''stencil'' values as unsigned integers in the range [0, 2<sup>n</sup> - 1], where ''n'' is the number of bitplanes in the stencil buffer.
 
The following values are accepted by {{Parameter|func}}:
 
; {{KW|_GL_NEVER}}
: Always fails.
; {{KW|_GL_LESS}}
: Passes if ( {{Parameter|ref}} & {{Parameter|mask}} ) < ( ''stencil'' & {{Parameter|mask}} ).
; {{KW|_GL_LEQUAL}}
: Passes if ( {{Parameter|ref}} & {{Parameter|mask}} ) <= ( ''stencil'' & {{Parameter|mask}} ).
; {{KW|_GL_GREATER}}
: Passes if ( {{Parameter|ref}} & {{Parameter|mask}} ) > ( ''stencil'' & {{Parameter|mask}} ).
; {{KW|_GL_GEQUAL}}
: Passes if ( {{Parameter|ref}} & {{Parameter|mask}} ) >= ( ''stencil'' & {{Parameter|mask}} ).
; {{KW|_GL_EQUAL}}
: Passes if ( {{Parameter|ref}} & {{Parameter|mask}} ) = ( ''stencil'' & {{Parameter|mask}} ).
; {{KW|_GL_NOTEQUAL}}
: Passes if ( {{Parameter|ref}} & {{Parameter|mask}} ) != ( ''stencil'' & {{Parameter|mask}} ).
; {{KW|_GL_ALWAYS}}
: Always passes.
 
{{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 test always passes.
 
{{KW|_glStencilFunc}} is the same as calling {{KW|_glStencilFuncSeparate}} with {{Parameter|face}} set to {{KW|_GL_FRONT_AND_BACK}}.
 
 
{{PageErrors}}
 
{{KW|_GL_INVALID_ENUM}} is generated if {{Parameter|func}} is not one of the eight accepted values.
 
 
{{PageUseWith}}
 
{{KW|_glGet}} with argument {{KW|_GL_STENCIL_FUNC}}, {{KW|_GL_STENCIL_VALUE_MASK}}, {{KW|_GL_STENCIL_REF}}, {{KW|_GL_STENCIL_BACK_FUNC}}, {{KW|_GL_STENCIL_BACK_VALUE_MASK}}, {{KW|_GL_STENCIL_BACK_REF}}, or {{KW|_GL_STENCIL_BITS}}
 
{{KW|_glIsEnabled}} with argument {{KW|_GL_STENCIL_TEST}}




{{PageSeeAlso}}
{{PageSeeAlso}}
* [[_GL|SUB _GL]]


[[_GL|SUB _GL]]
{{KW|_glEnable|(GL_STENCIL_TEST)}}, {{KW|_glLogicOp}}, {{KW|_glStencilFuncSeparate}}, {{KW|_glStencilMask}}, {{KW|_glStencilMaskSeparate}}, {{KW|_glStencilOp}}, {{KW|_glStencilOpSeparate}}


{{PageNavigation}}


{{PageCopyright}}
[[Category:Final]]
 
 
{{PageNavigation}}

Revision as of 15:44, 19 July 2022

The _glStencilFunc statement sets the function and reference value for stencil testing.


Syntax

_glStencilFunc GLenum func, GLint ref, GLuint mask


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