Skip to content

SetCameraStencil

Narta Xaymar Dirks edited this page Nov 25, 2026 · 1 revision

SetCameraStencil

SetCameraStencil:Void camera:Int32, enabled:Int32
Parameter Mode Type Default Description
camera In Int32 required Camera handle.
enabled In Int32 required True for a stencil, False for none (the default).

Description

Gives a camera a stencil buffer: 8 bits for every pixel, next to the depth buffer, which entities with SetEntityStencil test and change while the camera draws. A stencil can mask out a part of the picture (a portal, a window into another scene, the inside of a mirror), count overlaps, or build shadow volumes. Without this, the camera has no stencil and entities draw as if they had none. This is a BlitzLLVM extension.

The camera clears the stencil of its viewport to 0 when it starts drawing; SetCameraStencilClear changes that. Cameras that draw to targets of the same size share one depth buffer, so they also share the stencil: a second camera that clears neither depth nor stencil sees what the first one left.

A stencil costs one byte per pixel and a slightly slower depth buffer, so it is only there for cameras that ask for it. Entities that use order-independent transparency (BLITZLLVM_OIT 1 to 5) and 2D drawing ignore the stencil.

Examples

Graphics3D 640, 480, 0, 2
SetBuffer BackBuffer()
camera = CreateCamera()
SetCameraStencil camera, True

; The window: drawn first (EntityOrder 1), it sets the stencil to 1 where it is.
window = CreateCube()
EntityOrder window, 1
PositionEntity window, 0, 0, 10
SetEntityStencil window, 7, 1, 255, 255, 0, 0, 2

; The world behind it is only drawn where the stencil is 1.
sphere = CreateSphere(32)
EntityColor sphere, 255, 128, 0
PositionEntity sphere, 0, 0, 20
ScaleEntity sphere, 8, 8, 8
SetEntityStencil sphere, 2, 1

RenderWorld
Flip
WaitKey

Related Commands

CameraClsColor, GetCameraStencil, SetCameraBuffer, SetCameraClipPlane, SetCameraClipPlaneEnabled, SetCameraProjectionMatrix, SetCameraStencilClear, SetCameraViewMatrix

Home · Command Index


Getting started

Language

Tools


Language Features
BlitzBasic
Blitz3D
BlitzPlus
Differences

More

Clone this wiki locally