diff options
author | rodri <rgl@antares-labs.eu> | 2020-03-04 21:03:21 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2020-03-04 21:03:21 +0000 |
commit | a435467f81a1d9d429109f3a34988c642bed6035 (patch) | |
tree | fe1d314e5c9981f4b087ce4990bbe1ea6c3082df /libgraphics | |
parent | 3e0fe77fe3832b4c4eb7abe9c16088d9ff08f7bc (diff) | |
download | 3dee-a435467f81a1d9d429109f3a34988c642bed6035.tar.gz 3dee-a435467f81a1d9d429109f3a34988c642bed6035.tar.bz2 3dee-a435467f81a1d9d429109f3a34988c642bed6035.zip |
first steps towards a general rendering architecture.
Diffstat (limited to 'libgraphics')
-rw-r--r-- | libgraphics/render.c | 27 | ||||
-rw-r--r-- | libgraphics/triangle.c | 43 |
2 files changed, 13 insertions, 57 deletions
diff --git a/libgraphics/render.c b/libgraphics/render.c index f4e4c0f..ddc0663 100644 --- a/libgraphics/render.c +++ b/libgraphics/render.c @@ -4,16 +4,6 @@ #include "../geometry.h" #include "../graphics.h" -/* - * careful with concurrent rendering. - * use a lock or embed on each routine. - */ -static RFrame imgrframe = { - 0, 0, 1, /* p */ - 1, 0, 0, /* bx */ - 0, -1, 0 /* by */ -}; - /* requires p to be in NDC */ int isclipping(Point3 p) @@ -51,17 +41,26 @@ Point toviewport(Camera *c, Point3 p) { Point2 p2; + RFrame rf = { + c->viewport->r.min.x, c->viewport->r.max.y, 1, + 1, 0, 0, + 0, -1, 0 + }; - imgrframe.p = Pt2(c->viewport->r.min.x, c->viewport->r.max.y, 1); - p2 = invrframexform(flatten(c, p), imgrframe); + p2 = invrframexform(flatten(c, p), rf); return (Point){p2.x, p2.y}; } Point2 fromviewport(Camera *c, Point p) { - imgrframe.p = Pt2(c->viewport->r.min.x, c->viewport->r.max.y, 1); - return rframexform(Pt2(p.x, p.y, 1), imgrframe); + RFrame rf = { + c->viewport->r.min.x, c->viewport->r.max.y, 1, + 1, 0, 0, + 0, -1, 0 + }; + + return rframexform(Pt2(p.x, p.y, 1), rf); } void diff --git a/libgraphics/triangle.c b/libgraphics/triangle.c deleted file mode 100644 index b598855..0000000 --- a/libgraphics/triangle.c +++ /dev/null @@ -1,43 +0,0 @@ -#include <u.h> -#include <libc.h> -#include <draw.h> -#include "../geometry.h" -#include "../graphics.h" - -Triangle -Trian(int x0, int y0, int x1, int y1, int x2, int y2) -{ - return (Triangle){Pt(x0, y0), Pt(x1, y1), Pt(x2, y2)}; -} - -Triangle -Trianpt(Point p0, Point p1, Point p2) -{ - return (Triangle){p0, p1, p2}; -} - -void -triangle(Image *dst, Triangle t, int thick, Image *src, Point sp) -{ - Point pl[4]; - - pl[0] = t.p0; - pl[1] = t.p1; - pl[2] = t.p2; - pl[3] = pl[0]; - - poly(dst, pl, nelem(pl), 0, 0, thick, src, sp); -} - -void -filltriangle(Image *dst, Triangle t, Image *src, Point sp) -{ - Point pl[4]; - - pl[0] = t.p0; - pl[1] = t.p1; - pl[2] = t.p2; - pl[3] = pl[0]; - - fillpoly(dst, pl, nelem(pl), 0, src, sp); -} |