Archived

This topic is now archived and is closed to further replies.

Clipping in 2D

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites