I need to create a small clipped window which is a combination of a Rectangle and a Circle and Display objects that fit inside of that window clipping.
GL_SCISSOR_TEST will not work because it is just rectangle.
The only other solution i can find is GL_STENCIL*.
Is there any suggestions on how to make this peculiarly shaped polygon inclusion window can be created?
So are you looking for a different method of creating this clip region, or do you want help using the stencil buffer?
Here is what I’ve got
glStencilFunc(GL_ALWAYS, 0x1, 0x1);
glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE );
glVertex2f(x-20 , y+20);
glVertex2f(x-20 , y-20);
glStencilFunc(GL_EQUAL, 0x1, 0x1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_KEEP);
Am I to understand anything written beyond the last stencilFunc and StencilOp will be written if the StencilBuffer is not 1?
I am drawing that square, then Anything after drawing that square should not show up inside that square.
Sorry, I was in a Rush.
The goal of that code,disregard the glPushAttrib(GL_ALL_ATTRIB_BITS), is to make any sort of shape and make anything I draw appear only in that shape, and not outside of it.
The final product that I will be creating is an inclusion window that is in the shape of a circle/rectangle intersected, and I need a variety of different objects able to surf through that inclusion window without leaving it.
My code as I understand it creates a stencil_buffer setting all values to zero. I then create the square setting all the squares pixels to 1. I think change the stencil to draw if it is not equal to one. For some reason when I draw anything after the end of my code, It continues to draw right past the square and inside of it. This leads me to believe stencil_buffer isn’t functioning properly.
Any help is appreciated,
Two things come to mind:
First, make sure you created your window with a stencil buffer. Call glGet with GL_STENCIL_BITS to check.
Second, you don’t want to write to the stencil buffer after you draw your defining rectangle. Call glStencilMask(0), or use GL_KEEP for all parameters of glStencilOp. (In this case, the first parameter is the important one to get right since you’re using GL_EQUAL.)