Jump to content
  • Advertisement
Sign in to follow this  
Yourself

OpenGL HLSL stencil functions to OpenGL

This topic is 2594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I'm in the middle of porting some HLSL shaders to opengl (with CG) and I'm struggling a bit with the correct opengl stencil statements...
I have to states that need to be set for the stencil buffer :

//first onea
StencilEnable = true;
StencilPass = REPLACE;
StencilRef = 1;

//second
StencilEnable = true;
StencilPass = KEEP;
StencilFunc = EQUAL;
StencilRef = 1;[/quote]

I thought it would be this but it looks wrong sometimes. Withing my directX project, I'm clearing the backbuffer with stencil value 0
//first one
glClearStencil(0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

//second one
glClearStencil(0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);


So, can anybody verify if this is correct (and what would needed to be changed)?

Thx!!

Share this post


Link to post
Share on other sites
Advertisement
Do you realize that glClearStencil() doesn't clear the stencil buffer? It just sets the value to which the stencil buffer is cleared when you call glClear(). To clear the stencil buffer, call glClear(GL_STENCIL_BUFFER_BIT).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!