How to setup Stencil buffer with MFC

How to setup Stencil buffer with MFC

These day, I’m studying Stencil buffer to implement Shadow.
I made planar projected shadow. And I also made it with Shadow volume using Stencil buffer. NeHe tutorial was helpful for me.

Then, I applied that for my application. It runs on MFC Dialog.

To use stencil buffer with MFC, PFD should be set as None zero.
I allocated 8 bit for the stencil buffer.

static PIXELFORMATDESCRIPTOR pfd =
{
	sizeof(PIXELFORMATDESCRIPTOR),	//size of this pfd
	1,								//version number
	PFD_DRAW_TO_WINDOW|				//support window
	PFD_SUPPORT_OPENGL|				//support OpenGL
	PFD_DOUBLEBUFFER,				//double buffered
	PFD_TYPE_RGBA,					//RGBA type
	24,								//24-bit color depth
	0,0,0,0,0,0,					//color bits ignored
	8,								//alpha buffer
	0,								//shift bit ignored
	0,0,0,0,						//accumulation bits ignored
	16,								//16bit z-buffer
	8,								//stencil buffer
	0,								//auxilar buffer
	PFD_MAIN_PLANE,					//main layer
	0,								//reserved
	0,0,0							//layer masks ignored
};[/b]

And, some initialization for Stencil buffer were included.

glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black Background
glClearDepth(1.0f);									// Depth Buffer Setup
glClearStencil(0);									// Stencil Buffer Setup
glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
glCullFace(GL_BACK);								// Set Culling Face To Back Face
glEnable(GL_CULL_FACE);								// Enable Culling
glEnable(GL_STENCIL_TEST);[/b]

But, I couldn’t get the expected result.

The shadow volume was created well.(I had checked it to display that through framebuffer with disabled stencil buffer.)
And The final transparent rect. was also rendered well.

I’m worrying about my missing something about Stencil set-up.

I had attached my VC2008 project.

16, //16bit z-buffer
8, //stencil buffer

In general, if you want a stencil buffer, you should also get a 24-bit depth buffer.

glEnable(GL_STENCIL_TEST);

So, what is your stencil test?