diff --git a/FEATURES.md b/FEATURES.md new file mode 100644 index 0000000..929e95a --- /dev/null +++ b/FEATURES.md @@ -0,0 +1,19 @@ +shapes: + triangles: + point + line + solid + gradient + rectangle + solid + gradient + blitter (tilemaps) + triangle + solid + gradient + perspective mapping (3D!!!) + quad + solid + gradient (charts) + blitter (isometric) + affine mapping (sprite rotation and scaling) diff --git a/datatypes.cpp b/datatypes.cpp index a27de46..22a7e69 100644 --- a/datatypes.cpp +++ b/datatypes.cpp @@ -26,15 +26,15 @@ namespace UwU { }; // Coord2 datatype for xy coordinates, from top-left of surface - // struct Coord2 { - // Coord2(uint16_t x, uint16_t y) { - // this->x = x; - // this->y = y; - // } - // Coord2() {} - // uint16_t x; - // uint16_t y; - // }; + struct Coord2 { + Coord2(uint16_t x, uint16_t y) { + this->x = x; + this->y = y; + } + Coord2() {} + uint16_t x; + uint16_t y; + }; // Vec2 datatype for signed x, y coordinates // struct Vec2 { diff --git a/example b/example new file mode 100755 index 0000000..75f1cd0 Binary files /dev/null and b/example differ diff --git a/example.cpp b/example.cpp index bdedeec..f072806 100644 --- a/example.cpp +++ b/example.cpp @@ -44,21 +44,22 @@ int main(void) { UwU::Color blue = UwU::Color(0x0000ffff); // UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff)); - UwU::VGradientShader bisexual = UwU::VGradientShader(69, 420, UwU::Color(0xff0000ff), UwU::Color(0x0000ffff)); + UwU::VGradientShader bisexual = UwU::VGradientShader(0, 351, UwU::Color(0xff0000ff), UwU::Color(0x0000ffff)); + UwU::OffsetMapper rectMapper = UwU::OffsetMapper(69, 69); UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420); - rectangle.draw(surface.buffer, bisexual); + rectangle.draw(surface.buffer, rectMapper, bisexual); UwU::ColorShader greenShader = UwU::ColorShader(green); UwU::Point point = UwU::Point(187, 37); point.draw(surface.buffer, greenShader); - UwU::ColorShader blue = UwU::ColorShader(UwU::Color(0x0000ffff)); + UwU::ColorShader blueShader = UwU::ColorShader(blue); UwU::Trapezoid trapezoid = UwU::Trapezoid(100, 300, 690, 320, 720, 780); - trapezoid.draw(surface.buffer, blue); + trapezoid.draw(surface.buffer, blueShader); - UwU::ColorShader red = UwU::ColorShader(UwU::Color(0xff0000ff)); + UwU::ColorShader redShader = UwU::ColorShader(red); UwU::Triangle triangle = UwU::Triangle(140, 140, 60, 400, 240, 240); - triangle.draw(surface.buffer, red); + triangle.draw(surface.buffer, redShader); // // Benchmarking // struct timespec start, end; @@ -99,7 +100,7 @@ int main(void) { }; for (uint16_t i = 0; i < 8; i++) { - lines[i].draw(surface.buffer, blue); + lines[i].draw(surface.buffer, blueShader); } diff --git a/mappers/mapperbase.cpp b/mappers/mapperbase.cpp new file mode 100644 index 0000000..24caf45 --- /dev/null +++ b/mappers/mapperbase.cpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "../datatypes.cpp" +#include "../helpers.cpp" + +namespace UwU { + template + class MapperBase { + public: + Coord2 map(uint16_t x, uint16_t y) { + return static_cast(this)->map(x, y); + } + }; +} \ No newline at end of file diff --git a/mappers/mappers.h b/mappers/mappers.h new file mode 100644 index 0000000..90c660d --- /dev/null +++ b/mappers/mappers.h @@ -0,0 +1,4 @@ +#include "mapperbase.cpp" +#include "nullmapper.cpp" +#include "offsetmapper.cpp" +#include "tilemapper.cpp" \ No newline at end of file diff --git a/mappers/nullmapper.cpp b/mappers/nullmapper.cpp new file mode 100644 index 0000000..417726e --- /dev/null +++ b/mappers/nullmapper.cpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include "../datatypes.cpp" +#include "../helpers.cpp" +#include "mapperbase.cpp" + +namespace UwU { + class NullMapper : public MapperBase { + public: + NullMapper() {} + + Coord2 map(uint16_t x, uint16_t y) { + return Coord2(x, y); + } + }; +} \ No newline at end of file diff --git a/mappers/offsetmapper.cpp b/mappers/offsetmapper.cpp new file mode 100644 index 0000000..d77eeb0 --- /dev/null +++ b/mappers/offsetmapper.cpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "../datatypes.cpp" +#include "../helpers.cpp" +#include "mapperbase.cpp" + +namespace UwU { + class OffsetMapper : public MapperBase { + public: + OffsetMapper(uint16_t x0, uint16_t y0) { + this->x0 = x0; + this->y0 = y0; + } + uint16_t x0, y0; + + Coord2 map(uint16_t x, uint16_t y) { + uint16_t u = x -x0; + uint16_t v = y -y0; + return Coord2(u, v); + } + }; +} \ No newline at end of file diff --git a/mappers/tilemapper.cpp b/mappers/tilemapper.cpp new file mode 100644 index 0000000..b5dca69 --- /dev/null +++ b/mappers/tilemapper.cpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "../datatypes.cpp" +#include "../helpers.cpp" +#include "mapperbase.cpp" + +namespace UwU { + class TileMapper : public MapperBase { // not actually tilemapping yet + public: + TileMapper(uint16_t x0, uint16_t y0) { + this->x0 = x0; + this->y0 = y0; + } + uint16_t x0, y0; + + Coord2 map(uint16_t x, uint16_t y) { + uint16_t u = x -x0; + uint16_t v = y -y0; + return Coord2(u, v); + } + }; +} \ No newline at end of file diff --git a/primatives/rectangle.cpp b/primatives/rectangle.cpp index a023bf6..77e5ee3 100644 --- a/primatives/rectangle.cpp +++ b/primatives/rectangle.cpp @@ -5,8 +5,8 @@ #include "../datatypes.cpp" #include "../helpers.cpp" #include "../buffer.cpp" -#include "../shaders/shaderbase.cpp" #include "../shaders/shaders.h" +#include "../mappers/mappers.h" namespace UwU { // rectangle @@ -25,12 +25,13 @@ namespace UwU { uint16_t y1; // Draw a rectangle - template - void draw (Buffer buffer, ShaderBase& shader) { + template + void draw (Buffer buffer, MapperBase& mapper, ShaderBase& 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(x, y, shader.shade(x, y)); + Coord2 uv = mapper.map(x, y); + buffer.drawPixel(x, y, shader.shade(uv.x, uv.y)); } } return;