How can I vary the point size in OpenGL glBegin(GL_POINTS)?

max picture max · Jan 4, 2011 · Viewed 25k times · Source

Is there any way to vary the point size when drawing lots of points? I know there's the glPointSize(float), but is there a way to do it in a 'batch' or array?

I would like the points to have different sizes based on an attribute of the data. Such as each point having x, y, z, and a size attribute. I'm using frame buffers right now in java.

Could I possibly use vertex shaders for this?

Answer

tibur picture tibur · Jan 4, 2011

You can use point sprite: enable it using glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); and then you can use gl_PointSize attribute in your vertex program.

Vertex shader example taken from an OpenGL discussion thread:

void main() {
    gl_FrontColor=gl_Color;
    gl_PointSize = gl_Normal.x;
    gl_Position = ftransform();
}