Browse Source

Initial commit.

Manoel Trapier 1 year ago
commit
9012ff281f

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+
+*.o
+
+.idea/
+cmake-*/

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "external/upng"]
+	path = external/upng
+	url = https://github.com/elanthis/upng

+ 27 - 0
CMakeLists.txt

@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 3.1)
+
+# External cmake modules
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/cmake ${CMAKE_MODULE_PATH})
+
+project("Voxel-a-tord")
+
+include(Buildupng)
+include(GetGitRevisionDescription)
+git_describe(VERSION --tags --dirty=-dirty)
+
+option(WARN_AS_ERROR "Enable warning as error" OFF)
+
+set(COMP_FLAGS "-march=native -Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings")
+
+if (WARN_AS_ERROR)
+    set(COMP_FLAGS "${COMP_FLAGS} -Werror")
+endif()
+
+set(CMAKE_C_FLAGS ${COMP_FLAGS})
+set(CMAKE_CXX_FLAGS ${COMP_FLAGS})
+
+message("-- Building version ${VERSION}")
+
+add_compile_definitions(VERSION="${VERSION}")
+
+add_subdirectory(source)

File diff suppressed because it is too large
+ 20 - 0
assets/C1W.png


File diff suppressed because it is too large
+ 20 - 0
assets/C5W.png


File diff suppressed because it is too large
+ 20 - 0
assets/C9W.png


File diff suppressed because it is too large
+ 20 - 0
assets/D1.png


File diff suppressed because it is too large
+ 20 - 0
assets/D5.png


File diff suppressed because it is too large
+ 20 - 0
assets/D9.png


+ 32 - 0
external/cmake/BuildImGui.cmake

