diff --git a/example b/example index 75f1cd0..0609a46 100755 Binary files a/example and b/example differ diff --git a/example.cpp b/example.cpp index 9d0a81c..097b078 100644 --- a/example.cpp +++ b/example.cpp @@ -44,10 +44,17 @@ int main(void) { UwU::Color blue = UwU::Color(0x0000ffff); // UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff)); - UwU::VGradientShader bisexual = UwU::VGradientShader(0, 351, red, blue); - UwU::OffsetMapper offsetMapper = UwU::OffsetMapper(); + UwU::HGradientShader bisexual = UwU::HGradientShader(0, 179, red, blue); + UwU::TileMapper tileMapper = UwU::TileMapper(); + UwU::Buffer fontBuffer = font(); + UwU::BufferShader textMap = UwU::BufferShader(fontBuffer); + tileMapper.tileMap[0] = 0x0000; + tileMapper.tileMap[1] = 0x0111; + tileMapper.tileMap[2] = 0x0000; + tileMapper.tileMap[3] = 0x0222; + tileMapper.tileMap[4] = 0x0333; UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420); - rectangle.draw(surface.buffer, offsetMapper, bisexual); + rectangle.draw(surface.buffer, tileMapper, textMap); UwU::ColorShader greenShader = UwU::ColorShader(green); UwU::NullMapper nullMapper = UwU::NullMapper(); @@ -60,7 +67,8 @@ int main(void) { UwU::ColorShader redShader = UwU::ColorShader(red); UwU::Triangle triangle = UwU::Triangle(140, 140, 60, 400, 240, 240); - triangle.draw(surface.buffer, nullMapper, redShader); + UwU::OffsetMapper offsetMapper = UwU::OffsetMapper(); + triangle.draw(surface.buffer, offsetMapper, bisexual); // // Benchmarking // struct timespec start, end; diff --git a/mappers/tilemapper.cpp b/mappers/tilemapper.cpp index b86df29..3fd6334 100644 --- a/mappers/tilemapper.cpp +++ b/mappers/tilemapper.cpp @@ -9,11 +9,22 @@ namespace UwU { class TileMapper : public MapperBase { // not actually tilemapping yet public: - TileMapper() {} + TileMapper() { + this->tileMap = new uint16_t[16384]; // the map of tile positions 128x128 8x8 tiles from a 512x512 bitmap space + } + uint16_t* tileMap; Coord2 map(uint16_t x0, uint16_t y0, uint16_t x, uint16_t y) { - uint16_t u = x -x0; - uint16_t v = y -y0; + uint16_t u0 = x - x0; + uint16_t v0 = y - y0; + // returns uv coordinates that point to a specific pixel of a specific tile on a tilesheet buffer + uint16_t mapX = (u0 & 0x03f8) >> 3; + uint16_t mapY = (v0 & 0x03f8) << 4; + uint16_t tileIndex = tileMap[mapY + mapX]; + uint16_t u = (tileIndex & 0x003f) << 3; + u += (u0 & 0x0007); + uint16_t v = (tileIndex & 0x0fc0) >> 3; + v += (v0 & 0x0007); return Coord2(u, v); } }; diff --git a/shaders/buffershader.cpp b/shaders/buffershader.cpp new file mode 100644 index 0000000..d83d1b9 --- /dev/null +++ b/shaders/buffershader.cpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "../datatypes.cpp" +#include "../helpers.cpp" +#include "../buffer.cpp" +#include "shaderbase.cpp" + +namespace UwU { + class BufferShader : public ShaderBase { + public: + BufferShader(Buffer buffer) { + this->buffer = buffer; + } + Buffer buffer; + + Color shade(uint16_t x, uint16_t y) { + uint32_t index = (y * buffer.stride) + (x * 4); + Color c = Color(buffer.pixels[index + 2], buffer.pixels[index + 1], buffer.pixels[index], buffer.pixels[index + 3]); + return c; + } + }; +} \ No newline at end of file diff --git a/shaders/shaders.h b/shaders/shaders.h index 47aa080..9632c93 100644 --- a/shaders/shaders.h +++ b/shaders/shaders.h @@ -1,4 +1,5 @@ #include "shaderbase.cpp" #include "colorshader.cpp" #include "hgradientshader.cpp" -#include "vgradientshader.cpp" \ No newline at end of file +#include "vgradientshader.cpp" +#include "buffershader.cpp" \ No newline at end of file