[SOLVED]Setting stencil buffer

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

[SOLVED]Setting stencil buffer

Post by lvgeng »

Hi guys....
After checking the docs I think it might be a little hard for me to figure it out by myself.

In OpenGL developing we can set the stencil buffer by ourselves, with which I can render only part of the whole render zone by making use of the stencil check.
But in Irrlicht the only thing I found related to the stencil buffer is the bool stencilbuffer which decide if we want to use it in shadows rendering. Is that possible for us to use the stencilbuffer directly?

I wish to render some images for stereoscopic device based on light barriers.

//=============================================================================================
I got freeglut involved to solve the problem.

Code: Select all

        driver->beginScene(true, true, SColor(255, 100, 101, 140));
 
        //Enable Stencil buffer and write in it. It's used as mask in this case. ======================================
        glClearStencil(0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
 
        glEnable(GL_STENCIL_TEST);
        
        glStencilFunc(GL_NEVER, 0x1, 0x1);
        glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
        
        //set part of the stencil buffer by drawing. It is strange that I can only draw the rects by the methods provided by irrlicht.
        driver->draw2DRectangle(video::SColor(100, 255, 255, 255),
            core::rect<s32>(0, 0, 1300, 500));
                
        glStencilFunc(GL_EQUAL, 0x1, 0x1);
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
        //=============================================
        
        smgr->drawAll();
        guienv->drawAll();
 
 
        driver->endScene();
Last edited by lvgeng on Tue Dec 08, 2015 3:42 pm, edited 2 times in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Setting stencil buffer for purpose other than shadows.

Post by hendu »

In base irr: only for the main window, if you enable it at device creation.

My fork has a parameter to enable them in RTTs, I regularly use them there. I've also posted the patch to irr tracker. I think the shader-pipeline branch can also use them.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Setting stencil buffer for purpose other than shadows.

Post by Nadro »

Stencil support for RTT is already supported in trunk and will be available in SMaterial too in near future.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

Re: [SOLVED]Setting stencil buffer

Post by lvgeng »

Finally I decided to solve the problem by including freeglut.
If it helps.
Post Reply