Stencil buffer as viewport.

I have a small viewport wich i want to reshape from a square to a circle.
I mean the small viewport on the bottom right of this screenshot:

I was planning to use the stencil buffer to not draw outside the viser, using the following code:

if (view->IS_STENCIL){

	glStencilFunc(GL_ALWAYS, 1, 1);
} else if (view->USES_STENCIL){
	glStencilFunc(GL_EQUAL, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
} else {

and another viser picture:

First, the big viewport is drawn, doing nothing with stenciling. Then a view is drawn using view->IS_STENCIL with the last viser-image. Then the other underlying viewports under the viser are drawn.

The problem is, it just does not work for a bit. It just slows down everything to 1 fps…
Can someone help me with this? know a good tutorial or a hint?.

As far as it slowing things down to 1 FPS, that sounds like it is falling back to software stencil. This usually happens when in 16 bit color mode, with NVIDIA hardware. Try running in 32 bit color mode.

No, i use 32 bits mode.

It still sounds like software stencil is being used. Check your GL_RENDERER and GL_VENDOR strings.

Post up your pixel format description setup code. Perhaps you’re trying to use more than 8bits of stencil?

The stencil problem is still not solved, but that was the speed problem, it now is 40 fps instead of 80 fps, that is reasonable slower i think.
This is my pfd now:

static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
	1,											// Version Number
	PFD_DRAW_TO_WINDOW |						// Format Must Support Window
	PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
	PFD_DOUBLEBUFFER,							// Must Support Double Buffering
	PFD_TYPE_RGBA,								// Request An RGBA Format
	bits,										// Select Our Color Depth
	0, 0, 0, 0, 0, 0,							// Color Bits Ignored
	0,											// No Alpha Buffer
	0,											// Shift Bit Ignored
	0,											// No Accumulation Buffer
	0, 0, 0, 0,									// Accumulation Bits Ignored
	16,											// 16Bit Z-Buffer (Depth Buffer)
	8,											// No Stencil Buffer
	0,											// No Auxiliary Buffer
	PFD_MAIN_PLANE,								// Main Drawing Layer
	0,											// Reserved
	0, 0, 0										// Layer Masks Ignored

Try 24 bit z.

If you are having problems with Stencil, and performance is being degraded as much as it appears to be, you could take another approach if you wish, one that doesn’t depend on having hardware stencil buffer support at all.

You could just construct a “donut” of 20 or 30 transparent tri’s , before rendering your inset, and after having rendered the main scene. Sets it Z appropriately and it will give you the effect your after. It will also have a negligible effect on your scene performance.

Just an Idea.


I like heath’s idea.

There is a trick you can use when requesting z bits.

Set z bits to 1 that way it’ll give you the most it can within the bounds of your other requests, you might also want to try this with stencil. Being too explicit about your requirements can spell doom for your visual, especially if you don’t have more complex code that falls back to lower specifications.

Also, it is a good idea to check the pixel format you actually get from ChoosePixelFormat, as it may not match exactly what you request. And may even make a match that isn’t desired, such as choosing 16 bit z over 24 bit.

Yes, that is the solution, i am getting tired of getting that slow stencil to work. I go for the invisible shape solution since i don’t know how to manipulate the z-buffer. Right now i go for the easy and fast way, later i will look at the z-buffer solution for an alternative if needed.

thank u very mutch for ur help.