@@ -0,0 +1,32 @@
+cmake_minimum_required(VERSION 3.1)
+project(ImGui)
+include(ExternalProject)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+find_package(SDL2 REQUIRED)
+set(SDL2_INCDIR ${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIR} ${SDL2_MIXER_INCLUDE_DIR})
+
+add_library(ImGui STATIC)
+target_include_directories(ImGui PUBLIC ${SDL2_INCDIR})
+target_include_directories(ImGui PUBLIC external/imgui)
+target_include_directories(ImGui PUBLIC external/imgui/backends)
+
+file(GLOB ImG_SOURCES external/imgui/*.cpp external/imgui/backends/imgui_impl_sdl.cpp)
+file(GLOB ImG_HEADERS external/imgui/*.h external/imgui/backends/imgui_impl_sdl.h)
+
+target_sources(ImGui PRIVATE ${ImG_SOURCES} ${ImG_HEADERS})
+
+
+add_library(ImGuiSDL STATIC)
+message("SDL Dir: ${SDL2_INCDIR}")
+target_include_directories(ImGuiSDL PUBLIC ${SDL2_INCDIR})
+target_include_directories(ImGuiSDL PUBLIC external/imgui_sdl)
+target_include_directories(ImGuiSDL PUBLIC external/imgui)
+
+set(ImGSDL_SOURCES external/imgui_sdl/imgui_sdl.cpp)
+file(GLOB ImGSLD_HEADERS external/imgui_sdl/*.h)
+
+target_sources(ImGuiSDL PRIVATE ${ImGSDL_SOURCES} ${ImGSDL_HEADERS})

+ 10 - 0
external/cmake/Buildupng.cmake

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1)
+include(ExternalProject)
+
+add_library(uPNG STATIC)
+target_include_directories(uPNG PUBLIC external/upng)
+
+set(UPNG_SOURCES external/upng/upng.c)
+set(UPNG_HEADERS external/upng/upng.h)
+
+target_sources(uPNG PRIVATE ${UPNG_SOURCES} ${UPNG_HEADERS})

+ 102 - 0
external/cmake/FindSDL2_image.cmake

@@ -0,0 +1,102 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+# based on https://trenki2.github.io/blog/2017/07/04/using-sdl2-image-with-cmake/
+
+#.rst:
+# FindSDL2_image
+# -------------
+#
+# Locate SDL2_image library
+#
+# This module defines:
+#
+# ::
+#
+# SDL2_IMAGE_LIBRARIES, the name of the library to link against
+# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers
+# SDL2_IMAGE_FOUND, if false, do not try to link against
+# SDL2_IMAGE_VERSION_STRING - human-readable string containing the
+# version of SDL2_image
+#
+#
+#
+# For backward compatibility the following variables are also set:
+#
+# ::
+#
+# SDL2IMAGE_LIBRARY (same value as SDL2_IMAGE_LIBRARIES)
+# SDL2IMAGE_INCLUDE_DIR (same value as SDL2_IMAGE_INCLUDE_DIRS)
+# SDL2IMAGE_FOUND (same value as SDL2_IMAGE_FOUND)
+#
+#
+#
+# $SDLDIR is an environment variable that would correspond to the
+# ./configure --prefix=$SDLDIR used in building SDL.
+#
+# Created by Eric Wing. This was influenced by the FindSDL.cmake
+# module, but with modifications to recognize OS X frameworks and
+# additional Unix paths (FreeBSD, etc).
+
+if(NOT SDL2_IMAGE_INCLUDE_DIR AND SDL2IMAGE_INCLUDE_DIR)
+    set(SDL2_IMAGE_INCLUDE_DIR ${SDL2IMAGE_INCLUDE_DIR} CACHE PATH "directory cache entry initialized from old variable name")
+endif()
+find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
+        HINTS
+        ENV SDL2IMAGEDIR
+        ENV SDL2DIR
+        ${SDL2_DIR}
+        PATH_SUFFIXES SDL2
+        # path suffixes to search inside ENV{SDL2DIR}
+        include/SDL2 include
+        )
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+    set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+    set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+if(NOT SDL2_IMAGE_LIBRARY AND SDL2IMAGE_LIBRARY)
+    set(SDL2_IMAGE_LIBRARY ${SDL2IMAGE_LIBRARY} CACHE FILEPATH "file cache entry initialized from old variable name")
+endif()
+find_library(SDL2_IMAGE_LIBRARY
+        NAMES SDL2_image
+        HINTS
+        ENV SDL2IMAGEDIR
+        ENV SDL2DIR
+        ${SDL2_DIR}
+        PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+        )
+
+if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL2_image.h")
+    file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL2_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL2_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$")
+    file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL2_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_IMAGE_MINOR_VERSION[ \t]+[0-9]+$")
+    file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL2_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_IMAGE_PATCHLEVEL[ \t]+[0-9]+$")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}")
+    set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH})
+    unset(SDL2_IMAGE_VERSION_MAJOR_LINE)
+    unset(SDL2_IMAGE_VERSION_MINOR_LINE)
+    unset(SDL2_IMAGE_VERSION_PATCH_LINE)
+    unset(SDL2_IMAGE_VERSION_MAJOR)
+    unset(SDL2_IMAGE_VERSION_MINOR)
+    unset(SDL2_IMAGE_VERSION_PATCH)
+endif()
+
+set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY})
+set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR})
+
+include(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image
+        REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS
+        VERSION_VAR SDL2_IMAGE_VERSION_STRING)
+
+# for backward compatibility
+set(SDL2IMAGE_LIBRARY ${SDL2_IMAGE_LIBRARIES})
+set(SDL2IMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIRS})
+set(SDL2IMAGE_FOUND ${SDL2_IMAGE_FOUND})
+
+mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)

+ 102 - 0
external/cmake/FindSDL2_mixer.cmake

@@ -0,0 +1,102 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+# based on https://trenki2.github.io/blog/2017/07/04/using-sdl2-image-with-cmake/
+
+#.rst:
+# FindSDL2_mixer
+# -------------
+#
+# Locate SDL2_mixer library
+#
+# This module defines:
+#
+# ::
+#
+# SDL2_MIXER_LIBRARIES, the name of the library to link against
+# SDL2_MIXER_INCLUDE_DIRS, where to find the headers
+# SDL2_MIXER_FOUND, if false, do not try to link against
+# SDL2_MIXER_VERSION_STRING - human-readable string containing the
+# version of SDL2_mixer
+#
+#
+#
+# For backward compatibility the following variables are also set:
+#
+# ::
+#
+# SDL2MIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES)
+# SDL2MIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS)
+# SDL2MIXER_FOUND (same value as SDL2_MIXER_FOUND)
+#
+#
+#
+# $SDLDIR is an environment variable that would correspond to the
+# ./configure --prefix=$SDLDIR used in building SDL.
+#
+# Created by Eric Wing. This was influenced by the FindSDL.cmake
+# module, but with modifications to recognize OS X frameworks and
+# additional Unix paths (FreeBSD, etc).
+
+if(NOT SDL2_MIXER_INCLUDE_DIR AND SDL2MIXER_INCLUDE_DIR)
+    set(SDL2_MIXER_INCLUDE_DIR ${SDL2MIXER_INCLUDE_DIR} CACHE PATH "directory cache entry initialized from old variable name")
+endif()
+find_path(SDL2_MIXER_INCLUDE_DIR SDL_image.h
+        HINTS
+        ENV SDL2MIXERDIR
+        ENV SDL2DIR
+        ${SDL2_DIR}
+        PATH_SUFFIXES SDL2
+        # path suffixes to search inside ENV{SDL2DIR}
+        include/SDL2 include
+        )
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+    set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+    set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+if(NOT SDL2_MIXER_LIBRARY AND SDL2MIXER_LIBRARY)
+    set(SDL2_MIXER_LIBRARY ${SDL2MIXER_LIBRARY} CACHE FILEPATH "file cache entry initialized from old variable name")
+endif()
+find_library(SDL2_MIXER_LIBRARY
+        NAMES SDL2_mixer
+        HINTS
+        ENV SDL2MIXERDIR
+        ENV SDL2DIR
+        ${SDL2_DIR}
+        PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+        )
+
+if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL2_mixer.h")
+    file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL2_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL2_MIXER_MAJOR_VERSION[ \t]+[0-9]+$")
+    file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL2_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_MIXER_MINOR_VERSION[ \t]+[0-9]+$")
+    file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL2_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_MIXER_PATCHLEVEL[ \t]+[0-9]+$")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}")
+    set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH})
+    unset(SDL2_MIXER_VERSION_MAJOR_LINE)
+    unset(SDL2_MIXER_VERSION_MINOR_LINE)
+    unset(SDL2_MIXER_VERSION_PATCH_LINE)
+    unset(SDL2_MIXER_VERSION_MAJOR)
+    unset(SDL2_MIXER_VERSION_MINOR)
+    unset(SDL2_MIXER_VERSION_PATCH)
+endif()
+
+set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY})
+set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR})
+
+include(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer
+        REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS
+        VERSION_VAR SDL2_MIXER_VERSION_STRING)
+
+# for backward compatibility
+set(SDL2MIXER_LIBRARY ${SDL2_MIXER_LIBRARIES})
+set(SDL2MIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS})
+set(SDL2MIXER_FOUND ${SDL2_MIXER_FOUND})
+
+mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR)

+ 102 - 0
external/cmake/FindSDL2_ttf.cmake

@@ -0,0 +1,102 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+# based on https://trenki2.github.io/blog/2017/07/04/using-sdl2-image-with-cmake/
+
+#.rst:
+# FindSDL2_ttf
+# -------------
+#
+# Locate SDL2_ttf library
+#
+# This module defines:
+#
+# ::
+#
+# SDL2_TTF_LIBRARIES, the name of the library to link against
+# SDL2_TTF_INCLUDE_DIRS, where to find the headers
+# SDL2_TTF_FOUND, if false, do not try to link against
+# SDL2_TTF_VERSION_STRING - human-readable string containing the
+# version of SDL2_ttf
+#
+#
+#
+# For backward compatibility the following variables are also set:
+#
+# ::
+#
+# SDL2TTF_LIBRARY (same value as SDL2_TTF_LIBRARIES)
+# SDL2TTF_INCLUDE_DIR (same value as SDL2_TTF_INCLUDE_DIRS)
+# SDL2TTF_FOUND (same value as SDL2_TTF_FOUND)
+#
+#
+#
+# $SDLDIR is an environment variable that would correspond to the
+# ./configure --prefix=$SDLDIR used in building SDL.
+#
+# Created by Eric Wing. This was influenced by the FindSDL.cmake
+# module, but with modifications to recognize OS X frameworks and
+# additional Unix paths (FreeBSD, etc).
+
+if(NOT SDL2_TTF_INCLUDE_DIR AND SDL2TTF_INCLUDE_DIR)
+    set(SDL2_TTF_INCLUDE_DIR ${SDL2TTF_INCLUDE_DIR} CACHE PATH "directory cache entry initialized from old variable name")
+endif()
+find_path(SDL2_TTF_INCLUDE_DIR SDL_image.h
+        HINTS
+        ENV SDL2TTFDIR
+        ENV SDL2DIR
+        ${SDL2_DIR}
+        PATH_SUFFIXES SDL2
+        # path suffixes to search inside ENV{SDL2DIR}
+        include/SDL2 include
+        )
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+    set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+    set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+if(NOT SDL2_TTF_LIBRARY AND SDL2TTF_LIBRARY)
+    set(SDL2_TTF_LIBRARY ${SDL2TTF_LIBRARY} CACHE FILEPATH "file cache entry initialized from old variable name")
+endif()
+find_library(SDL2_TTF_LIBRARY
+        NAMES SDL2_ttf
+        HINTS
+        ENV SDL2TTFDIR
+        ENV SDL2DIR
+        ${SDL2_DIR}
+        PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+        )
+
+if(SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL2_ttf.h")
+    file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL2_ttf.h" SDL2_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL2_TTF_MAJOR_VERSION[ \t]+[0-9]+$")
+    file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL2_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_TTF_MINOR_VERSION[ \t]+[0-9]+$")
+    file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL2_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_TTF_PATCHLEVEL[ \t]+[0-9]+$")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}")
+    string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}")
+    set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH})
+    unset(SDL2_TTF_VERSION_MAJOR_LINE)
+    unset(SDL2_TTF_VERSION_MINOR_LINE)
+    unset(SDL2_TTF_VERSION_PATCH_LINE)
+    unset(SDL2_TTF_VERSION_MAJOR)
+    unset(SDL2_TTF_VERSION_MINOR)
+    unset(SDL2_TTF_VERSION_PATCH)
+endif()
+
+set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY})
+set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR})
+
+include(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf
+        REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS
+        VERSION_VAR SDL2_TTF_VERSION_STRING)
+
+# for backward compatibility
+set(SDL2TTF_LIBRARY ${SDL2_TTF_LIBRARIES})
+set(SDL2TTF_INCLUDE_DIR ${SDL2_TTF_INCLUDE_DIRS})
+set(SDL2TTF_FOUND ${SDL2_TTF_FOUND})
+
+mark_as_advanced(SDL2_TTF_LIBRARY SDL2_TTF_INCLUDE_DIR)

+ 168 - 0
external/cmake/GetGitRevisionDescription.cmake

@@ -0,0 +1,168 @@
+# - Returns a version string from Git
+#
+# These functions force a re-configure on each git commit so that you can
+# trust the values of the variables in your build system.
+#
+#  get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
+#
+# Returns the refspec and sha hash of the current head revision
+#
+#  git_describe(<var> [<additional arguments to git describe> ...])
+#
+# Returns the results of git describe on the source tree, and adjusting
+# the output so that it tests false if an error occurs.
+#
+#  git_get_exact_tag(<var> [<additional arguments to git describe> ...])
+#
+# Returns the results of git describe --exact-match on the source tree,
+# and adjusting the output so that it tests false if there was no exact
+# matching tag.
+#
+#  git_local_changes(<var>)
+#
+# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
+# Uses the return code of "git diff-index --quiet HEAD --".
+# Does not regard untracked files.
+#
+# Requires CMake 2.6 or newer (uses the 'function' command)
+#
+# Original Author:
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2009-2010.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+if(__get_git_revision_description)
+    return()
+endif()
+set(__get_git_revision_description YES)
+
+# We must run the following at "include" time, not at function call time,
+# to find the path to this module rather than the path to a calling list file
+get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+function(get_git_head_revision _refspecvar _hashvar)
+    set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+    set(GIT_DIR "${GIT_PARENT_DIR}/.git")
+    while(NOT EXISTS "${GIT_DIR}")	# .git dir not found, search parent directories
+        set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
+        get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
+        if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
+            # We have reached the root directory, we are not in git
+            set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+            set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+            return()
+        endif()
+        set(GIT_DIR "${GIT_PARENT_DIR}/.git")
+    endwhile()
+    # check if this is a submodule
+    if(NOT IS_DIRECTORY ${GIT_DIR})
+        file(READ ${GIT_DIR} submodule)
+        string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
+        get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
+        get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
+    endif()
+    set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
+    if(NOT EXISTS "${GIT_DATA}")
+        file(MAKE_DIRECTORY "${GIT_DATA}")
+    endif()
+
+    if(NOT EXISTS "${GIT_DIR}/HEAD")
+        return()
+    endif()
+    set(HEAD_FILE "${GIT_DATA}/HEAD")
+    configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
+
+    configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
+            "${GIT_DATA}/grabRef.cmake"
+            @ONLY)
+    include("${GIT_DATA}/grabRef.cmake")
+
+    set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
+    set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
+endfunction()
+
+function(git_describe _var)
+    if(NOT GIT_FOUND)
+        find_package(Git QUIET)
+    endif()
+    get_git_head_revision(refspec hash)
+    if(NOT GIT_FOUND)
+        set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+    if(NOT hash)
+        set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+
+    # TODO sanitize
+    #if((${ARGN}" MATCHES "&&") OR
+    #	(ARGN MATCHES "||") OR
+    #	(ARGN MATCHES "\\;"))
+    #	message("Please report the following error to the project!")
+    #	message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
+    #endif()
+
+    #message(STATUS "Arguments to execute_process: ${ARGN}")
+
+    execute_process(COMMAND
+            "${GIT_EXECUTABLE}"
+            describe
+            #${hash}
+            ${ARGN}
+            WORKING_DIRECTORY
+            "${CMAKE_CURRENT_SOURCE_DIR}"
+            RESULT_VARIABLE
+            res
+            OUTPUT_VARIABLE
+            out
+            ERROR_QUIET
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(NOT res EQUAL 0)
+        set(out "${out}-${res}-NOTFOUND")
+    endif()
+
+    set(${_var} "${out}" PARENT_SCOPE)
+endfunction()
+
+function(git_get_exact_tag _var)
+    git_describe(out --exact-match ${ARGN})
+    set(${_var} "${out}" PARENT_SCOPE)
+endfunction()
+
+function(git_local_changes _var)
+    if(NOT GIT_FOUND)
+        find_package(Git QUIET)
+    endif()
+    get_git_head_revision(refspec hash)
+    if(NOT GIT_FOUND)
+        set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+    if(NOT hash)
+        set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+
+    execute_process(COMMAND
+            "${GIT_EXECUTABLE}"
+            diff-index --quiet HEAD --
+            WORKING_DIRECTORY
+            "${CMAKE_CURRENT_SOURCE_DIR}"
+            RESULT_VARIABLE
+            res
+            OUTPUT_VARIABLE
+            out
+            ERROR_QUIET
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(res EQUAL 0)
+        set(${_var} "CLEAN" PARENT_SCOPE)
+    else()
+        set(${_var} "DIRTY" PARENT_SCOPE)
+    endif()
+endfunction()

+ 41 - 0
external/cmake/GetGitRevisionDescription.cmake.in

@@ -0,0 +1,41 @@
+#
+# Internal file for GetGitRevisionDescription.cmake
+#
+# Requires CMake 2.6 or newer (uses the 'function' command)
+#
+# Original Author:
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2009-2010.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+set(HEAD_HASH)
+
+file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
+
+string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
+if(HEAD_CONTENTS MATCHES "ref")
+	# named branch
+	string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
+	if(EXISTS "@GIT_DIR@/${HEAD_REF}")
+		configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
+	else()
+		configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
+		file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
+		if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
+			set(HEAD_HASH "${CMAKE_MATCH_1}")
+		endif()
+	endif()
+else()
+	# detached HEAD
+	configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
+endif()
+
+if(NOT HEAD_HASH)
+	file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
+	string(STRIP "${HEAD_HASH}" HEAD_HASH)
+endif()

+ 31 - 0
external/cmake/GetLua.cmake

@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 3.1)
+include(ExternalProject)
+
+# This file will
+function(AddExternalLua _lua_version _lua_hash)
+
+    if (CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
+        set(LUA_MAKE_TARGET linux)
+    elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
+        set(LUA_MAKE_TARGET macosx)
+    elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
+        set(LUA_MAKE_TARGET posix)
+    else()
+        set(LUA_MAKE_TARGET posix)
+    endif()
+    message("-- Lua: Building Lua for ${LUA_MAKE_TARGET}")
+
+    ExternalProject_Add(LuaCore
+            URL "https://www.lua.org/ftp/lua-${_lua_version}.tar.gz"
+            URL_HASH SHA1=${_lua_hash}
+            SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/lua
+            CONFIGURE_COMMAND ""
+            BUILD_IN_SOURCE True
+            BUILD_COMMAND make ${LUA_MAKE_TARGET}
+            INSTALL_COMMAND ""
+            )
+
+    set(LUA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/lua/src" PARENT_SCOPE)
+    set(LUA_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/external/lua/src/liblua.a" "-ldl" PARENT_SCOPE)
+
+endfunction()

+ 1 - 0
external/upng

@@ -0,0 +1 @@
+Subproject commit 01937b7d1c0a4491d49511cbb227163911476867

+ 16 - 0
source/CMakeLists.txt

@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.1)
+
+find_package(SDL2 REQUIRED)
+find_package(SDL2_ttf REQUIRED)
+
+set(SDL2_LIBS ${SDL2_LIBRARIES} ${SDL2_TTF_LIBRARY})
+set(SDL2_INCDIR ${SDL2_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIR})
+
+file(GLOB_RECURSE VAT_SOURCES *.c)
+file(GLOB_RECURSE VAT_HEADERS include/*.h)
+
+add_executable(voxelator)
+target_include_directories(voxelator PUBLIC include/)
+target_sources(voxelator PRIVATE ${VAT_SOURCES} ${VAT_HEADERS})
+target_include_directories(voxelator PUBLIC ${SDL2_INCDIR})
+target_link_libraries(voxelator ${SDL2_LIBS} uPNG m)

+ 457 - 0
source/display.c

@@ -0,0 +1,457 @@
+/*
+ * Voxel-a-tord
+ * display.c:
+ * Copyright (c) 2021-2022 986-Studio. All rights reserved.
+ *
+ * Created by Manoël Trapier on 01/03/2021.
+ */
+
+#include <stdio.h>
+#include <stdbool.h>
+
+#include <SDL.h>
+#include <SDL_ttf.h>
+
+#include <3dengine.h>
+#include <log.h>
+#include <display.h>
+
+/***********************************************************************************************************************
+ * Variables
+ **********************************************************************************************************************/
+static SDL_Window *window = NULL;
+static SDL_Renderer *renderer = NULL;
+static colour_t *frameBuffer = NULL;
+static double *zBuffer = NULL;
+static SDL_Texture *frameBufferTexture = NULL;
+static int32_t windowWidth = 1024;
+static int32_t windowHeight = 768;
+static TTF_Font *font = NULL;
+
+/***********************************************************************************************************************
+ * Functions
+ **********************************************************************************************************************/
+#define MAX(_a, _b) ((_a) < (_b)) ? (_b) : (_a)
+#define MIN(_a, _b) ((_a) > (_b)) ? (_b) : (_a)
+
+bool initialiseWindow(int32_t width, int32_t height, bool fullScreen)
+{
+    bool ret = false;
+    int windowFlags = 0;
+    int fullscreenWidth;
+    int fullscreenHeight;
+
+    if (SDL_Init(SDL_INIT_EVERYTHING))
+    {
+        Log(TLOG_PANIC, NULL, "SDL Initialisation error!! error: %s", SDL_GetError());
+        goto exit;
+    }
+
+    Log(TLOG_DEBUG, NULL, "SDL properly initialised!");
+
+    ret = TTF_Init();
+    if (ret)
+    {
+        Log(TLOG_PANIC, NULL, "SDL_ttf Initialisation error!! error: %s", SDL_GetError());
+        goto exit;
+    }
+
+    windowWidth = width;
+    windowHeight = height;
+
+    if (fullScreen)
+    {
+        Log(TLOG_DEBUG, NULL, "Will go fullscreen! Fasten your seatbelts!");
+        SDL_DisplayMode displayMode;
+        SDL_GetCurrentDisplayMode(0, &displayMode);
+
+        fullscreenWidth = displayMode.w;
+        fullscreenHeight = displayMode.h;
+
+        windowFlags = SDL_WINDOW_BORDERLESS;
+    }
+    else
+    {
+        fullscreenWidth = width;
+        fullscreenHeight = height;
+    }
+
+    window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, fullscreenWidth, fullscreenHeight,
+                              windowFlags);
+    if (window == NULL)
+    {
+        Log(TLOG_PANIC, NULL, "SDL Window creation error: %s", SDL_GetError());
+        goto exit;
+    }
+    Log(TLOG_DEBUG, NULL, "SDL Window created!");
+
+    renderer = SDL_CreateRenderer(window, -1, 0);
+    if (renderer == NULL)
+    {
+        Log(TLOG_PANIC, NULL, "SDL Renderer creation error: %s", SDL_GetError());
+        goto exit;
+    }
+    Log(TLOG_DEBUG, NULL, "SDL Renderer created!");
+
+    font = TTF_OpenFont("assets/pico8.ttf", 8);
+    if (font == NULL)
+    {
+        Log(TLOG_WARNING, NULL, "Cannot open the font for printing...: %s", SDL_GetError());
+        goto exit;
+    }
+
+    frameBuffer = (uint32_t *)calloc(windowWidth * windowHeight, sizeof(uint32_t));
+    if (!frameBuffer)
+    {
+        Log(TLOG_PANIC, NULL, "Memory allocation error.");
+        goto exit;
+    }
+
+    zBuffer = (double *)calloc(windowWidth * windowHeight, sizeof(double));
+    if (!frameBuffer)
+    {
+        Log(TLOG_PANIC, NULL, "Memory allocation error.");
+        goto exit;
+    }
+
+    frameBufferTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, windowWidth,
+                                           windowHeight);
+    if (frameBufferTexture == NULL)
+    {
+        Log(TLOG_PANIC, NULL, "SDL Texture creation error: %s", SDL_GetError());
+        goto exit;
+    }
+
+    if (fullScreen)
+    {
+        SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
+    }
+
+    ret = true;
+
+exit:
+    return ret;
+}
+
+void getWindowSize(int32_t *width, int32_t *height)
+{
+    *width = windowWidth;
+    *height = windowHeight;
+}
+
+void destroyWindow()
+{
+    if (font != NULL)
+    {
+        TTF_CloseFont(font);
+    }
+    if (frameBuffer != NULL)
+    {
+        free(frameBuffer);
+    }
+    if (zBuffer != NULL)
+    {
+        free(zBuffer);
+    }
+    SDL_DestroyRenderer(renderer);
+    SDL_DestroyWindow(window);
+    SDL_Quit();
+}
+
+void displayWindowClear()
+{
+    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+    SDL_RenderClear(renderer);
+}
+
+void displayWindowRender()
+{
+    SDL_RenderPresent(renderer);
+}
+
+void renderFrameBuffer()
+{
+    SDL_UpdateTexture(frameBufferTexture, NULL, frameBuffer, (uint32_t)(windowWidth * sizeof(uint32_t)));
+    SDL_RenderCopy(renderer, frameBufferTexture, NULL, NULL);
+}
+
+void drawText(int32_t x, int32_t y, colour_t colour, const char *format, ...)
+{
+    va_list va;
+    uint8_t r = ((colour >> 16) & 0xFF);
+    uint8_t g = ((colour >>  8) & 0xFF);
+    uint8_t b = ((colour      ) & 0xFF);
+    SDL_Color c = { r, g, b , 255};
+    char buffer[512];
+
+    va_start(va, format);
+    vsnprintf(buffer, 512, format, va);
+    va_end(va);
+
+    SDL_Surface *surface = TTF_RenderText_Blended(font, buffer, c);
+    SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
+
+    int labelWidth, labelHeight;
+
+    SDL_QueryTexture(texture, NULL, NULL, &labelWidth, &labelHeight);
+
+    SDL_Rect destRect =
+    {
+        x, y, labelWidth, labelHeight
+    };
+    SDL_RenderCopyEx(renderer, texture, NULL, &destRect,0, NULL, SDL_FLIP_NONE);
+
+    SDL_FreeSurface(surface);
+    SDL_DestroyTexture(texture);
+}
+
+void drawPixel(int32_t x, int32_t y, colour_t colour)
+{
+    if ((x >= 0) && (x < windowWidth) && (y >= 0) && (y < windowHeight))
+    {
+        frameBuffer[x + (y * windowWidth)] = colour;
+    }
+}
+
+void drawVLine(int32_t x, int32_t y0, int32_t y1, colour_t colour)
+{
+    int32_t i;
+    if (y0 > y1) {
+        intSwap(&y0, &y1); }
+
+    if ( ((x < 0) || (x > windowWidth)) ||
+         ((y0 < 0) && (y1 < 0)) ||
+         ((y0 > windowHeight) && (y1 > windowHeight)) )
+    {
+        return;
+    }
+
+    y0 = MAX(0, y0);
+    y1 = MIN(y1, (windowHeight - 1));
+
+    uint32_t *currentPos = &frameBuffer[x + (y0 * windowWidth)];
+
+    for(i = y0; i <= y1; i++, currentPos+=windowWidth)
+    {
+        *currentPos = colour;
+    }
+}
+
+void drawHLine(int32_t x0, int32_t y, int32_t x1, colour_t colour)
+{
+    int32_t i;
+    if (x0 > x1) {
+        intSwap(&x0, &x1); }
+
+    if ( ((y < 0) || (y > windowHeight)) ||
+         ((x0 < 0) && (x1 < 0)) ||
+         ((x0 > windowWidth) && (x1 > windowWidth)) )
+    {
+        return;
+    }
+
+    x0 = MAX(0, x0);
+    x1 = MIN(x1, (windowWidth - 1));
+
+    uint32_t *currentPos = &frameBuffer[x0 + (y * windowWidth)];
+
+    for(i = x0; i <= x1; i++, currentPos++)
+    {
+        *currentPos = colour;
+    }
+}
+
+void clearFrameBuffer(colour_t colour)
+{
+    int32_t x;
+    for (x = 0 ; x < windowWidth * windowHeight ; x++)
+    {
+        frameBuffer[x] = colour;
+    }
+}
+
+void clearZBuffer()
+{
+    int32_t x;
+    if (doZBuffer)
+    {
+        for (x = 0 ; x < windowWidth * windowHeight ; x++)
+        {
+                zBuffer[x] = 1.0;
+        }
+    }
+}
+
+void drawGrid(int spacing, colour_t colour)
+{
+    int32_t x, y;
+    for (y = 0 ; y < windowHeight ; y++)
+    {
+        for (x = 0 ; x < windowWidth ; x++)
+        {
+            if (((x % spacing) == 0) || ((y % spacing) == 0))
+            {
+                frameBuffer[x + (y * windowWidth)] = colour;
+            }
+        }
+    }
+}
+
+void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, colour_t colour)
+{
+    int32_t j;
+
+    for (j = 0 ; j < h ; j++)
+    {
+        drawHLine(x, y + j, x + w, colour);
+    }
+}
+
+/* FIXME: Some out of screen line may render weirdly. Will fix that later */
+void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, colour_t colour)
+{
+    int i;
+    int32_t deltaX = x1 - x0;
+    int32_t deltaY = y1 - y0;
+
+    int32_t sideLength = ( abs(deltaX) >= abs(deltaY) ) ? abs(deltaX) : abs(deltaY);
+
+    double incrementX = deltaX / (double)sideLength;
+    double incrementY = deltaY / (double)sideLength;
+
+    if (deltaX == 0)
+    {
+        drawVLine(x0, y0, y1, colour);
+    }
+    else if (deltaY == 0)
+    {
+        drawHLine(x0, y0, x1, colour);
+    }
+    else
+    {
+        double currentX = x0;
+        double currentY = y0;
+
+        for (i = 0 ; i < sideLength ; i++)
+        {
+            drawPixel(round(currentX), round(currentY), colour);
+            currentX += incrementX;
+            currentY += incrementY;
+        }
+    }
+}
+
+static vec3_t barycentricWeights(vec2_t a, vec2_t b, vec2_t c, vec2_t p)
+{
+    vec2_t ab = vec2SubVectors(b, a);
+    vec2_t bc = vec2SubVectors(c, b);
+    vec2_t ac = vec2SubVectors(c, a);
+    vec2_t ap = vec2SubVectors(p, a);
+    vec2_t bp = vec2SubVectors(p, b);
+    vec3_t ret;
+
+    double areaTriangleABC = (ab.x * ac.y) - (ab.y * ac.x);
+
+    double alpha = ((bc.x * bp.y) - (bp.x * bc.y)) / areaTriangleABC;
+    double beta = ((ap.x * ac.y) - (ac.x * ap.y)) / areaTriangleABC;
+    double gamma = 1 - alpha - beta;
+
+    ret.x = alpha;
+    ret.y = beta;
+    ret.z = gamma;
+
+    return ret;
+}
+
+void drawZPixel(int32_t x, int32_t y, vec4_t a, vec4_t b, vec4_t c, colour_t colour)
+{
+    vec2_t pointP = { x, y };
+    vec2_t a2 = vec2FromVec4(a);
+    vec2_t b2 = vec2FromVec4(b);
+    vec2_t c2 = vec2FromVec4(c);
+
+    if ((x < 0) || (y < 0) || (x > windowWidth) ||(y > windowHeight))
+    {
+        return;
+    }
+
+    vec3_t weights = barycentricWeights(a2, b2, c2, pointP);
+
+    double alpha = weights.x;
+    double beta = weights.y;
+    double gamma = weights.z;
+    double interpolatedReciprocalW;
+
+    interpolatedReciprocalW = (1 / a.w) * alpha + (1 / b.w) * beta + (1 / c.w) * gamma;
+
+    /* Inverse to get logical W invrementing going further to us */
+    interpolatedReciprocalW = 1 - interpolatedReciprocalW;
+    if (interpolatedReciprocalW < zBuffer[(windowWidth * y) + x])
+    {
+        drawPixel(x, y, colour);
+
+        /* Update Z Buffer */
+        zBuffer[(windowWidth * y) + x] = interpolatedReciprocalW;
+    }
+}
+
+void drawTexel(int32_t x, int32_t y, vec4_t a, vec4_t b, vec4_t c, tex2_t ta, tex2_t tb, tex2_t tc, texture_t *texture)
+{
+    vec2_t pointP = { x, y };
+    vec2_t a2 = vec2FromVec4(a);
+    vec2_t b2 = vec2FromVec4(b);
+    vec2_t c2 = vec2FromVec4(c);
+
+    if ((x < 0) || (y < 0) || (x > windowWidth) ||(y > windowHeight))
+    {
+        return;
+    }
+
+    vec3_t weights = barycentricWeights(a2, b2, c2, pointP);
+
+    double alpha = weights.x;
+    double beta = weights.y;
+    double gamma = weights.z;
+    double interpolatedU, interpolatedV, interpolatedReciprocalW;
+    int32_t texX, texY;
+
+    interpolatedReciprocalW = (1 / a.w) * alpha + (1 / b.w) * beta + (1 / c.w) * gamma;
+
+    if (doPerspectiveCorrection)
+    {
+        interpolatedU = (ta.u / a.w) * alpha + (tb.u / b.w) * beta + (tc.u / c.w) * gamma;
+        interpolatedV = ((1 - ta.v) / a.w) * alpha + ((1 - tb.v) / b.w) * beta + ((1 - tc.v) / c.w) * gamma;
+
+
+        interpolatedU /= interpolatedReciprocalW;
+        interpolatedV /= interpolatedReciprocalW;
+    }
+    else
+    {
+        interpolatedU = ta.u * alpha + tb.u * beta + tc.u * gamma;
+        interpolatedV = (1 - ta.v) * alpha + (1 - tb.v) * beta + (1 - tc.v) * gamma;
+    }
+
+    texX = abs((int32_t)(interpolatedU * texture->width));
+    texY = abs((int32_t)(interpolatedV * texture->height));
+
+    texX = texX % texture->width;
+    texY = texY % texture->height;
+
+    if (doZBuffer)
+    {
+        /* Inverse to get logical W invrementing going further to us */
+        interpolatedReciprocalW = 1 - interpolatedReciprocalW;
+        if (interpolatedReciprocalW < zBuffer[(windowWidth * y) + x])
+        {
+            drawPixel(x, y, texture->data[(texY * texture->width) + texX]);
+
+            /* Update Z Buffer */
+            zBuffer[(windowWidth * y) + x] = interpolatedReciprocalW;
+        }
+    }
+    else
+    {
+        drawPixel(x, y, texture->data[(texY * texture->width) + texX]);
+    }
+}

