I am calculating the final on-screen projected values in the vertex shader like so:
vec4 projectedpos = mvpmatrix * vec4(in_Position, 1.0); FinalPos = vec2(projectedpos.xy) / projectedpos.w; FinalPos = (FinalPos * 0.5 + 0.5) * vec2(Viewportwidth,Viewportheight); gl_Position = projectedpos;
Then, in the fragment shader:
if(truncate(FinalPos.x+0.5) == 10) out_Color = vec4(1.0,0.0,0.0,1.0);
FinalPos is an out variable to the vertex shader, and in to the fragment. ViewportWidth and ViewportHeight are obivously uniforms providing the window width and window height.
This should give me a vertical line at x=10. I dont see a straight line. The line seems to ‘jitter’ around x=10, i.e, often it will draw a red dot at x=11, or not draw one at all.
if(truncate(FinalPos.x) == 10) out_Color = vec4(1.0,0.0,0.0,1.0);
This is better, but its still not a completely straight line.
I had this working when I used ftransform(), but in Opengl 3 it refuses to work. I also tried an ‘invariant’ for gl_Position, but nope…