moved textures into their own classes, better tilemapping
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "texturebase.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class BitmapTexture : public TextureBase<BitmapTexture> {
|
||||
private:
|
||||
Buffer buffer;
|
||||
|
||||
public:
|
||||
BitmapTexture(Buffer buffer) {
|
||||
this->buffer = buffer;
|
||||
}
|
||||
|
||||
Color texel(uint16_t u, uint16_t v) {
|
||||
uint32_t index = (v * buffer.stride) + (u * 4);
|
||||
Color c = Color(buffer.pixels[index + 2], buffer.pixels[index + 1], buffer.pixels[index], buffer.pixels[index + 3]);
|
||||
return c;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "texturebase.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class ColorTexture : public TextureBase<ColorTexture> {
|
||||
private:
|
||||
Color color;
|
||||
|
||||
public:
|
||||
ColorTexture(Color color) {
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
Color texel(uint16_t u, uint16_t v) {
|
||||
(void)u;
|
||||
(void)v;
|
||||
return color;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "texturebase.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class GradientTexture : public TextureBase<GradientTexture> {
|
||||
public:
|
||||
GradientTexture(uint16_t width, Color c0, Color c1) {
|
||||
this->uScale = 0xffffffff / (1 + (uint32_t)width);
|
||||
this->c0 = c0;
|
||||
this->c1 = c1;
|
||||
}
|
||||
uint32_t uScale;
|
||||
Color c0;
|
||||
Color c1;
|
||||
|
||||
Color texel(uint16_t u, uint16_t v) {
|
||||
(void)v;
|
||||
uint32_t t = (((uint32_t)u) * uScale) / 0x01000000;
|
||||
return Helpers::lerpColor(c0, c1, (uint8_t)t);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "texturebase.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class HGradientTexture : public TextureBase<HGradientTexture> {
|
||||
public:
|
||||
HGradientTexture(uint16_t width, Color c0, Color c1) {
|
||||
this->uScale = 0xffffffff / (1 + (uint32_t)width);
|
||||
this->c0 = c0;
|
||||
this->c1 = c1;
|
||||
}
|
||||
uint32_t uScale;
|
||||
Color c0;
|
||||
Color c1;
|
||||
|
||||
Color texel(uint16_t u, uint16_t v) {
|
||||
(void)v;
|
||||
uint32_t t = (((uint32_t)u) * uScale) / 0x01000000;
|
||||
return Helpers::lerpColor(c0, c1, (uint8_t)t);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
|
||||
namespace UwU {
|
||||
template <class TextureT>
|
||||
class TextureBase {
|
||||
public:
|
||||
Color texel(uint16_t u, uint16_t v) {
|
||||
return static_cast<TextureT*>(this)->texel(u, v);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "texturebase.cpp"
|
||||
#include "colortexture.cpp"
|
||||
#include "bitmaptexture.cpp"
|
||||
#include "tilemaptexture.cpp"
|
||||
#include "hgradienttexture.cpp"
|
||||
#include "vgradienttexture.cpp"
|
||||
// #include "gradienttexture.cpp"
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "texturebase.cpp"
|
||||
#include "../tilemap.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class TilemapTexture : public TextureBase<TilemapTexture> {
|
||||
private:
|
||||
Buffer buffer;
|
||||
Tilemap tilemap;
|
||||
|
||||
public:
|
||||
TilemapTexture(Tilemap tilemap, Buffer buffer) {
|
||||
this->buffer = buffer;
|
||||
this->tilemap = tilemap;
|
||||
}
|
||||
|
||||
Color texel(uint16_t u, uint16_t v) {
|
||||
Coord2 bitmapUV = tilemap.map(u, v);
|
||||
uint32_t index = (bitmapUV.y * buffer.stride) + (bitmapUV.x * 4);
|
||||
Color c = Color(buffer.pixels[index + 2], buffer.pixels[index + 1], buffer.pixels[index], buffer.pixels[index + 3]);
|
||||
return c;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "texturebase.cpp"
|
||||
|
||||
namespace UwU {
|
||||
class VGradientTexture : public TextureBase<VGradientTexture> {
|
||||
public:
|
||||
VGradientTexture(uint16_t height, Color c0, Color c1) {
|
||||
this->vScale = 0xffffffff / (1 + (uint32_t)height);
|
||||
this->c0 = c0;
|
||||
this->c1 = c1;
|
||||
}
|
||||
uint32_t vScale;
|
||||
Color c0;
|
||||
Color c1;
|
||||
|
||||
Color texel(uint16_t u, uint16_t v) {
|
||||
(void)u;
|
||||
uint32_t t = (((uint32_t)v) * vScale) / 0x01000000;
|
||||
return Helpers::lerpColor(c0, c1, (uint8_t)t);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user