I am programming my own 2D graphics library with OpenGL, and I am at the stage where I have a container control that can contain graphic elements (like a rounded rectangle or an asterisk) and other child controls ... etc. I am trying to pin the rendering of child controls and graphic elements to a parent control. Therefore, if the child control overflows the boundaries of the containers, it is not displayed.
My first idea was to use a "scissor test" after finding it while searching the web. But the problem is that I am limited to rectangular cropping, and I want to be able to pin content in an arbitrary area, like a star polygonal shape.
I have an idea...
When it comes to drawing a control and its graphic elements, I see if my control should crop its contents or not. If so, I paint it with a uniform white color on a black background in a non-standard texture. Then I send it to the shader program. Therefore, I create each child element (controls and graphic elements) with an activated shader. In this fragment, the shader for each fragment, I think, is looking at the same coordinate in a special texture that has passed earlier. If the fragment in the special texture is white, I can display this fragment because it is in the visible region.
Do you think this might work? Is this a good idea or is there a better one?
source share