summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GFX/Image/PPMParser.cpp16
-rw-r--r--src/GFX/Image/PPMParser.hpp2
-rw-r--r--src/GFX/Image/RawImage.cpp4
-rw-r--r--src/GFX/Image/RawImage.hpp2
-rw-r--r--src/GFX/Texture.cpp2
-rw-r--r--src/World/BlockType.hpp12
-rw-r--r--src/World/Generation/ChunkMeshing.cpp6
7 files changed, 30 insertions, 14 deletions
diff --git a/src/GFX/Image/PPMParser.cpp b/src/GFX/Image/PPMParser.cpp
index f002db8..1f62871 100644
--- a/src/GFX/Image/PPMParser.cpp
+++ b/src/GFX/Image/PPMParser.cpp
@@ -68,12 +68,18 @@ RawImage::Pixel PPMParser::parse_pixel(uint8_t max_color) {
 
     auto map_to_range = [=](uint64_t s) -> uint8_t { return s * 255 / max_color; };
 
-    RawImage::Pixel pixel{};
-    pixel.r = map_to_range(r_sample);
-    pixel.g = map_to_range(g_sample);
-    pixel.b = map_to_range(b_sample);
+    RawImage::Pixel p{
+        map_to_range(r_sample),
+        map_to_range(g_sample),
+        map_to_range(b_sample),
+        255
+    };
+
+    if (p.r == alpha_color.r && p.g == alpha_color.g && p.b == alpha_color.b) {
+        p.a = 0;
+    }
 
-    return pixel;
+    return p;
 }
 
 uint64_t PPMParser::parse_sample() {
diff --git a/src/GFX/Image/PPMParser.hpp b/src/GFX/Image/PPMParser.hpp
index 07ff3c2..a7e9b41 100644
--- a/src/GFX/Image/PPMParser.hpp
+++ b/src/GFX/Image/PPMParser.hpp
@@ -37,6 +37,8 @@ private:
 
     bool is_eof() const;
 
+    static constexpr RawImage::Pixel alpha_color{192, 0, 255};
+
     std::string_view m_source;
     uint64_t m_cursor = 0;
 };
diff --git a/src/GFX/Image/RawImage.cpp b/src/GFX/Image/RawImage.cpp
index 6cb06b2..0bd2947 100644
--- a/src/GFX/Image/RawImage.cpp
+++ b/src/GFX/Image/RawImage.cpp
@@ -28,9 +28,9 @@ std::string RawImage::string() const {
 
     bool comma = false;
     str << "[";
-    for (const auto [r, g, b] : m_pixels) {
+    for (const auto [r, g, b, a] : m_pixels) {
         if (comma) { str << ", "; }
-        str << "{r=" << (uint)r << ", g=" << (uint)g << ", b=" << (uint)r << "}";
+        str << "{r=" << (uint)r << ", g=" << (uint)g << ", b=" << (uint)b << ", a=" << (uint)a << "}";
         comma = true;
     }
     str << "]";
diff --git a/src/GFX/Image/RawImage.hpp b/src/GFX/Image/RawImage.hpp
index be3c83a..809ddd9 100644
--- a/src/GFX/Image/RawImage.hpp
+++ b/src/GFX/Image/RawImage.hpp
@@ -16,7 +16,7 @@ public:
     }
 
     struct Pixel {
-        uint8_t r, g, b;
+        uint8_t r, g, b, a;
     };
 
     void add(Pixel pixel);
diff --git a/src/GFX/Texture.cpp b/src/GFX/Texture.cpp
index 64151a5..16f7dce 100644
--- a/src/GFX/Texture.cpp
+++ b/src/GFX/Texture.cpp
@@ -17,7 +17,7 @@ Texture::Texture(const Image::RawImage& image) {
     // will begin at the incorrect byte, causing color artifacts.
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.raw());
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.raw());
     glGenerateMipmap(GL_TEXTURE_2D);
 
     glBindTexture(GL_TEXTURE_2D, 0);
diff --git a/src/World/BlockType.hpp b/src/World/BlockType.hpp
index 472523f..82c63d3 100644
--- a/src/World/BlockType.hpp
+++ b/src/World/BlockType.hpp
@@ -26,6 +26,16 @@ public:
 
     operator Value() const { return m_block; }
 
+    bool is_transparent() const {
+        switch (m_block) {
+        case Air:
+        case Leaves:
+            return true;
+        default:
+            return false;
+        }
+    }
+
     static std::vector<BlockType> all() {
         return {
             Air,
@@ -34,6 +44,8 @@ public:
             Stone,
             Sand,
             Snow,
+            Wood,
+            Leaves,
             Water,
         };
     }
diff --git a/src/World/Generation/ChunkMeshing.cpp b/src/World/Generation/ChunkMeshing.cpp
index 0494da4..e065987 100644
--- a/src/World/Generation/ChunkMeshing.cpp
+++ b/src/World/Generation/ChunkMeshing.cpp
@@ -129,11 +129,7 @@ bool is_face_visible(Chunk& chunk, const ChunkMeshing::ChunkNeighbors& neighbors
     }
 
     auto [neighbor] = chunk_to_ask->get(neighbor_pos.x(), neighbor_pos.y(), neighbor_pos.z());
-    if (neighbor == BlockType::Air) {
-        return true;
-    }
-
-    return false;
+    return neighbor.is_transparent();
 }
 
 GFX::Mesh ChunkMeshing::create_mesh_for_chunk(Chunk& chunk, const ChunkNeighbors& neighbors) {