brute forced text support, fixed an off-by one, lots to fix

This commit is contained in:
2026-07-08 19:44:37 -07:00
parent ee0d43dd75
commit bb30e2df0b
6 changed files with 106 additions and 17 deletions
+5 -2
View File
@@ -3,6 +3,9 @@
[x] remove draw class entirely [x] remove draw class entirely
[x] create shader classes with polymorphism [x] create shader classes with polymorphism
[x] optimize shader/primative performance (repeat myself!) [x] optimize shader/primative performance (repeat myself!)
[ ] finish implementing gradient shaders to primatives [x] finish implementing gradient shaders to primatives
[ ] implement buffer shader [x] implement buffer shader
[ ] implement more primatives [ ] implement more primatives
[ ] fix off by one with buffer shader (and probably certain primatives)
[ ] fix memory leak and arrays in stack issue
[ ] fix shader offset limitations and headache
+1 -2
View File
@@ -11,8 +11,7 @@ namespace UwU {
class Buffer { class Buffer {
public: public:
Buffer(uint16_t width, uint16_t height) { Buffer(uint16_t width, uint16_t height) {
uint8_t pixels[width * height * 4]; this->pixels = new uint8_t[width * height * 4];
this->pixels = pixels;
this->width = width; this->width = width;
this->height = height; this->height = height;
this->stride = width * 4; this->stride = width * 4;
BIN
View File
Binary file not shown.
+46 -3
View File
@@ -20,6 +20,8 @@
#include <time.h> #include <time.h>
#include "font.cpp"
static void onKey(void *user, uint32_t keycode, uint32_t state) { static void onKey(void *user, uint32_t keycode, uint32_t state) {
if (keycode == 1) { if (keycode == 1) {
exit(1); exit(1);
@@ -34,10 +36,10 @@ int main(void) {
uint16_t w = 800, h = 480; uint16_t w = 800, h = 480;
UwU::Shader fuchsia = UwU::Shader(UwU::Direction::V, 100, 300, UwU::Color(0xb00b69ff), UwU::Color(0x00000000)); UwU::Shader fuchsia = UwU::Shader(UwU::Direction::V, 100, 300, UwU::Color(0xb00b69ff), UwU::Color(0x00000000));
UwU::Shader red = UwU::Shader(UwU::Direction::V, 69, 420, UwU::Color(0xff0000ff), UwU::Color(0x00000000)); UwU::Shader red = UwU::Shader(UwU::Direction::V, 69, 420, UwU::Color(0xff0000ff), UwU::Color(0x00000000));
UwU::Shader bisexual = UwU::Shader(UwU::Direction::H, 100, 469, UwU::Color(0xff0000ff), UwU::Color(0x0000ffff)); UwU::Shader bisexual = UwU::Shader(UwU::Direction::H, 0, 799, UwU::Color(0xff0000ff), UwU::Color(0x0000ffff));
UwU::Shader aqua = UwU::Shader(UwU::Direction::V, 4, 475, UwU::Color(0x00ff00ff), UwU::Color(0x0000ffff)); UwU::Shader aqua = UwU::Shader(UwU::Direction::V, 2, 349, UwU::Color(0x00ff00ff), UwU::Color(0x0000ffff));
UwU::Shader warmup = UwU::Shader(UwU::Color(0xb00b69ff)); UwU::Shader warmup = UwU::Shader(UwU::Color(0xb00b69ff));
UwU::Color green = UwU::Color(0x00ff00ff); UwU::Shader green = UwU::Shader(UwU::Color(0x00ff00ff));
UwU::Color blue = UwU::Color(0x0000ff80); UwU::Color blue = UwU::Color(0x0000ff80);
// UwU::Color alpha = UwU::Color(0x00000000); // UwU::Color alpha = UwU::Color(0x00000000);
@@ -51,6 +53,47 @@ int main(void) {
UwU::Triangle triangle = UwU::Triangle(280, 100, 240, 290, 320, 300); UwU::Triangle triangle = UwU::Triangle(280, 100, 240, 290, 320, 300);
UwU::Point point = UwU::Point(387, 43); UwU::Point point = UwU::Point(387, 43);
// Window Header
UwU::Trapezoid trap0 = UwU::Trapezoid(0, 7, 7, 0, 792, 799);
UwU::Rectangle rect1 = UwU::Rectangle(0, 8, 799, 23);
UwU::Trapezoid trap2 = UwU::Trapezoid(24, 31, 0, 0, 71, 63);
UwU::Trapezoid trap3 = UwU::Trapezoid(24, 31, 727, 736, 799, 799);
// trap0.draw(surface.buffer, bisexual);
// rect1.draw(surface.buffer, bisexual);
// trap2.draw(surface.buffer, bisexual);
// trap3.draw(surface.buffer, bisexual);
// Window Body
UwU::Shader sU1 = UwU::Shader(8, 8, font());
UwU::Shader sw1 = UwU::Shader(10, 8, font());
UwU::Shader sU2 = UwU::Shader(28, 8, font());
UwU::Shader sG1 = UwU::Shader(20, 8, font());
UwU::Shader sL1 = UwU::Shader(22, 8, font());
UwU::Rectangle rU1 = UwU::Rectangle(8, 8, 13, 16);
UwU::Rectangle rw1 = UwU::Rectangle(16, 8, 25, 16);
UwU::Rectangle rU2 = UwU::Rectangle(28, 8, 33, 16);
UwU::Rectangle rG1 = UwU::Rectangle(36, 8, 41, 16);
UwU::Rectangle rL1 = UwU::Rectangle(44, 8, 48, 16);
rU1.draw(surface.buffer, sU1);
rw1.draw(surface.buffer, sw1);
rU2.draw(surface.buffer, sU2);
rG1.draw(surface.buffer, sG1);
rL1.draw(surface.buffer, sL1);
// Window Footer
UwU::Trapezoid trap5 = UwU::Trapezoid(440, 471, 712, 689, 799, 799);
UwU::Trapezoid trap6 = UwU::Trapezoid(472, 479, 0, 7, 799, 792);
trap5.draw(surface.buffer, bisexual);
trap6.draw(surface.buffer, bisexual);
// Window Buttons
UwU::Trapezoid trap7 = UwU::Trapezoid(448, 455, 728, 720, 791, 791);
UwU::Rectangle rect8 = UwU::Rectangle(720, 456, 791, 463);
UwU::Trapezoid trap9 = UwU::Trapezoid(464, 471, 720, 720, 791, 783);
trap7.draw(surface.buffer, fuchsia);
rect8.draw(surface.buffer, fuchsia);
trap9.draw(surface.buffer, fuchsia);
bgRectangle.draw(buffer, aqua); bgRectangle.draw(buffer, aqua);
// Benchmarking // Benchmarking
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include <stdint.h>
#include "buffer.cpp"
UwU::Buffer font() {
const uint32_t fontInt[9] = {
0xcc003f00,
0xcc004300,
0xcf33c300,
0xcf33c300,
0xcf33df00,
0xcf33cf00,
0xcf33cf00,
0xcf33cf00,
0x7ffeffe0
};
UwU::Buffer font = UwU::Buffer(32, 9);
uint32_t t;
uint32_t b;
for (uint16_t y = 0; y < 9; y++) {
t = fontInt[y];
for (uint16_t x = 0; x < 32; x++) {
b = t & 0x80000000;
if (b == 0x80000000) {
font.pixels[(y * 128) + (x * 4) + 0] = 0xff;
font.pixels[(y * 128) + (x * 4) + 1] = 0xff;
font.pixels[(y * 128) + (x * 4) + 2] = 0xff;
font.pixels[(y * 128) + (x * 4) + 3] = 0xff;
} else {
font.pixels[(y * 128) + (x * 4) + 0] = 0x00;
font.pixels[(y * 128) + (x * 4) + 1] = 0x00;
font.pixels[(y * 128) + (x * 4) + 2] = 0x00;
font.pixels[(y * 128) + (x * 4) + 3] = 0x00;
}
t = t << 1;
}
}
return font;
}
+9 -9
View File
@@ -27,8 +27,8 @@ namespace UwU {
void draw (Buffer buffer, Shader shader) { void draw (Buffer buffer, Shader shader) {
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;}; if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
if (shader.shaderType == COLOR) { if (shader.shaderType == COLOR) {
for (uint16_t y = y0; y < y1; y++) { for (uint16_t y = y0; y <= y1; y++) {
for (uint16_t x = x0; x < x1; x++) { for (uint16_t x = x0; x <= x1; x++) {
buffer.drawPixel(x, y, shader.c0); buffer.drawPixel(x, y, shader.c0);
} }
} }
@@ -38,29 +38,29 @@ namespace UwU {
// Precompute gradient LUT // Precompute gradient LUT
Color cols[x1 - x0]; Color cols[x1 - x0];
for (uint16_t x = x0; x < x1; x++) { for (uint16_t x = x0; x <= x1; x++) {
cols[x - x0] = ShaderMethods::gradient(shader.u0, shader.scale, shader.c0, shader.c1, x); cols[x - x0] = ShaderMethods::gradient(shader.u0, shader.scale, shader.c0, shader.c1, x);
} }
for (uint16_t y = y0; y < y1; y++) { for (uint16_t y = y0; y <= y1; y++) {
for (uint16_t x = x0; x < x1; x++) { for (uint16_t x = x0; x <= x1; x++) {
buffer.drawPixel(x, y, cols[x - x0]); buffer.drawPixel(x, y, cols[x - x0]);
} }
} }
return; return;
} else if (shader.shaderType == VGRADIENT) { } else if (shader.shaderType == VGRADIENT) {
for (uint16_t y = y0; y < y1; y++) { for (uint16_t y = y0; y <= y1; y++) {
Color c = ShaderMethods::gradient(shader.v0, shader.scale, shader.c0, shader.c1, y); Color c = ShaderMethods::gradient(shader.v0, shader.scale, shader.c0, shader.c1, y);
for (uint16_t x = x0; x < x1; x++) { for (uint16_t x = x0; x <= x1; x++) {
buffer.drawPixel(x, y, c); buffer.drawPixel(x, y, c);
} }
} }
return; return;
} else if (shader.shaderType == BUFFER) { } else if (shader.shaderType == BUFFER) {
for (uint16_t y = y0; y < y1; y++) { for (uint16_t y = y0; y <= y1; y++) {
for (uint16_t x = x0; x < x1; x++) { for (uint16_t x = x0; x <= x1; x++) {
buffer.drawPixel(x, y, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, y)); buffer.drawPixel(x, y, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, y));
} }
} }