Got an iPhone app that could use a particle system? This excerpt from Philip Rideout's iPhone 3D programming introduces you to point sprites.
You may find yourself wanting to render a system of particles that need a bit more pizzazz than mere single-pixel points of light. The first thing that might come to mind is rendering a small alpha-blended quad for each particle. This is a perfectly reasonable approach, but it requires you to come up with the coordinates for two textured triangles at each point.
It turns out the iPhone supports an extension to make this much easier by enabling point sprites. Point sprites are small screen-aligned quads that get drawn at each vertex in a vertex array or VBO. For simplicity, a point sprite uses an entire texture; there’s no need to provide texture coordinates. This makes it a breeze to render particle systems such as the one depicted in Figure 7.15.
For OpenGL ES 1.1, the name of the extension is
GL_OES_point_sprite, and it allows you to make the following function calls:glEnable(GL_POINT_SPRITE_OES); glDisable(GL_POINT_SPRITE_OES); glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE); glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_FALSE);
With OpenGL ES 2.0, point sprites are supported in the core specification rather than an extension. There’s no need to call any of these functions because point sprite functionality is implicit. You’ll see how to use point sprites in both ES 1.1 and ES 2.0 in the upcoming SpringyStars sample.

No comments:
Post a Comment