15
\$\begingroup\$

I am trying to draw point sprites in OpenGL ES 2.0, but all my points end up with a size of 1 pixel...even when I set gl_PointSize to a high value in my vertex shader.

How can I make my point sprites bigger?

\$\endgroup\$
24
\$\begingroup\$

OpenGL ES 2.0 supports Point Sprites; i use them for particles. Just use glDrawElements with GL_POINTS.

In vertex shader, you set the size with gl_PointSize and use gl_PointCoord in fragment shader for texture mapping.

My vertex shader:

uniform mat4 uMvp;
uniform float uThickness;

attribute vec3 aPosition;
attribute vec2 aTexCoord; 
attribute vec4 aColor;

varying vec4 vColor;

void main() {
    vec4 position = uMvp * vec4(aPosition.xyz, 1.);
    vColor = aColor;
    gl_PointSize = uThickness;
    gl_Position =  position;  
}

My fragment shader:

uniform sampler2D tex0;
varying vec4 vColor;

void main() 
{
   gl_FragColor = texture2D(tex0, gl_PointCoord) * vColor;
}

If you are on Android, you can look my french Tutorial. There is a full project with point sprites.

\$\endgroup\$
1
  • \$\begingroup\$ Don't forget to explicitly specify float precision in fragment shaders - they don't have default float precision and on some drivers such shaders may fail to compile. \$\endgroup\$
    – keaukraine
    Jul 20 '14 at 14:41
1
\$\begingroup\$

Surprisingly, glLineWidth() makes points larger too:

    GLES20.glLineWidth(8); // Make the edges (and points!) thicker
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 38);// 38 is number of my vertexes
\$\endgroup\$
1
  • \$\begingroup\$ You are a hero. Bob bless. \$\endgroup\$
    – netpoetica
    Oct 25 '19 at 2:39
0
\$\begingroup\$

OpenGLES 2.0 does not directly support point sprites. You can either texture your glPoints or manually create a camera-facing and camera-aligned quad centered on a point.

\$\endgroup\$
2
  • 5
    \$\begingroup\$ False. use GL_POINTS and gl_PointSize in vertex shader \$\endgroup\$
    – Ellis
    Aug 3 '11 at 20:39
  • \$\begingroup\$ @Ellis Well he kind of said that. If you look at the link posted it talks about the GL ES 1 part that was deprecated, and how to "texture your glPoints" \$\endgroup\$
    – bobobobo
    Jan 2 '13 at 0:32

You must log in to answer this question.

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