Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Here is my code


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

In the rendering loop:

float vertices[]={0.0f,0.0f,0.0f};
//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(, 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


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

share|improve this question
Can you add more of your code? For example Attribute initialization and setting. – zacharmarz Apr 14 '11 at 16:35
I added/changed the code a little – Jonathan Apr 14 '11 at 21:24
You pass only one vertex with coordinates 0,0,0, so it have to draw just one point with these coordinates and also with black color. I don't think, it could give you any other color. Do I understand it wrong? – zacharmarz Apr 15 '11 at 8:23
if gl_PointCoord ranges from 0-1(as it should), the point's red value should range form 0-1 horizontally, and the green value from 0-1 vertically because of this line in the fragment shader: gl_FragColor = vec4(, 0, 1);, but I only get black. – Jonathan Apr 15 '11 at 9:40
When I look at your coordinates: float vertices[]={0.0f,0.0f,0.0f}; You pass just one point, and also draw just one point (glDrawArrays(GL_POINTS, 0, 1);). When you pass your coordinates (0,0,0) in VS, you draw just one pointSprite on screen and it's black colored (the same as your coordinates). I don't know, if pointCoords are somehow transfered over the whole pointSprite. I think, it's only passed from VS. – zacharmarz Apr 15 '11 at 10:29
up vote 1 down vote accepted

Curious. It's working exactly as it should for me. The only real difference is that I'm using an OpenGL 3.2 Core Profile.

Vertex shader:

#version 150

uniform mat4 ProjectionMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ModelMatrix;

in vec3 Position;

void main(void)
   gl_PointSize = 40.0;
   gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1);

Fragment shader:

#version 150

out vec4 FragmentColour;

void main(void)
   FragmentColour = vec4(, 0, 1);
share|improve this answer
this ended up being a driver bug – Jonathan Jul 8 '11 at 17:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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