I\'m trying to draw a triangle using an OpenGL fragment shader.
I succeeded in drawing a circle but I have a problem with handling the equation/logic or the code to draw
Hope you are rendering QUAD covering the view/screen...
The fragment shader friendly way of rendering triangle is to:
compute barycentric s,t coordinates of fragment
go for the matrix approach as you got mat3,vec3
in GLSL ...
decide if it is inside or outside
simply by testing s+t<=1.0
then set output color or discard;
however discard is not an option for you as you got more shapes...
So compute:
--------------------------------------------------------
| s | | (p1.a - p0.a) , (p2.a - p0.a) , p0.a | | p.a |
| t | = inverse | (p1.b - p0.b) , (p2.b - p0.b) , p0.b | * | p.b |
| 1 | | 0 , 0 , 1 | | 1 |
------------------------------------------------------------------
if (s+t<=1.0) set output color
You can also use the s,t
for texturing (even procedural one).