2

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

enter image description here

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

enter image description here

But when i try to resize the triangle i get this result

enter image description here

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 ?

Vahe
  • 149
  • 1
  • 3
  • 10
  • 1
    My [first attempts where similarly based on triangles and quads](https://stackoverflow.com/a/31423105/2521214) to workaround OpenGL pipeline limitations (however I used distance to curve instead of your approach which is the difference you missing) years back but I ended up with something entirely different and way much more cool/fast/efficient see [rendering 2D cubic curves in GLSL](https://stackoverflow.com/a/60113617/2521214) either use cubics like I do (they better) or downgrade to your quadratics... – Spektre Oct 14 '20 at 10:41

0 Answers0