Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break up 2d art into triangles using OpenGL

I have 2d character art that will be mapped to a Box2d skeleton. The character's arm, for example, may be 2 physics rectangles connected with a joint at the elbow. Each rectangle will have its own corresponding art sprite. The art for the lower arm will not be completely rectangular. It may be a rectangular png source, but there will be a lot of negative space where the arm isn't necessarily drawn.

My question is what is the best way to break up the 2d art into triangles? Should I treat all flat sprites as a simple rectangle made up of 2 triangles, leaving a lot of alpha space? Or is it best to break up the shape into multiple triangles and try to match the actual shape (possibly with a triangle fan)? What might be some of the advantages/disadvantages of each approach? I will be updating the textures as various things happen to the character.

Here's an illustration of what I'm talking about:

img

(the red square is the physics shape, and the blue lines are possible triangle configurations)

like image 737
Jim B Avatar asked Nov 13 '22 20:11

Jim B


1 Answers

Less geometry is usually better for performance (3rd from the left).

The "exact" triangulation (4th from the left) would be useful for high-fidelity collision-detection (lasers reflecting off a shiny asteroid?).

Be careful with frequent texture updates. glTexSubImage2d() is the way to go.

If your GL implementation supports it you can do asynchronous uploads using PBOs.

like image 151
genpfault Avatar answered Dec 10 '22 03:12

genpfault