Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed assets/textures/array.png
Binary file not shown.
Binary file removed assets/textures/atlas.png
Binary file not shown.
Binary file removed assets/textures/blocks.png
Binary file not shown.
Binary file added assets/textures/cobblestone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/dirt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/glass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/grass_side_overlay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/grass_side_snowed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/grass_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/leaves_oak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/leaves_spruce.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/log_oak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/log_oak_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/log_spruce.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/log_spruce_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/planks_oak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/planks_spruce.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/sand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/snow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/water_flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/water_still.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Pos=710,245
Size=500,500

[Window][Debug]
Pos=60,60
Size=500,541
Pos=56,60
Size=555,571

[Window][Fun Bullshit]
Pos=325,62
Expand All @@ -40,6 +40,6 @@ Pos=696,353
Size=528,284

[Window][##CreativeInventory]
Pos=696,399
Size=528,192
Pos=696,371
Size=528,248

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(SOURCES
world/RegionManager.cpp
utils/JobSystem.cpp
world/TerrainGenerator.cpp
world/Biome.cpp
world/CaveGenerator.cpp
world/WaterSimulator.cpp
rendering/ParticleSystem.cpp
Expand All @@ -27,6 +28,7 @@ set(SOURCES
ui/HUD.cpp
core/WorldSession.cpp
core/Renderer.cpp
rendering/Frustum.cpp
)

add_executable(VoxelEngine ${SOURCES})
Expand Down
102 changes: 81 additions & 21 deletions src/core/MainGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
#include <thread>

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#include "../../libs/imgui/imgui.h"
#include "../utils/BlockTypes.h"
#include "../rendering/Camera.h"
#include "../rendering/ItemModelGenerator.h"
#include "../rendering/ToolModelGenerator.h"
#include "../utils/CoordUtils.h"
#include "GameState.h"
#include "../gameplay/Player.h"
#include "../gameplay/Raycast.h"
#include "../rendering/opengl/ShaderClass.h"
#include "../world/Biome.h"
#include "../world/TerrainGenerator.h"

#define STB_IMAGE_IMPLEMENTATION
Expand Down Expand Up @@ -47,6 +51,7 @@ std::string currentWorldName;
float fov = 70.0f;
float mouseSensitivity = 0.1f;
bool wireframeMode = false;
bool showBiomeDebugColors = false;

bool drunkMode = false;
float drunkIntensity = 1.0f;
Expand Down Expand Up @@ -74,6 +79,12 @@ bool enableWaterSimulation = true;
int waterTickRate = 5;
float waterTickAccumulator = 0.0f;
const float WATER_TICK_INTERVAL = 0.05f;
int frustumSolidTested = 0;
int frustumSolidCulled = 0;
int frustumSolidDrawn = 0;
int frustumWaterTested = 0;
int frustumWaterCulled = 0;
int frustumWaterDrawn = 0;

Player* g_player = nullptr;
ChunkManager* g_chunkManager = nullptr;
Expand Down Expand Up @@ -134,29 +145,70 @@ GLuint loadHUDIcon(const std::string& path, bool useNearest)
return texture;
}

void loadBlockIcons(const std::string& basePath)
void generateBlockIcons(GLuint textureArray, Shader* itemModelShader)
{
std::unordered_map<uint8_t, std::string> iconFiles = {
{1, "natural_dirt.png"},
{2, "natural_grass_block.png"},
{3, "masonry_cobblestone.png"},
{4, "natural_sand.png"},
{5, "log_oak.png"},
{6, "leaves_oak.png"},
{7, "transparent_glass.png"},
{8, "planks_oak.png"}
};

for (const auto& [blockId, filename] : iconFiles)
constexpr int ICON_SIZE = 128;

GLuint fbo, rbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);

glGenRenderbuffers(1, &rbo);
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, ICON_SIZE, ICON_SIZE);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);

GLint prevViewport[4];
glGetIntegerv(GL_VIEWPORT, prevViewport);
glViewport(0, 0, ICON_SIZE, ICON_SIZE);

