Drawing a border on a 2d polygon with a fragment shader

All you need are the barycentric coordinates, since you are dealing with triangles. Assign each vertex of the triangle an identity, and then use the hardware’s built-in interpolation between the vertex and fragment stages to figure out the relative distance from each of the vertices in your fragment shader. You can think of the barycentric … Read more

YUV to RGB conversion by fragment shader

I don’t know if you solved your problem. I used your code and I solved in this mode. public class MyRenderer implements Renderer{ public static final int recWidth = Costanti.recWidth; public static final int recHeight = Costanti.recHeight; private static final int U_INDEX = recWidth*recHeight; private static final int V_INDEX = recWidth*recHeight*5/4; private static final int … Read more

How exactly does OpenGL do perspectively correct linear interpolation?

The output of a vertex shader is a four component vector, vec4 gl_Position. From Section 13.6 Coordinate Transformations of core GL 4.4 spec: Clip coordinates for a vertex result from shader execution, which yields a vertex coordinate gl_Position. Perspective division on clip coordinates yields normalized device coordinates, followed by a viewport transformation (see section 13.6.1) … Read more

Draw Quadratic Curve on GPU

For 3 control point Bezier curves I would: use triangles as primitives enlarge control points to include area around curve to avoid artifacts This way is fast and there is no problem to compute A’,B’,C’ from A,B,C and vice versa. If the scale is constant (for example scale=1.25) then the max usable curve thickness<=2.0*min(|control_point-M|)*(scale-1.0). For … Read more