1px line using triangles

Hi,
I have geometry (or fallback vertex only) shader, that generates lines with custom width and pass float uniform into shader.
For lines that are more than 1px thick, it works great. But if I want to draw nonantialliased line with 1px width, it looks ugly, especialy when line is not perpendicular to screen.
Any options ?
Problem is that I have only one definition of some geometry and wants to draw it with different line widths many times
Thank you

it looks ugly

Define ugly. Screen shot please.

[ATTACH=CONFIG]288[/ATTACH]
in 45 degrees rotation the line (created by two triangles) is 2px wide instead of 1px

Hmm, shaders please.


geometry shader line draw function: 
// make thick line
// from : transformed point (by modelviewprojectionmatrix)
// to : trasformed point
// colorfrom : first point color
// colorto : second point color
void makeLine(in vec4 from, in vec4 to, in vec4 colorfrom, in vec4 colorto)
{
// triangle positions
    vec4 position1 = from;
    vec4 position2 = from;
    vec4 position3 = to;
    vec4 position4 = to;
   
    // direction of line
    vec2 line2d = position3.xy - position1.xy;    

    // normalized direction
    vec2 direction = normalize(line2d);
    
    // shift vector
    vec2 vector;

    // make vector perpendicular to line
    vector.x = direction.y / screen.x;
    vector.y = -direction.x / screen.y;    


    // normalizedwidthdiv2 : global variable width normalized from px width to normalized coords
    // vec2 normalizedwidthdiv2 = width / screen;
    // uniform vec2 screen; // screen size in px
    // uniform vec2 width; // width of line in px

    vec2 shift = normalizedwidthdiv2 * vector;

    // shift positions
    position1.xy -= shift;
    position2.xy += shift;
    position3.xy -= shift;
    position4.xy += shift;
    
    // emit triangles
    gl_Position = position1;
    gl_FrontColor = colorfrom;
    EmitVertex();

   gl_Position = position3;
    gl_FrontColor = colorto;
    EmitVertex(); 

    gl_Position = position4;
    gl_FrontColor = colorto;
    EmitVertex();

    EndPrimitive();

    gl_Position = position1;
    gl_FrontColor = colorfrom;
    EmitVertex();

    gl_Position = position2;
    gl_FrontColor = colorfrom;
    EmitVertex(); 

    gl_Position = position4;
    gl_FrontColor = colorto;
    EmitVertex();

    EndPrimitive();
}

Please use [ code ] … [ /code ] blocks. Preserves the indentation. I inserted them for you.

Is it guaranteed that a consumer card can do this with pixel perfect precision?

I guess that makes Dark Photon a mod-and-or-admin then.

So many interesting threads.