glm::vec3 center(0.5f, 0.5f, 0.5f);
glm::mat4 proj = glm::ortho(-0.85f, 0.85f, 0.85f, -0.85f, 0.1f, 10.0f);
glm::vec3 eye = center + glm::normalize(glm::vec3(1.0f, 0.8f, 1.0f)) * 2.5f;
glm::mat4 view = glm::lookAt(eye, center, glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 mvp = proj * view;

itemModelShader->Activate();
glUniform1f(glGetUniformLocation(itemModelShader->ID, "timeOfDay"), 1.0f);
glUniform1f(glGetUniformLocation(itemModelShader->ID, "ambientLight"), 1.0f);
glUniformMatrix4fv(glGetUniformLocation(itemModelShader->ID, "transform"),
1, GL_FALSE, glm::value_ptr(mvp));
glUniform1i(glGetUniformLocation(itemModelShader->ID, "textureArray"), 0);

glEnable(GL_DEPTH_TEST);

for (auto& [blockId, model] : g_itemModels)
{
std::string fullPath = basePath + "/" + filename;
GLuint tex = loadHUDIcon(fullPath);
if (tex != 0)
{
g_blockIcons[blockId] = tex;
std::cout << "Loaded HUD icon for block " << (int)blockId << ": " << filename << std::endl;
}
GLuint iconTex;
glGenTextures(1, &iconTex);
glBindTexture(GL_TEXTURE_2D, iconTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ICON_SIZE, ICON_SIZE, 0,
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, iconTex, 0);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, textureArray);

glBindVertexArray(model.vao);
glDrawElements(GL_TRIANGLES, model.indexCount, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);

g_blockIcons[blockId] = iconTex;
}

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &fbo);
glDeleteRenderbuffers(1, &rbo);
glViewport(prevViewport[0], prevViewport[1], prevViewport[2], prevViewport[3]);
}

void unloadBlockIcons()
Expand Down Expand Up @@ -532,7 +584,15 @@ void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
skyLight = static_cast<float>(c->skyLight[blockIndex(local.x, local.y, local.z)]) / static_cast<float>(MAX_SKY_LIGHT);
}
}
g_particleSystem->spawnBlockBreakParticles(blockCenter, tileIndex, skyLight, 15);
glm::vec4 particleTint(1.0f);
if (g_blockTypes[oldBlock].faceTint[0])
{
BiomeID biome = getBiomeAt(hit->blockPos.x, hit->blockPos.z);
bool isLeaf = g_blockTypes[oldBlock].transparent && g_blockTypes[oldBlock].solid;
glm::vec3 t = isLeaf ? getBiomeFoliageTint(biome) : getBiomeGrassTint(biome);
particleTint = glm::vec4(t, 1.0f);
}
g_particleSystem->spawnBlockBreakParticles(blockCenter, tileIndex, skyLight, 15, particleTint);
}

return;
Expand Down
11 changes: 10 additions & 1 deletion src/core/MainGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "../rendering/ParticleSystem.h"
#include "GameState.h"

class Shader;

extern const int SCREEN_WIDTH;
extern const int SCREEN_HEIGHT;
extern const float MAX_RAYCAST_DISTANCE;
Expand All @@ -35,6 +37,7 @@ extern std::string currentWorldName;
extern float fov;
extern float mouseSensitivity;
extern bool wireframeMode;
extern bool showBiomeDebugColors;

extern bool drunkMode;
extern float drunkIntensity;
Expand Down Expand Up @@ -64,6 +67,12 @@ extern bool enableWaterSimulation;
extern int waterTickRate;
extern float waterTickAccumulator;
extern const float WATER_TICK_INTERVAL;
extern int frustumSolidTested;
extern int frustumSolidCulled;
extern int frustumSolidDrawn;
extern int frustumWaterTested;
extern int frustumWaterCulled;
extern int frustumWaterDrawn;

extern Player* g_player;
extern ChunkManager* g_chunkManager;
Expand All @@ -79,6 +88,6 @@ void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
void scrollCallback(GLFWwindow* window, double xoffset, double yoffset);
std::string resolveTexturePath(const std::string& relativePath);
GLuint loadHUDIcon(const std::string& path, bool useNearest = false);
void loadBlockIcons(const std::string& basePath);
void generateBlockIcons(GLuint textureArray, Shader* itemModelShader);
void unloadBlockIcons();
void executeCommand(const std::string& input, Player& player);
Loading