1
\$\begingroup\$

I am trying to render point sprites with with variable color, but they are all black. Before I added gl_PointSize = 5.0 they had color.

The environment is Android with C++, I believe OpenGL ES 2.0.

I have tried to work from point sprite size and applying color to point sprite, but have had no luck.

Vertex Shader:

precision mediump float;
precision mediump int;
attribute vec4 vertex;
uniform mat4 mvp;
varying vec4 v_color;
void main() {
  gl_Position = mvp*vertex;
  v_color = vertex;
  gl_PointSize = 5.0;
}

Fragment Shader:

precision mediump float;
precision mediump int;
varying vec4 v_color;
uniform sampler2D tex;
void main() {
  //gl_FragColor = vec4(v_color);
  //gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
  //gl_FragColor = texture2D(tex, gl_PointCoord);
  gl_FragColor = vec4(v_color.rgb, texture2D(tex, gl_PointCoord).a);
}

All of the gl_FragColor assignments both commented and active lead to black points.

How do I give these points color?

\$\endgroup\$
0
\$\begingroup\$

Well this is embarasing; due to a unreliable build system I had the correct answer all along. For other running into this here is what the working shader looks like.

Vertex Shader:

precision mediump float;
precision mediump int;
attribute vec4 vertex;
uniform mat4 mvp;
varying vec4 v_color;
void main() {
  gl_Position = mvp*vertex;
  v_color = vertex;
  gl_PointSize = 5.0;
}

Fragment Shader:

precision mediump float;
precision mediump int;
varying vec4 v_color;
uniform sampler2D tex;
void main() {
  gl_FragColor = vec4(v_color.rgb, texture2D(tex, gl_PointCoord).a);
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .