Search code examples
openglshapescut

OpenGL, remove sections from a shape


In OpenGL, how can one cut a triangle shaped hole from a square? making the hole transparent.

I'm also using SDL, maybe it can be achieved with an SDL surface?


Solution

  • While doing it on a texture is truly the easier way out, if you need it to be a real shape, you might try using the GLUtesselator from GLU toolkit. See a tutorial for it here.

    General usage is that you create a tesselator object, create two contours (the outer and the inner in a reverse direction) and the tesselator translates that into pure OpenGL commands. Of course if it's efficiency you're seeking you should implement or find some higher order system that operates on vertex buffers.