gl_PointCoord always zero

Posted by Jonathan on Game Development See other posts from Game Development or by Jonathan
Published on 2011-04-14T11:44:41Z Indexed on 2011/06/21 8:31 UTC
Read the original article Hit count: 641

Filed under:
|

I am trying to draw point sprites in OpenGL with a shader but gl_PointCoord is always zero.

Here is my code

Setup:

//Shader creation..(includes glBindAttribLocation(program, ATTRIB_P, "p");)
glEnableVertexAttribArray(ATTRIB_P);

In the rendering loop:

glUseProgram(shader_particles);
float vertices[]={0.0f,0.0f,0.0f};
glEnable(GL_TEXTURE_2D);
glEnable(GL_POINT_SPRITE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
//glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);(tried with this on/off, doesn't work)
glVertexAttribPointer(ATTRIB_P, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays(GL_POINTS, 0, 1);

Vertex Shader:

attribute highp vec4 p;
void main() {
  gl_PointSize = 40.0f;
  gl_Position = p;
}

Fragment Shader:

void main() {
 gl_FragColor = vec4(gl_PointCoord.st, 0, 1);//if the coords range from 0-1, this should draw a square with black,red,green,yellow corners
}

But this only draws a black square with a size of 40. What am I doing wrong?

Edit: Point sprites work when i use the fixed function, but I need to use shaders because in the end the code will be for opengl es 2.0

glUseProgram(0);
glEnable(GL_TEXTURE_2D);
glEnable(GL_POINT_SPRITE);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
glPointSize(40);
glBegin(GL_POINTS);
glVertex3f(0.0f,0.0f,0.0f);
glEnd();

Is anyone able to get point sprites working with shader? If so, please share some code.

© Game Development or respective owner

Related posts about opengl

Related posts about shaders