+ 61 - 0
source/include/display.h

@@ -0,0 +1,61 @@
+/*
+ * Voxel-a-tord
+ * display.h: 
+* Copyright (c) 2021-2022 986-Studio. All rights reserved.
+ *
+ * Created by Manoël Trapier on 01/03/2021.
+ */
+
+#ifndef THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H
+#define THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H
+
+#include <stdbool.h>
+#include <SDL.h>
+
+#include <vector.h>
+#include <texture.h>
+#include <colour.h>
+
+/***********************************************************************************************************************
+ * Data types
+ **********************************************************************************************************************/
+typedef struct window_t
+{
+    int32_t height, width;
+} window_t;
+
+/***********************************************************************************************************************
+ * Constants
+ **********************************************************************************************************************/
+#define FPS (60)
+#define FRAME_TARGET_TIME (1000 / FPS)
+
+/***********************************************************************************************************************
+ * Prototypes
+ **********************************************************************************************************************/
+/* --- Window functions --- */
+bool initialiseWindow(int32_t screenWidth, int32_t screenHeight, bool fullScreen);
+void destroyWindow();
+void renderFrameBuffer();
+void getWindowSize(int32_t *width, int32_t *height);
+void displayWindowClear();
+void displayWindowRender();
+
+/* --- Drawing functions --- */
+void clearZBuffer();
+void clearFrameBuffer(colour_t colour);
+
+void drawPixel(int32_t x, int32_t y, colour_t colour);
+
+void drawGrid(int spacing, colour_t colour);
+void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, colour_t colour);
+void drawVLine(int32_t x, int32_t y0, int32_t y1, colour_t colour);
+void drawHLine(int32_t x0, int32_t y, int32_t x1, colour_t colour);
+void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, colour_t colour);
+void drawText(int32_t x, int32_t y, colour_t colour, const char *format, ...);
+
+/* Other */
+void drawZPixel(int32_t x, int32_t y, vec4_t a, vec4_t b, vec4_t c, colour_t colour);
+void drawTexel(int32_t x, int32_t y, vec4_t a, vec4_t b, vec4_t c, tex2_t ta, tex2_t tb, tex2_t tc, texture_t *texture);
+
+#endif /* THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H */

