Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit 40bc8d534b8c2e32b1e4b2617709a873b06ad322 1 parent d2b4995
Rene Christen authored
Showing with 64 additions and 1 deletion.
  1. +16 −1 README.md
  2. +48 −0 src/ofxStencil.h
View
17 README.md
@@ -1,4 +1,19 @@
ofxStencil
==========
-Simple addon for using stencil buffer.
+Simple addon for using stencil buffer. Code adapted from:
+http://www.videotutorialsrock.com/opengl_tutorial/reflections/video.php
+
+You need to enable stencil buffer in main.cpp, for example:
+
+ofAppGlutWindow window;
+window.setGlutDisplayString("stencil~2 rgba double samples>=4 depth");
+
+Usage:
+
+ofxStencil stencil;
+stencil.beginDrawingStencil();
+//draw your mask
+stencil.beginUsingStencil();
+//draw what you want masked
+stencil.endUsingStencil();
View
48 src/ofxStencil.h
@@ -0,0 +1,48 @@
+/*
+
+code adapted from:
+http://www.videotutorialsrock.com/opengl_tutorial/reflections/video.php
+
+@note: need to enable stencil buffer in main.cpp
+
+ofAppGlutWindow window;
+window.setGlutDisplayString("stencil~2 rgba double samples>=4 depth");
+
+*/
+
+#pragma once
+
+#include "ofMain.h"
+
+class ofxStencil {
+public:
+
+ ofxStencil(){}
+
+ //set up to draw stencil
+ void beginDrawingStencil() {
+ glClear(GL_STENCIL_BUFFER_BIT);
+ glEnable(GL_STENCIL_TEST); //Enable using the stencil buffer
+ glColorMask(0, 0, 0, 0); //Disable drawing colors to the screen
+ glStencilFunc(GL_ALWAYS, 1, 1); //Make the stencil test always pass
+ //Make pixels in the stencil buffer be set to 1 when the stencil test passes
+ glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+ //Set all of the pixels below to be 1 in the stencil buffer...
+ }
+
+ //switch from drawing stencil to scene to be masked
+ void beginUsingStencil() {
+ glColorMask(1, 1, 1, 1); //Enable drawing colors to the screen
+ //Make the stencil test pass only when the pixel is 1 in the stencil buffer
+ glStencilFunc(GL_EQUAL, 1, 1);
+ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); //Make the stencil buffer not change
+ //Draw all pixels where the stencil buffer is 1...
+ }
+
+ //back to normal unmasked drawing
+ void endUsingStencil() {
+ glDisable(GL_STENCIL_TEST); //Disable using the stencil buffer
+ }
+
+};//class ofxStencil
+
Please sign in to comment.
Something went wrong with that request. Please try again.