Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Quick question : Which is the fastest method to render a large array of 4x4/8x8 particles in opengl ? Currently i spend 2triangles for each one but i think that its slow so i would really like to know if im doing it right.....

share|improve this question
1  
Just a reminder that since this is a performance question, you should measure the performance on your target platform, (a) to be sure it's really expensive enough to be worth worrying about and (b) to test the speedup of any proposed solutions. –  Nathan Reed Apr 9 '12 at 23:45
add comment

2 Answers 2

up vote 5 down vote accepted

You can draw points with OpenGL.

You want to call glDrawArrays() or glDrawElements() with GL_POINTS (instead of GL_TRIANGLE_STRIP or whatever you are using.)

This will draw points to the screen based on the current point size, which you can set via glPointSize(). You can also alias these points, but in my experience not all drivers / hardware supports aliased points.

You can't texture these points; they are just a single color.

share|improve this answer
    
Thanks for the hint.Do you happen to know if i could do the GL_POINT Method with shaders so that i can map a texture to them aswell ? –  user1010005 Apr 9 '12 at 17:27
1  
You can use with shaders, but there is only one vertex for a point (at the center), so you may have a hard time coming up with tex coords. stackoverflow.com/questions/5839095/… looks like it talks a bit about this... –  stephelton Apr 9 '12 at 17:33
    
You can set a point sprite with GL_POINTS as well. –  Mick Apr 9 '12 at 17:33
1  
@user1010005 To texture map with GL_POINTS you could look into GL_POINT_SPRITE_ARB. Also, I'm pretty sure that the points always end up occupying the same number of pixels on the screen, no matter how close or far you are from them. –  ktodisco Apr 9 '12 at 17:34
    
@ktodisco, you can pass in the point size as an attribute. i achieved a decent star effect by doing this. to change the size in the vert shader, you assign the variable gl_PointSize –  stephelton Apr 9 '12 at 17:52
show 1 more comment

In core OpenGL 3.2 and above, geometry shaders are available for use. To give a brief overview, you would only tell OpenGL to draw the points that represent the positions of your particles, and these points would pass through the vertex shader normally, but then when they get to the geometry shader, it constructs the rectangle (out of two tris) by emitting vertices to the next stage of the pipeline. Along with the vertices you can programmatically generate normals and texture coordinates.

Since this is all done in hardware, I'm pretty sure it's the fastest way right now to render point-sprite particles.

share|improve this answer
1  
This is probably a better solution than GL_POINTS, but it won't work for older OpenGL implementations (and OpenGL ES). –  stephelton Apr 9 '12 at 17:36
    
Sounds great but i plan to port my game to android platform :( –  user1010005 Apr 9 '12 at 17:39
2  
@user1010005 Just a tip, you should mention that when you ask the question, so we know what constraints to work with :) –  ktodisco Apr 9 '12 at 17:41
    
I'm a beginner with opengl sorry D: –  user1010005 Apr 9 '12 at 17:43
    
i would LOVE to see the geometry shader made available in OpenGL ES. )= –  stephelton Apr 9 '12 at 17:54
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.