Hello,
I’m trying to use the stencil buffer to render images inside a diamond shaped stencil area.
Here is how I create the diamond:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0,0,1,0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 0x1, 0x1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glBegin(GL_QUADS);
glVertex2f(-1.0, 0.0);
glVertex2f(0.0, 1.0);
glVertex2f(1.0, 0.0);
glVertex2f(0.0, -1.0);
glEnd();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
This is called everytime I resize the window.
Then I try to render the image that is in a texture:
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_captureWidth, m_captureHeight, m_colorFormat, m_colorBitFormat, (void*)m_pImage);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(m_widthRelation, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glTexCoord2f(m_widthRelation, m_heightRelation);
glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, m_heightRelation);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
If I use GL_EQUAL nothing is draw, with GL_NOTEQUAL the whole image is drawn.
What am i doing wrong ?
Thanks.