+ 95 - 0
source/include/log.h

@@ -0,0 +1,95 @@
+/*
+ * C Fancy Logger
+ * log.h:
+ * Copyright (c) 2009-2022 986-Studio. All rights reserved.
+ *
+ * Created by Manoël Trapier on 20/01/2009.
+ */
+
+#ifndef _LOG_H
+#define	_LOG_H
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+enum
+{
+    TLOG_ALWAYS = -1,
+    TLOG_PANIC = 0,
+    TLOG_ERROR,
+    TLOG_WARNING,
+    TLOG_NORMAL,
+    TLOG_VERBOSE,
+    TLOG_DEBUG,
+};
+
+//#define LOG_ALWAYS_FFLUSH
+#define DYNA_LOG_LEVEL
+#define SET_DEBUG_LOG
+
+/* Set if DYNALOG is set the maximum compiled log level */
+#ifndef MAXIMUM_DEBUG_LEVEL
+
+#ifndef SET_DEBUG_LOG
+#define MAXIMUM_DEBUG_LEVEL TLOG_NORMAL
+#else
+#define MAXIMUM_DEBUG_LEVEL TLOG_DEBUG
+#endif
+
+#endif /* MAXIMUM_DEBUG_LEVEL */
+
+/* Set the default log level */
+#ifndef SET_DEBUG_LOG
+#define DEFAULT_DEBUG_LEVEL TLOG_PANIC
+#else
+#define DEFAULT_DEBUG_LEVEL TLOG_NORMAL
+#endif
+
+/******************************************************************************/
+/*                        DO NOT MESS AFTER THIS LINE                         */
+/******************************************************************************/
+
+#ifdef DYNA_LOG_LEVEL
+# ifdef MAX_DEBUG_LEVEL
+#  undef MAX_DEBUG_LEVEL
+# endif
+# ifdef __LOG_C_INTERNAL_
+int MAX_DEBUG_LEVEL = DEFAULT_DEBUG_LEVEL;
+#else
+extern int MAX_DEBUG_LEVEL;
+#endif
+#else
+# ifndef MAX_DEBUG_LEVEL
+#  define MAX_DEBUG_LEVEL DEFAULT_DEBUG_LEVEL
+# endif
+#endif
+
+#define Log(_level, _user, _fmt, ...)\
+ if (_level <= MAXIMUM_DEBUG_LEVEL)\
+  if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC))\
+   do { log_real(_level, _user, _fmt, ##__VA_ARGS__); } while(0)
+
+void log_real(int level, const char *user, const char *fmt, ...);
+
+#define LOG(_level, _str, ...) if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC)) do { fputs(_str, stderr); } while(0)
+#define LOGCODE(_level, _user, _code)\
+   if (_level <= MAXIMUM_DEBUG_LEVEL) do{\
+    Log(_level, _user, "");\
+    if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC))\
+       do { _code; fprintf(stderr, "\n"); } while(0); } while(0)
+
+#define INFOL(_level, _fmt) LOGCODE(_level, "INFOL", { printf _fmt; })
+
+#define FUNC_IN() Log(TLOG_VERBOSE, NULL, ">>%s", __func__)
+#define FUNC_OUT() Log(TLOG_VERBOSE, NULL, "<<%s", __func__)
+#define FUNC_OUTR(out) Log(TLOG_VERBOSE, NULL, "<<%s (%d)", __func__, out)
+
+void log_displayPanic(int signal);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _LOG_H */
+

