Jump to content

How to Render Confetti, Fireworks, and More with OpenGL ES

0
  adfm's Photo
Posted Jun 02 2010 03:56 PM

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.

Figure 7.15. Point sprites

Attached Image

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.

Cover of iPhone 3D Programming
Learn more about this topic from iPhone 3D Programming. 

Do you have a great idea for a graphics-intensive iPhone or iPad application, but don't know how to bring it to life? This book offers the perfect solution: a crash course on the OpenGL graphics library with an overview of iPhone 3D development. Whether you're an experienced OpenGL developer looking to build iPhone apps for the first time, or an iPhone developer wanting to learn sophisticated graphics, iPhone 3D Programming addresses both in one concise, easy-to-use guide.

Learn More Read Now on Safari


Tags:
0 Subscribe


0 Replies