Hello!I need help.
I’m puzzled and don’t know how to make stencil buffer work.Hope you could give me some hints.
I have a rendering thread in my windows program,here’s a piece of code cut from it:
…
//This while-loop renders the scene all the time,
//until the “game” stops running by other means.
while(game_status.bRunning )
{
glViewport(0,0,winWidth,winHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, winWidth, 0, winHeight, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Here I want to draw a black rectangle in the lower part of my window.
//But the output on the screen doesn’t fit my need–the black rectangle wasn’t shown at all.
//What’s wrong?
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glColor3ub (0,0,0);
glRecti(0,0,windowWidth,windowHeight/10);
glStencilFunc(GL_NOTEQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glClearColor(0.4f, 0.4f, 0.6f, 0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
::SwapBuffers(pDC->GetSafeHdc());//pDC is ready before,dont worry about it.
}
…