Jump to content
  • Advertisement
Sign in to follow this  
xelanoimis

OpenGL 2d vertexes and viewport clipping

This topic is 4296 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

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
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!