diff --git a/TODO b/TODO index 69620c9..ce0fb89 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,9 @@ [x] remove draw class entirely [x] create shader classes with polymorphism [x] optimize shader/primative performance (repeat myself!) -[ ] finish implementing gradient shaders to primatives -[ ] implement buffer shader -[ ] implement more primatives \ No newline at end of file +[x] finish implementing gradient shaders to primatives +[x] implement buffer shader +[ ] 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 \ No newline at end of file diff --git a/buffer.cpp b/buffer.cpp index ddbe894..d9c7016 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -11,8 +11,7 @@ namespace UwU { class Buffer { public: Buffer(uint16_t width, uint16_t height) { - uint8_t pixels[width * height * 4]; - this->pixels = pixels; + this->pixels = new uint8_t[width * height * 4]; this->width = width; this->height = height; this->stride = width * 4; diff --git a/example b/example index 106f820..5fd8bb3 100755 Binary files a/example and b/example differ diff --git a/example.cpp b/example.cpp index 32c6b92..7137591 100644 --- a/example.cpp +++ b/example.cpp @@ -20,6 +20,8 @@ #include +#include "font.cpp" + static void onKey(void *user, uint32_t keycode, uint32_t state) { if (keycode == 1) { exit(1); @@ -34,10 +36,10 @@ int main(void) { uint16_t w = 800, h = 480; 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 bisexual = UwU::Shader(UwU::Direction::H, 100, 469, UwU::Color(0xff0000ff), UwU::Color(0x0000ffff)); - UwU::Shader aqua = UwU::Shader(UwU::Direction::V, 4, 475, UwU::Color(0x00ff00ff), 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, 2, 349, UwU::Color(0x00ff00ff), UwU::Color(0x0000ffff)); 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 alpha = UwU::Color(0x00000000); @@ -51,6 +53,47 @@ int main(void) { UwU::Triangle triangle = UwU::Triangle(280, 100, 240, 290, 320, 300); 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); // Benchmarking diff --git a/font.cpp b/font.cpp new file mode 100644 index 0000000..58b8128 --- /dev/null +++ b/font.cpp @@ -0,0 +1,44 @@ +#pragma once + +#include + +#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; +} \ No newline at end of file diff --git a/primatives/rectangle.cpp b/primatives/rectangle.cpp index 1f26ac3..a6d15e0 100644 --- a/primatives/rectangle.cpp +++ b/primatives/rectangle.cpp @@ -27,8 +27,8 @@ namespace UwU { void draw (Buffer buffer, Shader shader) { if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;}; if (shader.shaderType == COLOR) { - for (uint16_t y = y0; y < y1; y++) { - for (uint16_t x = x0; x < x1; x++) { + for (uint16_t y = y0; y <= y1; y++) { + for (uint16_t x = x0; x <= x1; x++) { buffer.drawPixel(x, y, shader.c0); } } @@ -38,29 +38,29 @@ namespace UwU { // Precompute gradient LUT 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); } - for (uint16_t y = y0; y < y1; y++) { - for (uint16_t x = x0; x < x1; x++) { + for (uint16_t y = y0; y <= y1; y++) { + for (uint16_t x = x0; x <= x1; x++) { buffer.drawPixel(x, y, cols[x - x0]); } } return; } 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); - for (uint16_t x = x0; x < x1; x++) { + for (uint16_t x = x0; x <= x1; x++) { buffer.drawPixel(x, y, c); } } return; } else if (shader.shaderType == BUFFER) { - for (uint16_t y = y0; y < y1; y++) { - for (uint16_t x = x0; x < x1; x++) { + for (uint16_t y = y0; y <= y1; y++) { + for (uint16_t x = x0; x <= x1; x++) { buffer.drawPixel(x, y, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, y)); } }