c++ - Odd OpenGL fragment shader behavior with gl_PointCoord -
i'm trying draw 2 dimensional line has smooth gradient between 2 colors. application allows me click , drag, first point of line segment first click point, sec point of line follows mouse cursor position.
i have line drawing using gldrawarrays(gl_lines, 0, points.size());, points 2 index array of points.
the line draws fine, clicking , dragging move line around works, i'm having explainable behavior fragment shader:
uniform vec4 color1; //color @ p1 uniform vec4 color2; //color @ p2 out vec4 fragcolor; void main() { //average fragment positions float weight = (gl_pointcoord.s + gl_pointcoord.t) * 0.5f; //weight first , sec color fragcolor = (color1 * weight) + (color2 * (1.0f - weight)); } color1 red, color2 green.
as drag line around bounces between exclusively red, exclusively green, gradient desire, or solid mixture of reddish , greenish on every screen redraw.
i suspect i'm using gl_pointcoord incorrectly, can't inspect values they're in shader.i tried next in shader:
fragcolor = (color1 + color2) * 0.5f; and gives stable yellowish color, have confidence colors stable between redraws.
any tips?
gl_pointcoord defined point primitves. using gl_lines undefined behavior , never going work.
if want smooth gradient, should add together weight attribute line vertices , set 0 or 1 start , end points, respectively.
c++ opengl glsl vector-graphics freeglut
No comments:
Post a Comment