Hi

I am trying to implement the Line Stipple in OpenGL because the Line stipple API is deprecated. It is working fine for lines and Polygons but It is not working for Circle. is there any problem with the below shaders? I see the pattern coming up fine for lines and polygons. But not working for circles. But when I zoom in case of circle I see the pattern. Don’t know what is the issue. Please let me know . Thanks in advance.

Below is my code for vertex and fragment shader.

```
vertex shader
const char* vertexShaderSource =
"#version 420 core \n" \
"layout (location = 0)in vec4 aPos; \n" \
"flat out vec3 startPos; \n " \
"out vec3 vertPos; \n " \
"uniform mat4 mvp; \n" \
"void main()\n" \
"{\n" \
" vec4 pos = mvp * vec4(aPos.x, aPos.y, 0.0, 1.0);\n" \
" gl_Position = pos; \n" \
" vertPos = pos.xyz/pos.w; \n" \
" startPos = vertPos; \n" \
"}\n";
Fragment Shader
const char* fragmentShaderSource =
"#version 420 core\n" \
"flat in vec3 startPos;\n" \
"in vec3 vertPos;\n" \
"uniform vec4 my_color;\n" \
"uniform vec2 u_resolution; \n"\
"uniform uint u_pattern;\n" \
"uniform float u_factor; \n" \
"uniform int stipple; \n" \
"out vec4 color;\n" \
"void main()\n" \
"{\n" \
"if (stipple == 1) \n" \
"{ \n" \
"vec2 dir = (vertPos.xy-startPos.xy) * u_resolution/2.0; \n" \
"float dist = length(dir); \n" \
"uint bit = uint(round(dist/u_factor)) & 15U; \n" \
"if((u_pattern & (1U<<bit)) == 0U) \n" \
" discard; \n" \
"} \n" \
"color = my_color;\n" \
"}\n";
Below is the code where I am setting the uniform values.
if (vModel->getLineStipple() > 1 )
{
glUniform1i(stip, 1);
GLint loc_res = glGetUniformLocation(shaderProgram, "u_resolution");
GLint loc_pattern = glGetUniformLocation(shaderProgram, "u_pattern");
GLint loc_factor = glGetUniformLocation(shaderProgram, "u_factor");
GLushort pattern = vModel->getLineStipple();
GLfloat factor = vModel->getStippleFactor();
glUniform1ui(loc_pattern, pattern);
glUniform1f(loc_factor, factor);
glUniform2f(loc_res, _scrWidth, _scrHeight);
}
then draw function
...
switch (vModel->getDrawMode())
{
case 0: //GL_POINTS
//glPointSize(6.0);
glDrawArrays(GL_POINTS, 0, vModel->getVertices().size());
break;
case 1: //GL_LINES
//glEnable(GL_LINE_SMOOTH);
//GLint range[2];
//glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE,range);
glDrawArrays(GL_LINES, 0, vModel->getVertices().size());
break;
case 2: //GL_LINE_LOOP
glDrawArrays(GL_LINE_LOOP, 0, vModel->getVertices().size());
break;
case 3: //GL_LINE_STRIP
glDrawArrays(GL_LINE_STRIP, 0, vModel->getVertices().size());
break;
}
```