+ 42 - 0
source/include/termcolour.h

@@ -0,0 +1,42 @@
+/*
+ * C Fancy Logger
+ * colour.h:
+ * Copyright (c) 2009-2022 986-Studio. All rights reserved.
+ *
+ * Created by Manoël Trapier on 20/01/2009.
+ */
+
+#ifndef LOG_COLOUR_H
+#define	LOG_COLOUR_H
+
+#define ALLOW_COLORS
+
+#ifdef ALLOW_COLORS
+#define __C(c) "\x1B[" c "m"
+#else
+#define __C(c) ""
+#endif
+
+#define ANSI_COLOR __C
+#define FBLACK ANSI_COLOR("30")
+#define FRED ANSI_COLOR("31")
+#define FGREEN ANSI_COLOR("32")
+#define FYELLOW ANSI_COLOR("33")
+#define FBLUE ANSI_COLOR("34")
+#define FMAGENTA ANSI_COLOR("35")
+#define FCYAN ANSI_COLOR("36")
+#define FWHITE ANSI_COLOR("37")
+
+#define BBLACK ANSI_COLOR("40")
+#define BRED ANSI_COLOR("41")
+#define BGREEN ANSI_COLOR("42")
+#define BYELLOW ANSI_COLOR("43")
+#define BBLUE ANSI_COLOR("44")
+#define BMAGENTA ANSI_COLOR("45")
+#define BCYAN ANSI_COLOR("46")
+#define BWHITE ANSI_COLOR("47")
+
+#define CNORMAL ANSI_COLOR("0")
+
+#endif	/* LOG_COLOUR_H */
+

