moved textures into their own classes, better tilemapping

This commit is contained in:
2026-07-25 23:47:54 -07:00
parent e6ce80ce13
commit 1c2579148e
19 changed files with 277 additions and 56 deletions
+5 -5
View File
@@ -6,8 +6,8 @@
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
#include "../shaders/shaders.h"
#include "../mappers/mappers.h"
#include "../textures/textures.h"
namespace UwU {
class Triangle {
@@ -31,8 +31,8 @@ namespace UwU {
uint16_t y2;
// Draw a triangle
template <class MapperT, class ShaderT>
void draw (Buffer buffer, MapperBase<MapperT>& mapper, ShaderBase<ShaderT>& shader) {
template <class MapperT, class TextureT>
void draw (Buffer buffer, MapperBase<MapperT>& mapper, TextureBase<TextureT>& texture) {
uint16_t topX, topY, midX, midY, btmX, btmY;
// Find top, middle and bottom points of triangle
if (y0 <= y1 && y0 <= y2) {
@@ -100,7 +100,7 @@ namespace UwU {
for (uint16_t i = 0; i < height; i++) {
for (uint16_t x = (uint16_t)splitBound[i]; x <= (uint16_t)longBound[i]; x++) {
uv = mapper.map(leftX, topY, x, i + (uint16_t)topY);
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(uv.x, uv.y));
buffer.drawPixel(x, i + (uint16_t)topY, texture.texel(uv.x, uv.y));
}
}
// Right-handed triangle case (midpoint is right of triangle)
@@ -108,7 +108,7 @@ namespace UwU {
for (uint16_t i = 0; i < height; i++) {
for (uint16_t x = (uint16_t)longBound[i]; x <= (uint16_t)splitBound[i]; x++) {
uv = mapper.map(leftX, topY, x, i + (uint16_t)topY);
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(uv.x, uv.y));
buffer.drawPixel(x, i + (uint16_t)topY, texture.texel(uv.x, uv.y));
}
}
}