Large changes to documentation
This commit is contained in:
@@ -92,8 +92,7 @@ enum block_id
|
||||
id_null
|
||||
};
|
||||
|
||||
// Returns true if the given block_id has any non-opaque pixels. Otherwise,
|
||||
// returns false.
|
||||
// Returns true if the block is not opaque. Otherwise, returns false.
|
||||
|
||||
inline bool is_transparent(block_id id)
|
||||
{
|
||||
@@ -114,7 +113,7 @@ inline bool is_transparent(block_id id)
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Conversion from block_id to std::string.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <vector>
|
||||
|
||||
// A struct of type face_info represents the layer (w coordinate) of each face
|
||||
// of a block. It is used to map the correct texture on to each face of a
|
||||
// of a block. It is used to map the correct texture onto each face of a
|
||||
// block.
|
||||
|
||||
struct face_info
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// A list of all the files in /tex (excluding file extensions).
|
||||
// A list of all the files in tex/ (excluding file extensions).
|
||||
|
||||
std::vector<std::string> all_tex =
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Convert a subset of a world into a vertex array (also called a mesh). The
|
||||
// generated vertex array is stored in target, and it's size (in floats) is
|
||||
// stored in target_size_in_floats.
|
||||
// Convert a subset of a world into a vertex array. The generated vertex
|
||||
// array is stored in target, and it's size in floats is stored in
|
||||
// target_size_in_floats.
|
||||
|
||||
void world_subset_to_mesh
|
||||
(
|
||||
@@ -43,8 +43,6 @@ void world_subset_to_mesh
|
||||
block_id voxel_id = input->get_id(cx, cy, cz);
|
||||
|
||||
// Ignore voxels that have a block_id equivalent to id_air.
|
||||
// Voxels that have a block_id equivalent to id_air are fully
|
||||
// transparent, and do not need to be rendered.
|
||||
|
||||
if (voxel_id == id_air)
|
||||
{
|
||||
@@ -56,8 +54,8 @@ void world_subset_to_mesh
|
||||
|
||||
face_info* cube_face_info = block_face_info[voxel_id];
|
||||
|
||||
// Get the layer index corresponding to each face of the
|
||||
// current voxel.
|
||||
// Get the layer (w coordinate) corresponding to each face of
|
||||
// the current voxel.
|
||||
|
||||
float layer_top = cube_face_info->l_top;
|
||||
|
||||
@@ -84,7 +82,7 @@ void world_subset_to_mesh
|
||||
float voxel_light = std::max(voxel_light_natural, voxel_light_artificial);
|
||||
|
||||
// Calculate the lighting value of each face by multiplying
|
||||
// the lighting value of the current voxel by a constant
|
||||
// the final lighting value of the current voxel by a constant
|
||||
// coefficient.
|
||||
|
||||
float lighting_top = 1.0f * voxel_light;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <string>
|
||||
|
||||
// Load a shader program from two files. One is a vertex shader, and one is a
|
||||
// fragment shader. Geometry shader support is not implemented.
|
||||
// fragment shader.
|
||||
|
||||
GLuint load_program(std::string vertex_path, std::string fragment_path)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ GLuint load_block_texture_array()
|
||||
|
||||
int channels = 4;
|
||||
|
||||
// The texture array must have one layer for each texture in all_tex.
|
||||
// The texture array must have one layer for each texture path in all_tex.
|
||||
|
||||
GLsizei layers = all_tex.size();
|
||||
|
||||
@@ -68,7 +68,7 @@ GLuint load_block_texture_array()
|
||||
exit(12);
|
||||
}
|
||||
|
||||
// Copy the sub-texture texels to the texel array.
|
||||
// Copy the sub-texture's texels to the texel array.
|
||||
|
||||
memcpy(texels + (i * x_res * y_res * channels), sub_data, x_res * y_res * channels);
|
||||
|
||||
@@ -76,7 +76,8 @@ GLuint load_block_texture_array()
|
||||
|
||||
stbi_image_free(sub_data);
|
||||
|
||||
// Add to map.
|
||||
// Add a map entry that has a key of the sub-texture's name and a
|
||||
// value of the sub-texture's layer index to the map.
|
||||
|
||||
block_name_to_layer.emplace(all_tex[i], float(i));
|
||||
}
|
||||
@@ -87,6 +88,8 @@ GLuint load_block_texture_array()
|
||||
|
||||
glGenTextures(1, &texture_array);
|
||||
|
||||
// Bind the texture array to the current state.
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, texture_array);
|
||||
|
||||
// Allocate storage for the 2D texture array.
|
||||
@@ -105,7 +108,7 @@ GLuint load_block_texture_array()
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// Unbind the texture array.
|
||||
// Unbind the texture array from the current state.
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
|
||||
|
||||
@@ -113,7 +116,7 @@ GLuint load_block_texture_array()
|
||||
|
||||
free(texels);
|
||||
|
||||
// Return the output std::map.
|
||||
// Return the reference to the texture array.
|
||||
|
||||
return texture_array;
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
// A voxel can be represented with 16 bits of data. The last 8 bits hold the
|
||||
// block_id information (that allows 256 distinct block_id values). The first
|
||||
// 4 bits hold the natural light information, and the second 4 bits hold the
|
||||
// artificial light information. That allows for 16 unique lighting values for
|
||||
// each lighting component, and 256 unique lighting permutations in total.
|
||||
// block_id information. The first 4 bits hold the natural light information,
|
||||
// and the second 4 bits hold the artificial light information.
|
||||
|
||||
typedef unsigned short voxel;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
// A world struct hold information about a worlds dimensions and block data.
|
||||
// A world struct holds information about a world's dimensions and block data.
|
||||
// It makes it easy and efficient to modify and read the properties of every
|
||||
// voxel it contains.
|
||||
|
||||
@@ -198,8 +198,8 @@ world* allocate_world(unsigned int x_res, unsigned int y_res, unsigned int z_res
|
||||
return new_world;
|
||||
}
|
||||
|
||||
// Deallocate a world*'s voxels, and then delete the pointer to the underlying
|
||||
// world object.
|
||||
// Deallocate a world*'s voxels, and then delete the pointer to the world
|
||||
// object.
|
||||
|
||||
void deallocate_world(world* to_be_annihilated)
|
||||
{
|
||||
|
||||
14
src/main.hpp
14
src/main.hpp
@@ -2,9 +2,7 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
// GLM is used as the mathematics library. It provides functions that are
|
||||
// based on GLSL, and makes it really easy to generate projection and view
|
||||
// matrices.
|
||||
// GLM is used as the mathematics library.
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
@@ -12,19 +10,15 @@
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
// GLAD is used as the loader for OpenGL functions. On operating systems such
|
||||
// as OS X, a loader is not necessarily needed. However, on most other
|
||||
// systems, a loader is required in order to use any OpenGL functions.
|
||||
// GLAD is used as the loader for OpenGL functions.
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
// SDL2 is used as the multimedia interface for Minceraft. It provides
|
||||
// cross-platform functions that allow easy access to the operating system.
|
||||
// SDL2 is used as the multimedia interface.
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
// stb_image is used as the image loading library. It makes it as simple as
|
||||
// one function call to load a .png image.
|
||||
// stb_image is used as the image loading library.
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
|
||||
|
||||
Reference in New Issue
Block a user