I’m trying and failing to use point sprites with GLSL. For some reason the values in gl_PointCoord seem random.
Here are my shaders:
Vertex:
#version 120
uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;
uniform float point_size;
attribute vec3 a_Vertex;
void main(void)
{
vec4 pos = modelview_matrix * vec4(a_Vertex, 1.0);
gl_PointSize = point_size;
gl_Position = projection_matrix * pos;
}
Fragment:
#version 120
uniform sampler2D texture0;
void main(void) {
gl_FragColor = texture2D(texture0, gl_PointCoord);
}
This looked like it was just sampling the texture randomly… a bit like static on a TV screen (the texture was black and white so it looked exactly like that).
So what I decided to try was output the ‘s’ coordinate of gl_PointCoord as the red component of the output color. Instead of a smooth gradient as I was expecting (as ‘s’ increases from zero to one) it again looked like static (albeit red this time).
I’m stumped. The spec says:
The values in gl_PointCoord are two-dimensional coordinates indicating where within a point primitive the current fragment is located, when point sprites are enabled. They range from 0.0 to 1.0 across the point. If the current primitive is not a point, or if point sprites are not enabled, then the values read from gl_PointCoord are undefined.
Point sprites are definitely enabled and the primitive is definitely a point.
Here’s my rendering code anyway:
glEnable(GL_POINT_SPRITE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); glDrawArrays(GL_POINTS, 0, positions.size());
Does anyone have any clue as to what I’m doing wrong?