+ 147 - 0
source/log.c

@@ -0,0 +1,147 @@
+/*
+ * C Fancy Logger
+ * log.c:
+ * Copyright (c) 2009-2022 986-Studio. All rights reserved.
+ *
+ * Created by Manoël Trapier on 20/01/2009.
+ */
+
+#define __LOG_C_INTERNAL_
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <termcolour.h>
+#include <string.h>
+#include <stdarg.h>
+#include <log.h>
+#include <sys/time.h>
+#include <time.h>
+#include <pthread.h>
+#include <syslog.h>
+#include <sys/syscall.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <execinfo.h>
+
+void log_displayPanic(int signal)
+{
+    size_t size = 0;
+
+    //size = backtrace(array, 30);
+    /* Now flood user with unusefull data. */
+    fprintf(stderr, FYELLOW "\n\n ----- " FYELLOW " YICK! ERROR YICK! [bt:%zu]" FYELLOW "----- \n", size);
+
+    // get void*'s for all entries on the stack
+
+    // print out all the frames to stderr
+    fprintf(stderr, " ----- Error:  signal: %d -----\n" FRED, signal);
+    //backtrace_symbols_fd(array, size, 2);
+    fprintf(stderr, FYELLOW "\n\n ----- " FYELLOW " YICK! ERROR YICK! " FYELLOW "----- " CNORMAL "\n");
+}
+
+void time_stamp_line(void)
+{
+    /* Time "0" will be thefirst log line */
+    static char firstRun = 1;
+    static struct timeval firstTime;
+    struct timeval curTime;
+
+    int cMin, cSec;
+    long long cMSec;
+
+    /* Get datetime */
+    gettimeofday(&curTime, NULL);
+
+    if (firstRun == 1)
+    {
+        firstRun = 0;
+        firstTime.tv_sec = curTime.tv_sec;
+        firstTime.tv_usec = curTime.tv_usec;
+    }
+
+    cMSec = ((curTime.tv_sec - firstTime.tv_sec) * 1000) + (curTime.tv_usec - firstTime.tv_usec) / 1000;
+    cSec = (cMSec / 1000);
+    cMSec %= 1000;
+
+    cMin = cSec / 60;
+
+    cSec %= 60;
+
+    /* Put cursor at start of line */
+    fprintf(stderr, "%c[s", 0x1B);
+    fprintf(stderr, "%c[7000D", 0x1B);
+    fprintf(stderr, "%c[1C", 0x1B);
+    fprintf(stderr, FWHITE"[" FYELLOW "%03d" FRED "." FBLUE "%02d" FRED "." FGREEN "%03lld" FWHITE "]" CNORMAL, cMin,
+            cSec, cMSec);
+    fprintf(stderr, "%c[u", 0x1B);
+}
+
+void log_real(int level, const char *user, const char *fmt, ...)
+{
+    int i;
+    va_list va;
+
+    /* The LOG_PANIC must always be displayed */
+    if ((level <= MAX_DEBUG_LEVEL) || (level <= TLOG_PANIC))
+    {
+        fprintf(stderr, CNORMAL);
+        time_stamp_line();
+        fprintf(stderr, CNORMAL " | ");
+
+        switch (level)
+        {
+        case TLOG_PANIC:   fprintf(stderr, BRED FWHITE); break;
+        case TLOG_ERROR:   fprintf(stderr, FRED); break;
+        case TLOG_WARNING: fprintf(stderr, FYELLOW); break;
+        default:
+        case TLOG_NORMAL:  fprintf(stderr, FGREEN); break;
+        case TLOG_VERBOSE: fprintf(stderr, FCYAN); break;
+        case TLOG_DEBUG:   fprintf(stderr, BBLUE FWHITE); break;
+        }
+
+        if (user != NULL)
+        {
+            i = strlen(user);
+            if (i < 12)
+            {
+                i = 12 - i;
+                for (; i >= 0 ; i--)
+                {
+                    fprintf(stderr, " ");
+                }
+            }
+            fprintf(stderr, "%s", user);
+        }
+        else
+        {
+            switch (level)
+            {
+            case TLOG_PANIC:   fprintf(stderr, "        PANIC"); break;
+            case TLOG_ERROR:   fprintf(stderr, "        Error"); break;
+            case TLOG_WARNING: fprintf(stderr, "      Warning"); break;
+            default:
+            case TLOG_NORMAL:  fprintf(stderr, "         Info"); break;
+            case TLOG_VERBOSE: fprintf(stderr, "      Verbose"); break;
+            case TLOG_DEBUG:   fprintf(stderr, "        Debug"); break;
+            }
+        }
+
+        fprintf(stderr, CNORMAL " | ");
+
+        va_start(va, fmt);
+        vfprintf(stderr, fmt, va);
+        va_end(va);
+
+        if (fmt[0] != 0)
+        {
+            fprintf(stderr, "\n");
+        }
+
+#ifdef LOG_ALWAYS_FFLUSH
+        /* Systematicaly flush */
+        fflush(stderr);
+#endif
+    }
+}
+

+ 14 - 0
source/main.c

@@ -0,0 +1,14 @@
+/*
+ * Voxel-a-tord
+ * main.c:
+ * Copyright (c) 2022 986-Studio. All rights reserved.
+ *
+ * Created by Manoël Trapier on 28/09/2022.
+ */
+
+
+int main(int argc, char *arvg[])
+{
+
+    return 0;
+}

Some files were not shown because too many files changed in this diff