summaryrefslogtreecommitdiff
path: root/libgraphics
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-03-04 21:03:21 +0000
committerrodri <rgl@antares-labs.eu>2020-03-04 21:03:21 +0000
commita435467f81a1d9d429109f3a34988c642bed6035 (patch)
treefe1d314e5c9981f4b087ce4990bbe1ea6c3082df /libgraphics
parent3e0fe77fe3832b4c4eb7abe9c16088d9ff08f7bc (diff)
download3dee-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.c27
-rw-r--r--libgraphics/triangle.c43
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);
-}