Compare commits

...

2 Commits

Author SHA1 Message Date
Annika f09db214cc organized project directory. makefile broken 2026-07-07 08:09:54 -07:00
Annika 1fce028eea stubbed out shaders 2026-07-07 07:46:27 -07:00
24 changed files with 78 additions and 234 deletions
+9 -9
View File
@@ -7,27 +7,27 @@ ifeq ($(LDFLAGS),)
LDFLAGS := -lwayland-client -lm
endif
LIB_SRC := waymini.c xdg-shell-client-protocol.c
LIB_SRC := waymini/waymini.c waymini/xdg-shell-client-protocol.c
LIB_OBJ := $(LIB_SRC:.c=.o)
.PHONY: all clean
all: libwaymini.a example waymini
all: waymini/libwaymini.a example waymini
libwaymini.a: $(LIB_OBJ)
ar rcs $@ $^
waymini/libwaymini.a: $(LIB_OBJ)
ar rcs -rpath=./waymini $@ $^
example: example.cpp libwaymini.a
example: example.cpp waymini/libwaymini.a
g++ $(CFLAGS) -o $@ example.cpp -L. -lwaymini $(LDFLAGS)
waymini: waymini_standalone.c waymini.c xdg-shell-client-protocol.c
$(CC) $(CFLAGS) -o $@ waymini_standalone.c waymini.c xdg-shell-client-protocol.c $(LDFLAGS)
waymini: waymini/waymini_standalone.c waymini/waymini.c waymini/xdg-shell-client-protocol.c
$(CC) $(CFLAGS) -o $@ waymini/waymini_standalone.c waymini/waymini.c waymini/xdg-shell-client-protocol.c $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f $(LIB_OBJ) libwaymini.a example waymini
rm -f $(LIB_OBJ) waymini/libwaymini.a example waymini/waymini
xdg-shell-client-protocol.c xdg-shell-client-protocol.h: gen-protocols.sh
bash gen-protocols.sh
bash waymini/gen-protocols.sh
+4 -4
View File
@@ -1,4 +1,4 @@
write a monolithic header file
refactor example code using composition
remove draw class entirely
create shader classes with polymorphism
[ ] write a monolithic header file
[x] refactor example code using composition
[ ] remove draw class entirely
[ ] create shader classes with polymorphism
-31
View File
@@ -1,31 +0,0 @@
#pragma once
#include <stdint.h>
#include <stdlib.h>
namespace UwU {
class Bresenham {
private:
int16_t x0;
int16_t y0;
int16_t x1;
int16_t y1;
int16_t d;
int16_t
public:
Bresenham(int16_t x0, int16_t y0, int16_t x1, int16_t y1) {
this->x0 = x0;
this->y0 = y0;
this->x1 = x1;
this->y1 = y1;
if (abs(y1 - y0) < abs(x1 - x0)) {
if (x0 > x1) {
}
}
}
};
}
+17
View File
@@ -4,6 +4,7 @@
#include "datatypes.cpp"
#include "helpers.cpp"
#include "shaders/shader.cpp"
namespace UwU {
// Buffer object - can be a wayland surface or a virtual buffer
@@ -42,5 +43,21 @@ namespace UwU {
pixels[i + 3] = 0xff; // A
return;
}
void drawPixelShader(Coord2 coord, Shader shader) {
size_t i = (size_t)coord.y * stride + (size_t)coord.x * 4;
uint8_t b0 = pixels[i + 0];
uint8_t g0 = pixels[i + 1];
uint8_t r0 = pixels[i + 2];
Color newColor = shader.color();
uint8_t b = Helpers::lerp8(b0, newColor.b, newColor.a);
uint8_t g = Helpers::lerp8(g0, newColor.g, newColor.a);
uint8_t r = Helpers::lerp8(r0, newColor.r, newColor.a);
pixels[i + 0] = b; // B
pixels[i + 1] = g; // G
pixels[i + 2] = r; // R
pixels[i + 3] = 0xff; // A
return;
}
};
}
-153
View File
@@ -1,153 +0,0 @@
#pragma once
#include "waymini.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "datatypes.cpp"
#include "helpers.cpp"
#include "triangle.cpp"
#include "buffer.cpp"
#include "surface.cpp"
#include "trapezoid.cpp"
#include "line.cpp"
#include "rectangle.cpp"
#include "point.cpp"
namespace UwU {
class Draw {
public:
Draw(uint16_t width, uint16_t height, waymini_key_cb onKey)
: surface(width, height, onKey) {}
class Surface surface;
bool shouldClose() {
return surface.shouldClose();
}
void updateSize() {
surface.updateSize();
return;
}
uint16_t getWidth() {
return surface.getWidth();
}
uint16_t getHeight() {
return surface.getHeight();
}
uint16_t getStride() {
return surface.getStride();
}
void present() {
surface.present();
return;
}
void destroy() {
surface.destroy();
return;
}
// Draw a rectangle (duh)
void rectangle(Coord2 point0, Coord2 point1, Color color) {
Rectangle rectangle = Rectangle(point0.x, point0.y, point1.x, point1.y);
rectangle.draw(surface.buffer, color);
return;
}
// Draws a rectangle with a 4-point color gradient
void rectangleGradient(Coord2 point0, Coord2 point1, Color colorUL, Color colorUR, Color colorLL, Color colorLR) {
// convert to int32_t and ensure x1>x0 && y1>y0
int32_t x0, y0, x1, y1;
if (point0.x > point1.x) {
x0 = (int32_t)point1.x;
x1 = (int32_t)point0.x;
} else {
x0 = (int32_t)point0.x;
x1 = (int32_t)point1.x;
}
if (point0.y > point1.y) {
y0 = (int32_t)point1.y;
y1 = (int32_t)point0.y;
} else {
y0 = (int32_t)point0.y;
y1 = (int32_t)point1.y;
}
// setup gradient coefficient arrays
int32_t w = x1 - x0 + 1;
int32_t h = y1 - y0 + 1;
int16_t xGrad[w];
int16_t yGrad[h];
// calculate gradient coefficients
Helpers::bresenham(0, 0, w - 1, 255, xGrad);
Helpers::bresenham(0, 0, h - 1, 255, yGrad);
// for each point calculate, alpha blend and print color
Color Lmix = Color();
Color Rmix = Color();
Color Xmix = Color();
for (int32_t y = y0; y <= y1; y++) {
Lmix = Helpers::lerpColor(colorUL, colorLL, (uint8_t)yGrad[y - y0]);
Rmix = Helpers::lerpColor(colorUR, colorLR, (uint8_t)yGrad[y - y0]);
for (int32_t x = x0; x <= x1; x++) {
Xmix = Helpers::lerpColor(Lmix, Rmix, (uint8_t)xGrad[x - x0]);
// putPixel(x, y, Xmix.r, Xmix.g, Xmix.b, Xmix.a);
surface.buffer.drawPixel(Coord2((uint16_t)x, (uint16_t)y), Xmix);
}
}
return;
}
// Fill a simple gradient. Each row is stride bytes.
void rainbow() {
for (uint32_t y = 0; y < getHeight(); y++) {
for (uint32_t x = 0; x < getWidth(); x++) {
surface.buffer.drawPixel(Coord2((uint16_t)x, (uint16_t)y), Color(
(uint8_t)(y * 255 / getHeight()),
0x00,
(uint8_t)(x * 255 / getWidth()),
0xff));
// size_t i = (size_t)y * getStride() + (size_t)x * 4;
// pixels[i + 0] = (uint8_t)(y * 255 / getHeight()); // B
// pixels[i + 1] = 0x00; // G
// pixels[i + 2] = (uint8_t)(x * 255 / getWidth()); // R
// pixels[i + 3] = 0xFF; // A
}
}
}
// Draw a single point
void point (Point point, Color color) {
point.draw(surface.buffer, color);
}
void line (Line line, Color color) {
line.draw(surface.buffer, color);
return;
}
void trapezoid (Trapezoid coords, Color color) {
coords.draw(surface.buffer, color);
return;
}
// Draw a triangle
void triangle (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, Color color) {
Triangle triangle = Triangle(x0, y0, x1, y1, x2, y2);
triangle.draw(surface.buffer, color);
return;
}
};
}
BIN
View File
Binary file not shown.
+9 -19
View File
@@ -1,6 +1,6 @@
// #pragma once
#include "waymini.h"
#include "waymini/waymini.h"
#include <stdint.h>
#include <stdio.h>
@@ -9,14 +9,15 @@
#include "datatypes.cpp"
#include "helpers.cpp"
#include "triangle.cpp"
#include "buffer.cpp"
#include "surface.cpp"
#include "trapezoid.cpp"
#include "line.cpp"
#include "rectangle.cpp"
#include "point.cpp"
#include "draw.cpp"
#include "primatives/line.cpp"
#include "primatives/point.cpp"
#include "primatives/rectangle.cpp"
#include "primatives/trapezoid.cpp"
#include "primatives/triangle.cpp"
// #include "draw.cpp"
#include "shaders/shader.cpp"
static void onKey(void *user, uint32_t keycode, uint32_t state) {
if (keycode == 1) {
@@ -30,38 +31,27 @@ static void onKey(void *user, uint32_t keycode, uint32_t state) {
int main(void) {
uint16_t w = 800, h = 480;
UwU::Color fuchsia = UwU::Color(0xb00b6980);
UwU::Shader fuchsia = UwU::Shader();
UwU::Color red = UwU::Color(0xff000080);
UwU::Color green = UwU::Color(0x00ff00ff);
UwU::Color blue = UwU::Color(0x0000ff80);
UwU::Color alpha = UwU::Color(0x00000000);
printf("r: %u, g:%u, b:%u, a:%u\n", fuchsia.r, fuchsia.g, fuchsia.b, fuchsia.a);
// struct waymini *wm = waymini_create(w, h, on_key, NULL);
// UwU::Draw draw = UwU::Draw(w, h, onKey);
UwU::Surface surface = UwU::Surface(w, h, onKey);
// draw.rainbow();
// draw.rectangle(UwU::Coord2(69, 69), UwU::Coord2(420, 420), fuchsia);
UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420);
rectangle.draw(surface.buffer, fuchsia);
// draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red);
// draw.trapezoid(UwU::Trapezoid(300, 400, 360, 380, 600, 480), red);
UwU::Trapezoid trapezoid = UwU::Trapezoid(300, 400, 360, 380, 600, 480);
trapezoid.draw(surface.buffer, red);
// draw.triangle(280, 100, 240, 290, 320, 300, blue);
UwU::Triangle triangle = UwU::Triangle(280, 100, 240, 290, 320, 300);
triangle.draw(surface.buffer, blue);
// myTrap = UwU:Trapezoid(300, 400, 360, 380, 600, 480);
// myTrap.draw()
// draw.point(UwU::Point(387, 43), green);
UwU::Point point = UwU::Point(387, 43);
point.draw(surface.buffer, green);
BIN
View File
Binary file not shown.
+3 -3
View File
@@ -2,9 +2,9 @@
#include <stdint.h>
#include "datatypes.cpp"
#include "helpers.cpp"
#include "buffer.cpp"
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
// line
+3 -3
View File
@@ -2,9 +2,9 @@
#include <stdint.h>
#include "datatypes.cpp"
#include "helpers.cpp"
#include "buffer.cpp"
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
// point
+6 -5
View File
@@ -2,9 +2,10 @@
#include <stdint.h>
#include "datatypes.cpp"
#include "helpers.cpp"
#include "buffer.cpp"
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
#include "../shaders/shader.cpp"
namespace UwU {
// rectangle
@@ -23,11 +24,11 @@ namespace UwU {
uint16_t y1;
// Draw a rectangle
void draw (Buffer buffer, Color color) {
void draw (Buffer buffer, Shader shader) {
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
for (uint16_t y = y0; y < y1; y++) {
for (uint16_t x = x0; x < x1; x++) {
buffer.drawPixel(Coord2(x, y), color);
buffer.drawPixelShader(Coord2(x, y), shader);
}
}
return;
+3 -3
View File
@@ -2,9 +2,9 @@
#include <stdint.h>
#include "datatypes.cpp"
#include "helpers.cpp"
#include "buffer.cpp"
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
// trapezoid (horizontally constrained)
+3 -3
View File
@@ -2,9 +2,9 @@
#include <stdint.h>
#include "datatypes.cpp"
#include "helpers.cpp"
#include "buffer.cpp"
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
class Triangle {
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
// shader prototype
class Shader {
public:
Shader() {}
Color color() {
return Color(0xb00b69ff);
}
};
}
+2 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include "waymini.h"
#include "waymini/waymini.h"
#include <stdint.h>
#include <stdio.h>
@@ -12,6 +12,7 @@
namespace UwU {
class Surface {
// should probably be a child of buffer
public:
Surface(uint16_t width, uint16_t height, waymini_key_cb onKey) {
this->wm = waymini_create((uint32_t)width, (uint32_t)height, onKey, NULL);
BIN
View File
Binary file not shown.
View File
View File
View File