From 6477319da461ad78a120a3c777228eaa8194c9f8 Mon Sep 17 00:00:00 2001 From: rodri Date: Mon, 29 Jun 2020 18:28:02 +0000 Subject: bring flat triangle rasterization back, with some goodies for future shading work. add uv coordinates to the vertex. --- graphics.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'graphics.h') diff --git a/graphics.h b/graphics.h index 44f213d..8e63b67 100644 --- a/graphics.h +++ b/graphics.h @@ -8,6 +8,7 @@ typedef struct Vertex Vertex; typedef struct Framebuffer Framebuffer; typedef struct Viewport Viewport; typedef struct Camera Camera; +typedef struct Triangle Triangle; struct Color { @@ -19,6 +20,7 @@ struct Vertex Point3 p; /* position */ Point3 n; /* surface normal */ Color c; /* shading color */ + Point2 uv; /* texture coordinate */ }; struct Framebuffer @@ -47,6 +49,11 @@ struct Camera Projection ptype; }; +struct Triangle +{ + Point p0, p1, p2; +}; + /* Camera */ void configcamera(Camera*, Image*, double, double, double, Projection); void placecamera(Camera*, Point3, Point3, Point3); @@ -64,5 +71,12 @@ Point toviewport(Camera*, Point3); Point2 fromviewport(Camera*, Point); void perspective(Matrix3, double, double, double, double); void orthographic(Matrix3, double, double, double, double, double, double); +/* temporary debug helpers */ void line3(Camera*, Point3, Point3, int, int, Image*); Point string3(Camera*, Point3, Image*, Font*, char*); + +/* triangle */ +Triangle Trian(int, int, int, int, int, int); +Triangle Trianpt(Point, Point, Point); +void triangle(Image*, Triangle, int, Image*, Point); +void filltriangle(Image*, Triangle, Image*, Point); -- cgit v1.2.3