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.....

  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Nathan Reed Apr 9 '12 at 23:45

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.

  • \$\begingroup\$ 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 ? \$\endgroup\$ – user1010005 Apr 9 '12 at 17:27
  • 1
    \$\begingroup\$ 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... \$\endgroup\$ – notlesh Apr 9 '12 at 17:33
  • \$\begingroup\$ You can set a point sprite with GL_POINTS as well. \$\endgroup\$ – Mick Apr 9 '12 at 17:33
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – kevintodisco Apr 9 '12 at 17:34
  • \$\begingroup\$ @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 \$\endgroup\$ – notlesh Apr 9 '12 at 17:52

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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