views:

203

answers:

2

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?

+1  A: 

You can use a texture and alpha blending: the texture would contain a transparent triangle. See this tutorial on blending.

EDIT: Of course alpha blending doesn't change the geometry. For that you need to perform treatments that are more complicated. See this tutorial on realtime CSG.

Reference: Constructive Solid Geometry

Gregory Pakosz
+1  A: 

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.

Kornel Kisielewicz
I've got the tesselator working to my needs, thank you. If anyone reading this needs help with it, email me ([email protected]) and I'll send you the code I've used. I thought it would be a pretty common openGL problem.