commit 77307eead3c04283b404b463155cfce2f7e6bb06
parent df591f57ff459fcfbe08ea4cbc7335fa448b7a73
Author: Robert Russell <robert@rr3.xyz>
Date: Mon, 26 Aug 2024 20:58:13 -0700
Add gitignore
Diffstat:
2 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1 @@
+main
+\ No newline at end of file
diff --git a/main.c b/main.c
@@ -18,6 +18,7 @@ struct cycle2 {
Vec2 *verts;
};
+// TODO: More format options (not only f32 RGBA)
struct image2 {
usize w, h;
Vec4 *pixels; // Row major order, starting in upper left
@@ -135,6 +136,7 @@ image2_bbox(Quad2 *r, Image2 image) {
}));
}
+// TODO: Support filling collections of cycles (like Postscript), not only one
int
fill(Image2 image, Quad2 src_view, Cycle2 cycle, Vec4 color) {
if (cycle.len < 3) return -1;
@@ -348,13 +350,13 @@ fill(Image2 image, Quad2 src_view, Cycle2 cycle, Vec4 color) {
}
void
-image2_write_farbfeld(FILE *f, Image2 image) {
+write_farbfeld(FILE *f, Image2 image) {
char header[16];
memcpy(header, "farbfeld", 8);
r_writeb32(header + 8, image.w);
r_writeb32(header + 12, image.h);
if (!fwrite(header, sizeof header, 1, f))
- r_fatalf("image2_write_farbfeld: failed to write header");
+ r_fatalf("write_farbfeld: failed to write header");
for (usize i = 0; i < image.h; i++) {
for (usize j = 0; j < image.w; j++) {
@@ -369,24 +371,22 @@ image2_write_farbfeld(FILE *f, Image2 image) {
buf[3] = r_htob16((*p)[3] * (f32)U16_MAX);
if (!fwrite(buf, sizeof buf, 1, f))
- r_fatalf("image2_write_farbfeld: failed to write pixel data");
+ r_fatalf("write_farbfeld: failed to write pixel data");
}
}
}
int
main(void) {
- Vec4 black = { 0.0f, 0.0f, 0.0f, 1.0f };
- Vec4 white = { 1.0f, 1.0f, 1.0f, 1.0f };
+ //Cycle2 cycle = {
+ // .len = 3,
+ // .verts = (Vec2[]){
+ // { 0.0f, 0.0f },
+ // { 1.0f, 0.0f },
+ // { 0.5f, 1.0f },
+ // },
+ //};
- Cycle2 cycle = {
- .len = 3,
- .verts = (Vec2[]){
- { 0.0f, 0.0f },
- { 1.0f, 0.0f },
- { 0.5f, 1.0f },
- },
- };
//Cycle2 cycle = {
// .len = 4,
// .verts = (Vec2[]){
@@ -396,6 +396,19 @@ main(void) {
// { 0.2f, 0.8f },
// },
//};
+
+ Cycle2 cycle = {
+ .len = 6,
+ .verts = (Vec2[]){
+ { 0.1f, 0.1f },
+ { 0.5f, 0.3f },
+ { 0.9f, 0.1f },
+ { 0.8f, 0.9f },
+ { 0.5f, 0.5f },
+ { 0.2f, 0.9f },
+ },
+ };
+
Quad2 cycle_view = {
{ 0.0f, 0.0f },
{ 1.0f, 1.0f },
@@ -406,13 +419,17 @@ main(void) {
.h = 1000,
.pixels = r_ealloc(1000 * 1000 * sizeof(Vec4)),
};
+
+ Vec4 white = { 1.0f, 1.0f, 1.0f, 1.0f };
for (usize i = 0; i < image.h; i++) {
for (usize j = 0; j < image.w; j++)
SET(image.pixels[i * image.h + j], white);
}
- if (fill(image, cycle_view, cycle, black) < 0)
+ f32 a = 1.0f;
+ Vec4 color = { 0.1f * a, 0.6f * a, 0.3f * a, a };
+ if (fill(image, cycle_view, cycle, color) < 0)
r_fatalf("fill error");
- image2_write_farbfeld(stdout, image);
+ write_farbfeld(stdout, image);
}