How can I vary the point size in OpenGL glBegin(GL_POINTS)?
Is there开发者_如何学JAVA 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?
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();
}
This was what I ever did,
//reset
glLoadIdentity();
//set size to 1 for a group of points
glPointSize(1);
//group #1 starts here
glBegin(GL_POINTS);
//color of group #1 is white
glColor3f(1,1,1);
for(int a=0; a<x; a++)
for(int b=0; b<y; b++)
glVertex3f(a/953.,-b/413.,0.); //location of points
glEnd();
//set size to 5 for another group of points
glPointSize(5);
//group #2 starts here
glBegin(GL_POINTS);
//color of group #2 is red
glColor3f(1,0,0);
for(unsigned long int a=0; a<jd; a++)
{
glVertex3f(data[a].i,data[a].j,0);
}
glEnd();
I believe it's with glPointSize(GLfloat size)
Source:
http://www.talisman.org/opengl-1.1/Reference/glPointSize.html
With GL_POINT_DISTANCE_ATTENUATION
(GL14?) you can set the coefficients for a function (I think it's quadratic) for computing point size from Z distance.
Increasing and decreasing the point size affects more than one pixel, but shaders are meant to be run only once per pixel. It will fail, because once the shader program has been run for a particular pixel, can the change only affect the following pixels, but not the previous pixels.
Shader programs are run on many shader units simultaneously and for many pixels in parallel making it impossible to do what you are trying to do. The limitation will be that one can set the pixel size with a shader program, but it will keep its size for all pixels the shader program gets run.
You could try to sort your point data by size and group points of the same size into one array and draw each array with a different point size.
Or you could try doing it with an indirection where you first render the different point sizes into a texture and in a second pass render the pixels by accessing the texture data and using it to test if a pixel should be rendered (or not).
精彩评论