Jump to content
  • Advertisement
Sign in to follow this  

Rendering inside an irregular area e.g. country boundary

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

I want to render the terrain map along with some other graphics inside the Canadian country boundary, the part of the terrain map that is outside Canada is designed to be discarded. The geographic data is available. How can I do this? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
It'd be useful to know what format your data is in.

Assuming it's some sort of grid bitmap (e.g. for each 'pixel' of your data, you can query whether it's canada or not) , you can turn that into a outline using the 'marching squares' algorithm. This can result in a vector representation of the country (perhaps that's what you're starting with, in which case you can skip the marching squares step).

Now it sounds like you want to triangulate this outline so you draw it as a solid filled polygon. For this your best bet might be 'ear clipping'.

Marching squares and ear clipping are well documented algorithms, so rather than detail them, you can just google them.

Share this post


Link to post
Share on other sites
Thanks for your quick response, C0lumbo.
Our Canada country boundary is just an array of points and we draw the boundary as a polygon (GL_POLYGON). Using marching squares and ear clipping algorithm may be an overkill. Our preliminary method is to create a mask that mask out all graphics outside the polygon. But we are not sure whether OpenGL provides such mechanism.

Share this post


Link to post
Share on other sites
Look up the stencil buffer and test. You would render the country with writing to the stencil buffer, after that everything else would render to the screen with stencil test on (render only pixels, where a stencil flag has been set).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!