feat: add rasterization primitives

This commit is contained in:
2026-03-04 15:41:20 +05:30
parent e7b99ed918
commit 1c3fc0c4bd
18 changed files with 386 additions and 152 deletions

40
src/core/raster.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef RASTER_H_
#define RASTER_H_
#include "primitives.h"
#include "stddef.h"
#include "vector.h"
typedef struct {
V2 p1;
V2 p2;
int winding;
} Edge;
typedef struct {
Edge *edges;
size_t count;
size_t capacity;
} EdgeBuffer;
void add_edge(EdgeBuffer *edges, Edge edge);
void flatten_line(EdgeBuffer *edges, Line line);
void flatten_polyline(EdgeBuffer *edges, Polyline *line);
void flatten_polygon(EdgeBuffer *buffer, Polygon *line);
typedef struct {
unsigned int width;
unsigned int height;
unsigned char *pixels; // Flat RGB8 array
} Framebuffer;
Framebuffer mk_framebuffer(unsigned int width, unsigned int height);
void put_pixel(Framebuffer *fb, int x, int y, unsigned char r, unsigned char g,
unsigned char b);
void draw_line(Framebuffer *fb, V2 a, V2 b, unsigned char r, unsigned char g,
unsigned char bl);
#endif // RASTER_H_