Issue large circular dots in modern OpenGL

I want to display filled circles of a dynamically changing radius around a set of points whose 2D coordinates are stored in VBO. So far I have used GL_POINT_SMOOTH, but now, switching to OpenGL 4.0, this option is no longer available. I saw a similar question here , but it doesn’t quite match my need, because the centers of the circles in this example are hardcoded in the fragment shader. How should I do it?

At the moment, my vertex shader looks like this:

#version 400

layout(location=0) in vec2 in_Position;
layout(location=1) in vec4 in_Color;
out vec4 ex_Color;

uniform vec4 bounds;

void main(void){
    float x = -1+2/(bounds.y-bounds.x)*(in_Position.x-bounds.x);
    float y = -1+2/(bounds.w-bounds.z)*(in_Position.y-bounds.z);
    gl_Position = vec4(x,y,0,1);
    ex_Color = in_Color;
}

And my fragment shader looks like this:

#version 400

in vec4 ex_Color;
out vec4 out_Color;

void main(void){
    out_Color = ex_Color;
}

With these shaders I get square dots.

+4
source share
1 answer

"" :

  • :

    glEnable(GL_PROGRAM_POINT_SIZE);
    
  • GL_POINTS.

  • gl_PointSize :

    gl_Position = ...;
    gl_PointSize = ...;
    

    , , , , , , .

  • , gl_PointSize. gl_PointCoord, . , [0, 1] .

    , , , :

    outColor = texture(particleTex, gl_PointCoord);
    

    , , :

    vec2 circCoord = 2.0 * gl_PointCoord - 1.0;
    if (dot(circCoord, circCoord) > 1.0) {
        discard;
    }
    

    , , .

, . :

GLfloat sizeRange[2] = {0.0f};
glGetFloatv(GL_POINT_SIZE_RANGE, sizeRange);
+11

All Articles