|
@@ -299,7 +299,8 @@ OLIVECDEF void olivec_circle(Olivec_Canvas oc, int cx, int cy, int r, uint32_t c
|
|
// TODO: lines with different thiccness
|
|
// TODO: lines with different thiccness
|
|
OLIVECDEF void olivec_line(Olivec_Canvas oc, int x1, int y1, int x2, int y2, uint32_t color);
|
|
OLIVECDEF void olivec_line(Olivec_Canvas oc, int x1, int y1, int x2, int y2, uint32_t color);
|
|
OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color);
|
|
OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color);
|
|
-OLIVECDEF void olivec_triangle3(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t c1, uint32_t c2, uint32_t c3);
|
|
|
|
|
|
+OLIVECDEF void olivec_triangle3c(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t c1, uint32_t c2, uint32_t c3);
|
|
|
|
+OLIVECDEF void olivec_triangle3z(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, float z1, float z2, float z3);
|
|
OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int x, int y, Olivec_Font font, size_t size, uint32_t color);
|
|
OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int x, int y, Olivec_Font font, size_t size, uint32_t color);
|
|
OLIVECDEF void olivec_sprite_blend(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
|
|
OLIVECDEF void olivec_sprite_blend(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
|
|
OLIVECDEF void olivec_sprite_copy(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
|
|
OLIVECDEF void olivec_sprite_copy(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
|
|
@@ -582,8 +583,8 @@ OLIVECDEF void barycentric(int x1, int y1, int x2, int y2, int x3, int y3,
|
|
// u3 = det - u1 - u2
|
|
// u3 = det - u1 - u2
|
|
}
|
|
}
|
|
|
|
|
|
-OLIVECDEF void olivec_triangle3(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3,
|
|
|
|
- uint32_t c1, uint32_t c2, uint32_t c3)
|
|
|
|
|
|
+OLIVECDEF void olivec_triangle3c(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3,
|
|
|
|
+ uint32_t c1, uint32_t c2, uint32_t c3)
|
|
{
|
|
{
|
|
if (y1 > y2) {
|
|
if (y1 > y2) {
|
|
OLIVEC_SWAP(int, x1, x2);
|
|
OLIVEC_SWAP(int, x1, x2);
|
|
@@ -647,6 +648,70 @@ OLIVECDEF void olivec_triangle3(Olivec_Canvas oc, int x1, int y1, int x2, int y2
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+OLIVECDEF void olivec_triangle3z(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, float z1, float z2, float z3)
|
|
|
|
+{
|
|
|
|
+ if (y1 > y2) {
|
|
|
|
+ OLIVEC_SWAP(int, x1, x2);
|
|
|
|
+ OLIVEC_SWAP(int, y1, y2);
|
|
|
|
+ OLIVEC_SWAP(float, z1, z2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (y2 > y3) {
|
|
|
|
+ OLIVEC_SWAP(int, x2, x3);
|
|
|
|
+ OLIVEC_SWAP(int, y2, y3);
|
|
|
|
+ OLIVEC_SWAP(float, z2, z3);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (y1 > y2) {
|
|
|
|
+ OLIVEC_SWAP(int, x1, x2);
|
|
|
|
+ OLIVEC_SWAP(int, y1, y2);
|
|
|
|
+ OLIVEC_SWAP(float, z1, z2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int dx12 = x2 - x1;
|
|
|
|
+ int dy12 = y2 - y1;
|
|
|
|
+ int dx13 = x3 - x1;
|
|
|
|
+ int dy13 = y3 - y1;
|
|
|
|
+
|
|
|
|
+ for (int y = y1; y <= y2; ++y) {
|
|
|
|
+ // TODO: move boundary checks outside of loops in olivec_fill_triangle
|
|
|
|
+ if (0 <= y && (size_t) y < oc.height) {
|
|
|
|
+ int s1 = dy12 != 0 ? (y - y1)*dx12/dy12 + x1 : x1;
|
|
|
|
+ int s2 = dy13 != 0 ? (y - y1)*dx13/dy13 + x1 : x1;
|
|
|
|
+ if (s1 > s2) OLIVEC_SWAP(int, s1, s2);
|
|
|
|
+ for (int x = s1; x <= s2; ++x) {
|
|
|
|
+ if (0 <= x && (size_t) x < oc.width) {
|
|
|
|
+ int u1, u2, det;
|
|
|
|
+ barycentric(x1, y1, x2, y2, x3, y3, x, y, &u1, &u2, &det);
|
|
|
|
+ float z = z1*u1/det + z2*u2/det + z3*(det - u1 - u2)/det;
|
|
|
|
+ OLIVEC_PIXEL(oc, x, y) = *(uint32_t*)&z;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int dx32 = x2 - x3;
|
|
|
|
+ int dy32 = y2 - y3;
|
|
|
|
+ int dx31 = x1 - x3;
|
|
|
|
+ int dy31 = y1 - y3;
|
|
|
|
+
|
|
|
|
+ for (int y = y2; y <= y3; ++y) {
|
|
|
|
+ if (0 <= y && (size_t) y < oc.height) {
|
|
|
|
+ int s1 = dy32 != 0 ? (y - y3)*dx32/dy32 + x3 : x3;
|
|
|
|
+ int s2 = dy31 != 0 ? (y - y3)*dx31/dy31 + x3 : x3;
|
|
|
|
+ if (s1 > s2) OLIVEC_SWAP(int, s1, s2);
|
|
|
|
+ for (int x = s1; x <= s2; ++x) {
|
|
|
|
+ if (0 <= x && (size_t) x < oc.width) {
|
|
|
|
+ int u1, u2, det;
|
|
|
|
+ barycentric(x1, y1, x2, y2, x3, y3, x, y, &u1, &u2, &det);
|
|
|
|
+ float z = z1*u1/det + z2*u2/det + z3*(det - u1 - u2)/det;
|
|
|
|
+ OLIVEC_PIXEL(oc, x, y) = *(uint32_t*)&z;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// TODO: AA for triangle
|
|
// TODO: AA for triangle
|
|
OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color)
|
|
OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color)
|
|
{
|
|
{
|