basic tilemapping
This commit is contained in:
+12
-4
@@ -44,10 +44,17 @@ int main(void) {
|
|||||||
UwU::Color blue = UwU::Color(0x0000ffff);
|
UwU::Color blue = UwU::Color(0x0000ffff);
|
||||||
|
|
||||||
// UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff));
|
// UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff));
|
||||||
UwU::VGradientShader bisexual = UwU::VGradientShader(0, 351, red, blue);
|
UwU::HGradientShader bisexual = UwU::HGradientShader(0, 179, red, blue);
|
||||||
UwU::OffsetMapper offsetMapper = UwU::OffsetMapper();
|
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);
|
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::ColorShader greenShader = UwU::ColorShader(green);
|
||||||
UwU::NullMapper nullMapper = UwU::NullMapper();
|
UwU::NullMapper nullMapper = UwU::NullMapper();
|
||||||
@@ -60,7 +67,8 @@ int main(void) {
|
|||||||
|
|
||||||
UwU::ColorShader redShader = UwU::ColorShader(red);
|
UwU::ColorShader redShader = UwU::ColorShader(red);
|
||||||
UwU::Triangle triangle = UwU::Triangle(140, 140, 60, 400, 240, 240);
|
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
|
// // Benchmarking
|
||||||
// struct timespec start, end;
|
// struct timespec start, end;
|
||||||
|
|||||||
+14
-3
@@ -9,11 +9,22 @@
|
|||||||
namespace UwU {
|
namespace UwU {
|
||||||
class TileMapper : public MapperBase<TileMapper> { // not actually tilemapping yet
|
class TileMapper : public MapperBase<TileMapper> { // not actually tilemapping yet
|
||||||
public:
|
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) {
|
Coord2 map(uint16_t x0, uint16_t y0, uint16_t x, uint16_t y) {
|
||||||
uint16_t u = x -x0;
|
uint16_t u0 = x - x0;
|
||||||
uint16_t v = y -y0;
|
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);
|
return Coord2(u, v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "../datatypes.cpp"
|
||||||
|
#include "../helpers.cpp"
|
||||||
|
#include "../buffer.cpp"
|
||||||
|
#include "shaderbase.cpp"
|
||||||
|
|
||||||
|
namespace UwU {
|
||||||
|
class BufferShader : public ShaderBase<BufferShader> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
#include "shaderbase.cpp"
|
#include "shaderbase.cpp"
|
||||||
#include "colorshader.cpp"
|
#include "colorshader.cpp"
|
||||||
#include "hgradientshader.cpp"
|
#include "hgradientshader.cpp"
|
||||||
#include "vgradientshader.cpp"
|
#include "vgradientshader.cpp"
|
||||||
|
#include "buffershader.cpp"
|
||||||
Reference in New Issue
Block a user