-1

The problem:

There is a parabola on a plane defined by 3 points. Here you can see what it looks like. (this is what I made so far...) : Gif about the process

So I want to fill with a color the inner part of the parabola and with a different color the outer part. From the 3 points I calculate the equation of the parabola.

Gabe
  • 624
  • 8
  • 19

2 Answers2

1

You can draw fullscreen quad.

Pass 3 points(or equation) into fragment shader and check whether fragment is above/below parabola and fill it with desired color.

//Assuming (0,0) is in the middle of the screen:
in vec2 fragmentPosition; //from -1 to 1
uniform vec3 parabola;

void main(void) {

    // a*x^2+b*x+c = 0
    float a = parabola.x;
    float b = parabola.y;
    float c = parabola.z;

    float x = fragmentPosition.x;
    float y = fragmentPosition.y;

    if (a*x*x + b*x + c > y) {
        gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
    } else {
        gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
    }
}

If you want to draw it behind points, use z values for it.

Adrian Krupa
  • 1,877
  • 1
  • 15
  • 24
0

If you don't want to use shaders, then you have to tesselate your screen: take its rectangle, spit it in plainty of thin vertical quads (bottom to top), spit these i, 2 so that their limit is a segment of your curve. Draw the bottom ones with a color, the top ones with another color. Much like figures for numerical integration by trapezes.

Fabrice NEYRET
  • 644
  • 4
  • 16