Clipping in 2D

Started by
2 comments, last by Ziphnor 21 years, 8 months ago
Im trying to create a 2d game using SDL/OpenGL. When drawing my GUI components i would very much like to limit the components to only draw inside itself, anything drawn outside by the component being clipped(and the component probably adding a scroll bar). I was wondering how best to do this automaticly, using the clipping ability of OpenGL. My projection is set using glOrtho so that 1 unit = 1 pixel. I was considering somehow adding some clip planes using glClipPlane, but im not quite sure it will end up correct, because it seems to me that such planes would have to run non-parallel to the view volumens side clipplanes(because other wise they wouldnt clip anything would they? Or perhaps the orthogonality applies to them too) and if they do that they might clip stuff drawn below z = 0(while i dont use perspective i do plan to use z-axis for depth testing some things in my isometric world). Or perhaps i could just call glOrtho with different side planes. Another option seems to change the viewport, draw the component, then change it back again. Well, if anyone actually understand anything of these rambling and know how one usually deal with this, i would much appreciate a hint on which approach would be best(or perhaps i should say which approach *works*). If this is somehow an idiotic question, feel free to tell me so EDIT: It seems it can be done with glViewport, but then things are scaled, and the coordinate system is changed to the top left of the new viewport(this is actually quite nice since my components dont have their abs position, only the position inside their parent component). It seems kind of clumsy though.... [edited by - ziphnor on July 25, 2002 10:55:04 AM]
Advertisement
Have you tried "gluPickMatrix". It says "The gluPickMatrix function creates a projection matrix you can use to restrict drawing to a small region of the viewport."
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>
Thanks, that sounds like exactly what i am looking for!
Can''t try it out right now but it seems safe to say : problem solved!

I really did try to find such a function myself, but i must admit it never crossed by mind that it might be called something like that(i searched and searched for clipping

How did you find it?
I ran across it reading the OpenGL section of the Microsoft Platform SDK docs. When I read your question I sort of remembered there was a function that did what you wanted, though I did have to look around for it because all I remembered about the name was it had something to do with selection (or something like that). Anyway, I hope it helps.
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>

This topic is closed to new replies.

Advertisement