# optimized rendering for particle system

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

## Recommended Posts

I'm thinking in 3 options (my pseudocode) 1º glbegin(gl_quads) loop in particles: ..glvertex ..gltexcoord glend 2º loop in particles: ..glbegin(gl_trianglestrip) ..glvertex ..gltexcoord ..glend 3º glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, SizeOf(TVector), dst) glEnableClientState(GL_TEXTURE_COORD_ARRAY) glTexCoordPointer(2, GL_FLOAT, SizeOf(TVector), tex) glDrawArrays(GL_QUADS, 0, 2 * 4) It's a 2d particlesystem, and another doubt, on the 3º method, how can i draw the particles rotated?

##### Share on other sites
Quote:
 Original post by arthurprsand another doubt, on the 3º method, how can i draw the particles rotated?

glRotatef

##### Share on other sites
Quote:
Original post by V-man
Quote:
 Original post by arthurprsand another doubt, on the 3º method, how can i draw the particles rotated?

glRotatef

i know, but particles have different angles

[Edited by - arthurprs on July 28, 2008 12:11:08 AM]

##### Share on other sites
Then you either calculate the position/rotation on the CPU before sending the coordinates to the GPU or use a vertex shader/program to calculate position/rotation on the GPU (best option available nowadays).

##### Share on other sites
glBegin is slow slow slow. Draw your particles with vertex arrays (the third method), and if needed manually rotate the particles on the cpu.

##### Share on other sites
Quote:
Original post by arthurprs
Quote:
Original post by V-man
Quote:
 Original post by arthurprsand another doubt, on the 3º method, how can i draw the particles rotated?

glRotatef

i know, but particles have different angles

I would use a vertex shader.
You can pass the angle in radians as a texture coordinate and in the shader, compute a rotation matrix and you can even translate if you submit translation factors as texcoordinates.
The other way is to submit rotation and translation as a uniform array. Submit an index using a texcoord and access the array.

##### Share on other sites
I'm not very experienced on opengl and i have to say that i don't know how to do much of the options you guys talked about :(
i know rotating the vextex on the cpu, but i think this method is not very fast,
can you guys post some snippets of the other ways?

thanks.

ps: sorry my english errors, i'm from brazil

##### Share on other sites
I don't have any code snippets.
I recommend learning some GLSL and then you'll know what to, or ask GLSL related questions. A nice tut site is http://www.lighthouse3d.com/opengl/glsl/

If performance is not an issue, if you aren't rendering several thousand particles, then just stick with doing things on the CPU.

##### Share on other sites
Quote:
 Original post by OrangyTangglBegin is slow slow slow. Draw your particles with vertex arrays (the third method), and if needed manually rotate the particles on the cpu.
As a general statement, glBegin being slow actually depends on a few things, if used in conjunction with Display Lists, the state changes can be compiled as well (Yann L stated this, and I have noted it to be true in some situations), and may infact run slightly faster. I would say that is unlikely to hold with this example (because each particle would have a unique positional update). The expensive part of a particle systems are overdraw and state-update (position, colour, intensity, collision etc.) so design your system to take these into account. My planned system is spread across cores for updates and uses GPU processing and GPU memory residency to speed things up.

[EDIT: if you're using DX10/GL2.1 with ext_gpu_program4, you can use attribute streams or Texture buffer objects to do the particle transform/rotation entirely on the GPU]

##### Share on other sites
after some research i have thinked on 3 ways to render then
witch one will be more suitable?
(i'm not sure if the 2º way is correct (first contact with displaylists))

eachframe:
..eachparticle:
....colorpointer
....texpointer
....{vertexes rotated on cpu}
....vertexpointer
..glDrawArrays

make displaylist
eachframe:
..eachparticle:
....pushmatrix
....rotate
....translate
....calllist
....popmatrix

eachframe:
..eachparticle:
....pushmatrix
....rotate
....translate
....glbegin(gl_trianglestrip)
....
....glend
....popmatrix

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015825
×