Rendering inside an irregular area e.g. country boundary

Started by
2 comments, last by Ashaman73 11 years, 4 months ago
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.
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.
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.
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).

This topic is closed to new replies.

Advertisement