I was wondering how can I draw curves using a triangle, so I ended up reading these 2 articles. http://commaexcess.com/articles/6/vector-graphics-on-the-gpu http://www.mdk.org.pl/2007/10/27/curvy-blues
As I understand it correctly, the hardware interpolates u and v across three vertices.
Here is my result
My coordinates for the triangle
vec![100.0, 100.0
100.0, 100.0,
200.0, 100.0];
UV coordinates
vec![0.0, 0.0
0.5, 0.0
1.0, 1.0]
My fragment shader looks like this
#version 430 core
out vec4 frag_color;
in vec2 uv;
in vec4 cords;
void main() {
float x = uv.x;
float y = uv.y;
float result = (x*x) - y;
if(result > 0.0) {
frag_color = vec4(1.0, 0.1, 0.5, 1.0);
} else {
frag_color = vec4(2.0, 0.2, 3.0, 1.0);
}
}
I would like to have a good stroke at the middle point. I tried the following.
if(result > 0.01) {
frag_color = vec4(1.0,0.1,0.5, 1.0);
} else if(result < -0.01) {
frag_color = vec4(2.0,0.2,1.0, 1.0);
} else {
frag_color = vec4(2.0, 0.2, 3.0, 0.0); // mid point
}
I got this
But when i try to resize the triangle i get this result
The stroke width is thicker, but I want to keep the width in the previous image. I have no idea how to achieve this, is it even possible ?