I’m using glScissor() in my application and it works properly, but I met a problem:
I have my Window object for which drawing area is specified by glScissor() and inside this area, I’m drawing my ListView object for which the drawing area should also be specified with glScissor() as I don’t want to draw it all.
In a code I could represent it as:
Window::draw()
{
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, width, height);
// Draw some components...
mListView.draw(); // mListView is an object of ListView type
glDisable(GL_SCISSOR_TEST);
}
ListView::draw()
{
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, width, height);
// Draw a chosen part of ListView here
glDisable(GL_SCISSOR_TEST);
}
But of course in this situation enable/disable calls are wrong:
glEnable(GL_SCISSOR_TEST);
glEnable(GL_SCISSOR_TEST);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_SCISSOR_TEST);
If I remove those internal glEnable/glDisable calls (the ones in ListView), I would anyway end up with two glScissor() calls which also seems to be wrong.
EDIT
I would like to somehow achieve both scissor effects, I mean – that Window should draw only in it’s scissored area and internal ListView also only in it’s scissored area.
As you can see in a picture, with red rectangle I have marked scissor area for Window which WORKS, and with a blue rectangle I marked an area on which I’d like to draw my ListView. That’s why I was trying to use nested scissors, but I know it was useless. So basically my question is, what could be the best approach to achieve this?

Since OpenGL is a state machine and the scissor rect, like any other state, is overwritten when calling
glScissorthe next time, you have to properly restore the window’s scissor rect after drawing the list view. This can either be done by just letting the window manage it:But it might be more flexible to let the individual components restore the scissor state themselves, especially if used in such a hierarchical manner. For this you can either use the deprecated
glPush/PopAttribfunctions to save and restore the scissor rect:Or you save and restore the scissor state yourself:
This can of course be automated with a nice RAII wrapper, but that is free for you to excercise.