0

Was trying to implement rounded points logic according to this answer:

draw circular points

Followed all the steps as given:

  1. glEnable(GL_PROGRAM_POINT_SIZE);
  2. glDrawArrays(GL_POINTS, 0, 3 );

vertex shader:

#version 460

layout (location=0) in vec3 VertexPosition;
layout (location=1) in vec3 VertexColor;

layout (location=0) out vec3 vColor;

void main()
{
    vColor = VertexColor;

    gl_Position = vec4(VertexPosition,1.0);
    gl_PointSize = 2.0;
}

fragment shader:

#version 460

layout (location=0) in vec3 vColor;
layout (location=0) out vec4 FragColor;

vec2 circCoord = 2.0 * gl_PointCoord - 1.0;

void main() {

    if(dot(circCoord, circCoord) > 1.0){
        discard;
    }
    FragColor = vec4(vColor, 1.0);

}

but for some reason , nothing is being drawn or every fragment is being discarded. If I remove the discard statement in fragment shader I get a square point. What am I doing wrong?

Asonic84
  • 79
  • 6
  • Shouldn't the circCoord calculation be part of the main method? – BDL May 20 '21 at 23:25
  • @BDL tried that too result is same – Asonic84 May 21 '21 at 05:56
  • If I see it right you are not passing circle center to fragment (at least I do not see it, it should be a `flat` variable) and I do not also see you computing distance of fragment to center and deciding according to it ... in respect to radius which I do not see anywhere too. Instead you are using `circCoord = 2.0 * gl_PointCoord - 1.0;` which is just screen position in <-1,+1> range ... I would expect something like `if (length(frag_position-center_position)>radius) discard;` – Spektre May 21 '21 at 07:07
  • @Spektre I did these two changes and now I have rounded points 1. Defined a surface format(Qt5) which was not defined `QSurfaceFormat canvasFormat(QSurfaceFormat::DebugContext); canvasFormat.setDepthBufferSize(24); canvasFormat.setStencilBufferSize(8); canvasFormat.setVersion(4, 6); canvasFormat.setProfile(QSurfaceFormat::CoreProfile); QSurfaceFormat::setDefaultFormat(canvasFormat);` 2. Changed the frag code to this `if(dot(gl_PointCoord-0.5, gl_PointCoord-0.5) > 0.25) discard; else FragColor = vec4(vColor, 1.0);` probably the context – Asonic84 May 21 '21 at 07:19

0 Answers0