2d vertexes and viewport clipping

Started by
1 comment, last by xelanoimis 17 years, 1 month ago
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
Advertisement
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.
I only have simple colored and textured 2d triangles so I guess they will be clipped ok.
Thanks!

This topic is closed to new replies.

Advertisement