Sign in to follow this  
xelanoimis

OpenGL 2d vertexes and viewport clipping

Recommended Posts

Hi, I use 2d vertexes (xy) to draw 2d stuff and I was curious if I can use the viewport setting for fast 2d clipping instead of clipping the geometry myself (which may be tricky for triangles or random lines). Ortho2d projection is used. For example, I have a screen of 640x480 and I want to set a viewport half of it, in the middle (x=160,y=120,w=320,h=240). Then if I move a sprite arround the screan (from 0 to 640) I expect it to be visible only when crossing the middle area I set as viewport. I see that it works in DirectX, but I just want to be sure it works on any hardware, and OpenGL does always clip those 2d coordinates with the viewport rect. So if anyone knows if this procedure of clipping 2d vertexes with the viewport is ok to use, or it just works on some video cards, please let me know. Thanks

Share this post


Link to post
Share on other sites
Clipping can be done with either the viewport or scissor test (glScissor). The scissor test just confines drawing to a screen aligned rect, whereas changing the viewport also changes how your scene is projected to the screen.

Be aware that the clipping isn't pixel perfect - it's done at a primative level. Usually this is the same thing, but some drawing operations can still draw outside the clipping rect (eg. wide lines may have their end points unclipped but actual rasterisation may draw outside).

Clipping is GL1.1 so it works everywhere, which is nice. If you need pixel-accurate clipping, or clipping of funny shapes then the stencil buffer would probably be a better idea.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this