#### Archived

This topic is now archived and is closed to further replies.

# Best method to render particles in gl?

This topic is 6312 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I was just looking over some demo src for a simple particle engine in gl and was wondering if this is the most eff. method. Every time a particle is rendered, the code calls glPushMatrix(), then glPopMatrix() too restore the identity values. However, it would seem to me that you could simply reverse the calls, like this:
  glRotate( .. pos vec ..); glTranslate( .. pos vec .. ); // draw it here glTranlaste ( .. neg vec .. ); glRotate ( .. neg vec .. ); 
Would this be faster or slower than the above method? or should I just test it and see... ? Thanks, Jason

##### Share on other sites
well, you''d have to send the data over the BUS again... with pushing and popping you don''t pass any parameters (popping) and i guess it''s pretty much optimised in the drivers so it shouldn''t be to slow :o)

cya,
Phil

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

##### Share on other sites
I found a much better method on http://nate.scuzzy.net/. Basically, you take the camera matrix, extract the "up" and "right" vectors from it, and then ue those to draw each particle, so say you have a particle at P, of size 2 * s. You draw it like this:

  Vector a( P + (up * s) + (right * s) );Vector b( P - (up * s) + (right * s) );Vector c( P - (up * s) - (right * s) );Vector d( P + (up * s) - (right * s) );// now render the quad a,b,c,d with the normal modelview matrix and everything

You don''t need to change any matrices at all. It does require you to read the camera matrix, but you only do that once, and then you can render all 10,000 particles like that.

Technically, it''s not quite right, because all the particles will be on a plane, and not on a sphere around the camera, but I found that it''s really not noticable... unless you''ve got an unusually high field of view.

War Worlds - A 3D Real-Time Strategy game in development.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
12

• 9
• 21
• 13
• 9
• 17
• ### Forum Statistics

• Total Topics
632608
• Total Posts
3007391

×