diff --git a/.gitignore b/.gitignore index 2f88b18..a6d16e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /cmake-build-debug /.idea + +/assets/test_files \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c16646..219d6ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX) include_directories( ${ReWindow_SOURCE_DIR}/include ${Event_SOURCE_DIR}/include + ${glad_SOURCE_DIR}/include ) target_include_directories(JGL PUBLIC @@ -89,7 +90,6 @@ target_include_directories(JGL PUBLIC ${ReImage_SOURCE_DIR}/include ${mcolor_SOURCE_DIR}/include ${J3ML_SOURCE_DIR}/include - ${glad_SOURCE_DIR}/include ${jlog_SOURCE_DIR}/include ) @@ -97,15 +97,15 @@ add_executable(JGL_Demo main.cpp) #set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib") if (UNIX AND NOT APPLE) - target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS}) - target_link_libraries(JGL PRIVATE ${FREETYPE_LIBRARIES}) - target_link_libraries(JGL PUBLIC ${OPENGL_LIBRARIES} mcolor J3ML glad jlog ReImage) + target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS} ) + target_link_libraries(JGL PRIVATE ${FREETYPE_LIBRARIES} glad) + target_link_libraries(JGL PUBLIC ${OPENGL_LIBRARIES} mcolor J3ML jlog ReImage) endif() if (WIN32) target_include_directories(JGL PRIVATE ${freetype_SOURCE_DIR}/include) - target_link_libraries(JGL PRIVATE freetype) + target_link_libraries(JGL PRIVATE freetype glad) target_link_libraries(JGL PUBLIC ${OPENGL_LIBRARIES} mcolor J3ML glad jlog ReImage) endif() -target_link_libraries(JGL_Demo PUBLIC JGL ReWindowLibrary Event) +target_link_libraries(JGL_Demo PUBLIC JGL ReWindowLibrary Event glad) diff --git a/Doxyfile b/Doxyfile index 6154317..ae17eb3 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1,4 +1,4 @@ -# Doxyfile 1.9.6 +# Doxyfile 1.9.4 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. @@ -19,8 +19,7 @@ # configuration file: # doxygen -x [configFile] # Use doxygen to compare the used configuration file with the template -# configuration file without replacing the environment variables or CMake type -# replacement variables: +# configuration file without replacing the environment variables: # doxygen -x_noenv [configFile] #--------------------------------------------------------------------------- @@ -42,7 +41,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = JGL +PROJECT_NAME = "Josh's Graphics Library" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -54,21 +53,21 @@ PROJECT_NUMBER = # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = "Linear Algebra, Geometry, and Algorithms in C++" +PROJECT_BRIEF = # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # the logo to the output directory. -PROJECT_LOGO = logo_light_small.png +PROJECT_LOGO = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = . +OUTPUT_DIRECTORY = "../../JGL DOXY" # If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 # sub-directories (in 2 levels) under the output directory of each output format @@ -79,14 +78,14 @@ OUTPUT_DIRECTORY = . # control the number of sub-directories. # The default value is: NO. -CREATE_SUBDIRS = NO +CREATE_SUBDIRS = YES # Controls the number of sub-directories that will be created when # CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every # level increment doubles the number of directories, resulting in 4096 # directories at level 8 which is the default and also the maximum value. The # sub-directories are organized in 2 levels, the first level always has a fixed -# number of 16 directories. +# numer of 16 directories. # Minimum value: 0, maximum value: 8, default value: 8. # This tag requires that the tag CREATE_SUBDIRS is set to YES. @@ -568,8 +567,7 @@ HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. If set # to NO, these classes will be included in the various overviews. This option -# will also hide undocumented C++ concepts if enabled. This option has no effect -# if EXTRACT_ALL is enabled. +# has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_CLASSES = NO @@ -607,10 +605,9 @@ INTERNAL_DOCS = NO # Windows (including Cygwin) and MacOS, users should typically set this option # to NO, whereas on Linux or other Unix flavors it should typically be set to # YES. -# Possible values are: SYSTEM, NO and YES. -# The default value is: SYSTEM. +# The default value is: system dependent. -CASE_SENSE_NAMES = SYSTEM +CASE_SENSE_NAMES = NO # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with # their full class and namespace scopes in the documentation. If set to YES, the @@ -860,14 +857,6 @@ WARN_IF_INCOMPLETE_DOC = YES WARN_NO_PARAMDOC = NO -# If WARN_IF_UNDOC_ENUM_VAL option is set to YES, doxygen will warn about -# undocumented enumeration values. If set to NO, doxygen will accept -# undocumented enumeration values. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: NO. - -WARN_IF_UNDOC_ENUM_VAL = NO - # If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when # a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS # then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but @@ -926,21 +915,10 @@ INPUT = include \ # libiconv (or the iconv built into libc) for the transcoding. See the libiconv # documentation (see: # https://www.gnu.org/software/libiconv/) for the list of possible encodings. -# See also: INPUT_FILE_ENCODING # The default value is: UTF-8. INPUT_ENCODING = UTF-8 -# This tag can be used to specify the character encoding of the source files -# that doxygen parses The INPUT_FILE_ENCODING tag can be used to specify -# character encoding on a per file pattern basis. Doxygen will compare the file -# name with each pattern and apply the encoding instead of the default -# INPUT_ENCODING) if there is a match. The character encodings are a list of the -# form: pattern=encoding (like *.php=ISO-8859-1). See cfg_input_encoding -# "INPUT_ENCODING" for further information on supported encodings. - -INPUT_FILE_ENCODING = - # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and # *.h) to filter out the source-files in the directories. @@ -1089,11 +1067,6 @@ IMAGE_PATH = # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. # -# Note that doxygen will use the data processed and written to standard output -# for further processing, therefore nothing else, like debug statements or used -# commands (so in case of a Windows batch file always use @echo OFF), should be -# written to standard output. -# # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # properly processed by doxygen. @@ -1135,15 +1108,6 @@ FILTER_SOURCE_PATTERNS = USE_MDFILE_AS_MAINPAGE = -# The Fortran standard specifies that for fixed formatted Fortran code all -# characters from position 72 are to be considered as comment. A common -# extension is to allow longer lines before the automatic comment starts. The -# setting FORTRAN_COMMENT_AFTER will also make it possible that longer lines can -# be processed before the automatic comment starts. -# Minimum value: 7, maximum value: 10000, default value: 72. - -FORTRAN_COMMENT_AFTER = 72 - #--------------------------------------------------------------------------- # Configuration options related to source browsing #--------------------------------------------------------------------------- @@ -1281,11 +1245,10 @@ CLANG_DATABASE_PATH = ALPHABETICAL_INDEX = YES -# The IGNORE_PREFIX tag can be used to specify a prefix (or a list of prefixes) -# that should be ignored while generating the index headers. The IGNORE_PREFIX -# tag works for classes, function and member names. The entity will be placed in -# the alphabetical list under the first letter of the entity name that remains -# after removing the prefix. +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. IGNORE_PREFIX = @@ -1364,15 +1327,10 @@ HTML_STYLESHEET = # Doxygen will copy the style sheet files to the output directory. # Note: The order of the extra style sheet files is of importance (e.g. the last # style sheet in the list overrules the setting of the previous ones in the -# list). -# Note: Since the styling of scrollbars can currently not be overruled in -# Webkit/Chromium, the styling will be left out of the default doxygen.css if -# one or more extra stylesheets have been specified. So if scrollbar -# customization is desired it has to be added explicitly. For an example see the -# documentation. +# list). For an example see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_STYLESHEET = +HTML_EXTRA_STYLESHEET = ../../doxygen_theme_flat_design/src/doxygen-style.css # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note @@ -1382,20 +1340,11 @@ HTML_EXTRA_STYLESHEET = # files will be copied as-is; there are no commands or markers available. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE tag can be used to specify if the generated HTML output -# should be rendered with a dark or light theme. -# Possible values are: LIGHT always generate light mode output, DARK always -# generate dark mode output, AUTO_LIGHT automatically set the mode according to -# the user preference, use light mode if no preference is set (the default), -# AUTO_DARK automatically set the mode according to the user preference, use -# dark mode if no preference is set and TOGGLE allow to user to switch between -# light and dark mode via a button. -# The default value is: AUTO_LIGHT. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE = AUTO_DARK +HTML_EXTRA_FILES = ../../doxygen_theme_flat_design/src/img/opened-folder.png \ + ../../doxygen_theme_flat_design/src/img/on_sync.png \ + ../../doxygen_theme_flat_design/src/img/off_sync.png \ + ../../doxygen_theme_flat_design/src/img/document.png \ + ../../doxygen_theme_flat_design/src/img/closed-folder.png # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen # will adjust the colors in the style sheet and background images according to @@ -1406,7 +1355,7 @@ HTML_COLORSTYLE = AUTO_DARK # Minimum value: 0, maximum value: 359, default value: 220. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_HUE = 337 # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors # in the HTML output. For a value of 0 the output will use gray-scales only. A @@ -1414,7 +1363,7 @@ HTML_COLORSTYLE_HUE = 220 # Minimum value: 0, maximum value: 255, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_SAT = 15 # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the # luminance component of the colors in the HTML output. Values below 100 @@ -1425,7 +1374,7 @@ HTML_COLORSTYLE_SAT = 100 # Minimum value: 40, maximum value: 240, default value: 80. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_COLORSTYLE_GAMMA = 80 +HTML_COLORSTYLE_GAMMA = 169 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting this @@ -1695,7 +1644,7 @@ DISABLE_INDEX = NO # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -GENERATE_TREEVIEW = YES +GENERATE_TREEVIEW = NO # When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the # FULL_SIDEBAR option determines if the side bar is limited to only the treeview @@ -1760,6 +1709,17 @@ HTML_FORMULA_FORMAT = png FORMULA_FONTSIZE = 10 +# Use the FORMULA_TRANSPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + # The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands # to create new LaTeX commands to be used in formulas as building blocks. See # the section "Including formulas" for details. @@ -1859,7 +1819,7 @@ MATHJAX_CODEFILE = # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. -SEARCHENGINE = YES +SEARCHENGINE = NO # When the SERVER_BASED_SEARCH tag is enabled the search engine will be # implemented using a web server instead of a web client using JavaScript. There @@ -2465,7 +2425,7 @@ HIDE_UNDOC_RELATIONS = YES # http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent # Bell Labs. The other options in this section have no effect if this option is # set to NO -# The default value is: NO. +# The default value is: YES. HAVE_DOT = YES @@ -2479,38 +2439,26 @@ HAVE_DOT = YES DOT_NUM_THREADS = 0 -# DOT_COMMON_ATTR is common attributes for nodes, edges and labels of -# subgraphs. When you want a differently looking font in the dot files that -# doxygen generates you can specify fontname, fontcolor and fontsize attributes. -# For details please see Node, -# Edge and Graph Attributes specification You need to make sure dot is able -# to find the font, which can be done by putting it in a standard location or by -# setting the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the -# directory containing the font. Default graphviz fontsize is 14. -# The default value is: fontname=Helvetica,fontsize=10. +# When you want a differently looking font in the dot files that doxygen +# generates you can specify the font name using DOT_FONTNAME. You need to make +# sure dot is able to find the font, which can be done by putting it in a +# standard location or by setting the DOTFONTPATH environment variable or by +# setting DOT_FONTPATH to the directory containing the font. +# The default value is: Helvetica. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_COMMON_ATTR = "fontname=Helvetica,fontsize=10" +DOT_FONTNAME = Helvetica -# DOT_EDGE_ATTR is concatenated with DOT_COMMON_ATTR. For elegant style you can -# add 'arrowhead=open, arrowtail=open, arrowsize=0.5'. Complete documentation about -# arrows shapes. -# The default value is: labelfontname=Helvetica,labelfontsize=10. +# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of +# dot graphs. +# Minimum value: 4, maximum value: 24, default value: 10. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_EDGE_ATTR = "labelfontname=Helvetica,labelfontsize=10" +DOT_FONTSIZE = 10 -# DOT_NODE_ATTR is concatenated with DOT_COMMON_ATTR. For view without boxes -# around nodes set 'shape=plain' or 'shape=plaintext' Shapes specification -# The default value is: shape=box,height=0.2,width=0.4. -# This tag requires that the tag HAVE_DOT is set to YES. - -DOT_NODE_ATTR = "shape=box,height=0.2,width=0.4" - -# You can set the path where dot can find font specified with fontname in -# DOT_COMMON_ATTR and others dot attributes. +# By default doxygen will tell dot to use the default font as specified with +# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set +# the path where dot can find it using this tag. # This tag requires that the tag HAVE_DOT is set to YES. DOT_FONTPATH = @@ -2666,8 +2614,9 @@ DIR_GRAPH_MAX_DEPTH = 1 # Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order # to make the SVG files visible in IE 9+ (other browsers do not have this # requirement). -# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo, -# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and +# Possible values are: png, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd, +# gif, gif:cairo, gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd, +# png:cairo, png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and # png:gdiplus:gdiplus. # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. @@ -2753,6 +2702,18 @@ DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 0 +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not seem +# to support this out of the box. +# +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). +# The default value is: NO. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_TRANSPARENT = NO + # Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) support diff --git a/include/JGL/JGL.h b/include/JGL/JGL.h index 7958e0c..f1abd0f 100644 --- a/include/JGL/JGL.h +++ b/include/JGL/JGL.h @@ -26,6 +26,7 @@ #include #include #include +#include /// OpenGL Wrapper for rendering 2D & 3D graphics in both a 2D and 3D context. namespace JGL { @@ -33,10 +34,14 @@ namespace JGL { using namespace J3ML::Geometry; + [[nodiscard]] bool Init(const Vector2& window_size, float fovY, float far_plane); + /// @param window_size void Update(const Vector2& window_size); + inline void PurgeFontCache() { JGL::fontCache.purgeCache(); } std::array OpenGLPerspectiveProjectionRH(float fovY, float aspect, float z_near, float z_far); + /// Returns true if the graphics driver meets the requirements (GL Version & Extensions). bool MeetsRequirements(); /// Drawing functions for primitive 2D Shapes. @@ -308,9 +313,6 @@ namespace JGL { /// Drawing functions for primitive 3D Shapes. namespace J3D { - /// Initializes internals for 3D rendering. Probably will be rethought later. - void Init(const Vector2 &window_size, float fov, float far_plane); - /// Helper function to conveniently change the Field-Of-View. void ChangeFOV(float fov); diff --git a/include/JGL/types/Font.h b/include/JGL/types/Font.h index 11286b1..7298848 100644 --- a/include/JGL/types/Font.h +++ b/include/JGL/types/Font.h @@ -14,7 +14,7 @@ extern "C" typedef struct FT_LibraryRec_* FT_Library; namespace JGL { - /// Initializes FreeType engine. Remember to call this during program initialization. + //bool Init(); bool InitTextEngine(); /// A Font class implementation. diff --git a/include/JGL/types/Skeleton.h b/include/JGL/types/Skeleton.h index 8f4f45c..5287674 100644 --- a/include/JGL/types/Skeleton.h +++ b/include/JGL/types/Skeleton.h @@ -7,13 +7,14 @@ namespace JGL { class Bone; - class SkeletalVertex; + class SkeletalVertexAttribute; class Skeleton; class KeyFrame; class Animation; + class AnimationState; } -class JGL::SkeletalVertex : public Vector3 { +class JGL::SkeletalVertexAttribute { private: std::array bone_ids = { 0, 0, 0, 0 }; std::array bone_weights = { 0, 0, 0, 0 }; @@ -21,9 +22,9 @@ public: [[nodiscard]] std::array GetAffectingBoneIDs() const; [[nodiscard]] std::array GetAffectingBoneWeights() const; public: - SkeletalVertex() = default; + SkeletalVertexAttribute() = default; /// These cannpt be longer than 4. - SkeletalVertex(const Vector3& rhs, const std::vector& bone_ids, const std::vector& bone_weights); + SkeletalVertexAttribute(const std::vector& ids, const std::vector& weights); }; class JGL::Bone { @@ -90,17 +91,34 @@ public: class JGL::Animation { private: - float length; + int id = -1; + // Not all animations have names. + std::string name; + float length = 0; std::vector key_frames; + std::vector vertex_attributes{}; public: [[nodiscard]] float GetDuratrion() const; [[nodiscard]] std::vector GetKeyFrames() const; + [[nodiscard]] int GetID() const; + [[nodiscard]] std::string GetName() const; + [[nodiscard]] std::vector GetSkeletalVertexAttributes() const; public: void AppendKeyFrame(const KeyFrame& new_key); void SetDuration(float duration); + void SetID(int identifier); + void SetName(const std::string& name_id); public: - explicit Animation(float duration, const std::vector& key_frames = {}); ~Animation() = default; + Animation(int id, float duration, const std::vector& key_frames, const std::vector& skeletal_vertex_attributes, + const std::string& name = ""); }; +class JGL::AnimationState { +private: + int animation_id = -1; + float animation_time = 0; +public: + +}; diff --git a/include/JGL/types/VRamList.h b/include/JGL/types/VRamList.h index 4bef475..505d231 100644 --- a/include/JGL/types/VRamList.h +++ b/include/JGL/types/VRamList.h @@ -38,7 +38,7 @@ public: /// Returns the number of elements in the list. [[nodiscard]] long GetLength() const; /// Returns the size of the data in bytes. - [[nodiscard]] size_t GetSize() const; + [[nodiscard]] size_t GetDataSize() const; /** Get VBO data back from the GPU. This is *bad* because the CPU is going to wait * for the transfer to finish. Has limited use other than testing. */ [[nodiscard]] std::vector GetDataF() const; diff --git a/include/JGL/types/VertexArray.h b/include/JGL/types/VertexArray.h index b8a27bc..a0bd808 100644 --- a/include/JGL/types/VertexArray.h +++ b/include/JGL/types/VertexArray.h @@ -2,8 +2,8 @@ #include #include +#include #include -#include #include #include #include @@ -15,7 +15,7 @@ namespace JGL { typedef Vector3 Normal; /// 2D positions that describe how a texture is to be wrapped around a 3D object. typedef Vector2 TextureCoordinate; - /// A 3D model. + /// Container for storing 3D models in v-ram, system memory, or both. class VertexArray; } @@ -26,20 +26,21 @@ private: protected: virtual void CreateMESphere(); virtual void CreateMEOBB(); +protected: + std::vector animations{}; protected: VRamList vertices; VRamList indices; VRamList normals; VRamList texture_coordinates; protected: - /** Intended for low quality version in system memory for calculations to be done on the CPU. - * In some scenarios like complex collision, You'd have to loop over every vertex. - * It makes more sense for performance and memory reasons to store a *much* lower quality version in system memory. + /** For models which are not animated, This is intended for a low quality version in + * system memory for calculations to be done on the CPU. For models that are, the default pose of the model is here. */ - std::vector local_vertices; - std::vector local_indices; - std::vector local_texture_coordinates; - std::vector local_normals; + std::vector local_vertices{}; + std::vector local_indices{}; + std::vector local_texture_coordinates{}; + std::vector local_normals{}; public: /** Don't use these for anything other than drawing because the GPU is gonna spin during read-back */ [[nodiscard]] VRamList GetVertices() const; @@ -52,6 +53,9 @@ public: [[nodiscard]] std::vector GetLocalIndices() const; [[nodiscard]] std::vector GetLocalTextureCoordinates() const; [[nodiscard]] std::vector GetLocalNormals() const; +public: + /// Returns true if the VertexArray does not have any animations. + bool Static(); public: /// Provides the minimally enclosing bounding sphere of the vertex array given information from the instance. /// @param scale The scale of the instance. @@ -80,7 +84,15 @@ public: [[nodiscard]] AABB GetMEAABB(const Matrix4x4& instance_matrix, bool translate = false) const; public: /// Vertices are required, Everything else is optional. - VertexArray(const Vector3* vertex_positions, const long& vp_length, const unsigned int* vertex_indices = nullptr, const long& vi_length = 0, const Normal* vertex_normals = nullptr, const long& vn_length = 0, - const TextureCoordinate* texture_coordinates = nullptr, const long& vt_length = 0); + VertexArray(const Vertex* vertex_positions, const long& vp_length, const unsigned int* vertex_indices = nullptr, const long& vi_length = 0, + const Normal* vertex_normals = nullptr, const long& vn_length = 0, const TextureCoordinate* texture_coordinates = nullptr, const long& vt_length = 0); + + /// Vertices are required, Everything else is optional. + explicit VertexArray(const std::vector& vertex_positions, const std::vector& vertex_indices = {}, + const std::vector& vertex_normals = {}, const std::vector& texture_coordinates = {}); }; +using namespace JGL; +static VertexArray Animate(int animation_id, float animation_time); +static VertexArray Animate(const AnimationState& anim_state); + diff --git a/main.cpp b/main.cpp index 9807897..c2fc26a 100644 --- a/main.cpp +++ b/main.cpp @@ -106,13 +106,10 @@ class JGLDemoWindow : public ReWindow::RWindow public: void initGL() { camera = new Camera; - gladLoadGL(); - if (!JGL::MeetsRequirements()) - Logger::Warning("The graphics driver does not meet the minimum requirements to run this program."); - JGL::InitTextEngine(); - JGL::Update(getSize()); - J3D::Init(getSize(), 90, 100); + if (!JGL::Init(getSize(), 75, 100)) + Logger::Fatal("Initialization failed."); + FreeSans = JGL::Font("assets/fonts/FreeSans.ttf"); Jupiteroid = JGL::Font("assets/fonts/Jupiteroid.ttf"); @@ -139,8 +136,8 @@ public: void display() { float dt = 1.f / fps; - JGL::Update(getSize()); + if (fov_increasing) fov += 0.025; else diff --git a/src/JGL.cpp b/src/JGL.cpp index 1a2e9e8..d04e38e 100644 --- a/src/JGL.cpp +++ b/src/JGL.cpp @@ -9,7 +9,8 @@ #include #include #include -#include "JGL/types/VRamList.h" +#include +#include JGL::RenderTarget* render_target = nullptr; GLfloat oldColor[4] = {0, 0, 0, 1}; @@ -30,9 +31,26 @@ bool wasBlendEnabled = false; bool wasColorArrayEnabled = false; GLint activeTextureUnit = 0; +float j3d_far_plane = 0; +float j3d_fov = 0; +Vector2 wS; + namespace JGL { using namespace J3ML; - Vector2 wS; + + bool Init(const Vector2& window_size, float fovY, float far_plane) { + gladLoadGL(); + if (!MeetsRequirements()) { + Logger::Error("The graphics driver does not meet the minimum requirements to run this program."); + return false; + } + + InitTextEngine(); + wS = window_size; + j3d_fov = fovY; + j3d_far_plane = far_plane; + return true; + } void Update(const Vector2& window_size) { wS = window_size; @@ -959,17 +977,6 @@ namespace JGL { return result; } - bool j3d_initialized = false; - float j3d_far_plane = 0; - float j3d_fov = 0; - - void J3D::Init(const J3ML::LinearAlgebra::Vector2& window_size, float fov, float far_plane) { - wS = window_size; - j3d_far_plane = far_plane; - j3d_fov = fov; - j3d_initialized = true; - } - void J3D::ChangeFOV(float fov) { j3d_fov = fov; } @@ -979,8 +986,6 @@ namespace JGL { } void J3D::Begin() { - if (!j3d_initialized) - throw std::runtime_error("You have to run J3D::Init before rendering 3D elements."); auto aspect = (float) wS.x / (float) wS.y; glMatrixMode(GL_PROJECTION); diff --git a/src/types/Font.cpp b/src/types/Font.cpp index 83dcede..d60a42e 100644 --- a/src/types/Font.cpp +++ b/src/types/Font.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #if __linux__ #include @@ -32,7 +32,7 @@ namespace JGL::Detail // Keep note of this, might cause problems later? if (ft != nullptr) - throw std::runtime_error("Error::FREETYPE: FT_Library was initialized but is already initialized."); + Logger::Fatal("Error::FREETYPE: FT_Library was initialized but is already initialized."); if (FT_Init_FreeType(&ft)) return true; @@ -52,23 +52,20 @@ namespace JGL::Detail } } -namespace JGL -{ +namespace JGL { - bool InitTextEngine() - { + bool InitTextEngine() { return Detail::InitTextEngine(); } - Font::Font(const std::filesystem::path& path) - { + Font::Font(const std::filesystem::path& path) { if (Detail::ft == nullptr) - throw new std::runtime_error("Error::FREETYPE: FT_Library was not initialized before attempting to load a font!"); + throw std::runtime_error("Error::FREETYPE: FT_Library was not initialized before attempting to load a font!"); Font font; if (FT_New_Face(Detail::ft, path.string().c_str(), 0, &face)) { std::cout << "Error::FREETYPE: Failed to load font!" << std::endl; - throw new std::runtime_error("Error::FREETYPE: Failed to load font!"); + throw std::runtime_error("Error::FREETYPE: Failed to load font!"); //return -1; } unsigned int newIndex = 0; diff --git a/src/types/Skeleton.cpp b/src/types/Skeleton.cpp index f15b436..f837d11 100644 --- a/src/types/Skeleton.cpp +++ b/src/types/Skeleton.cpp @@ -4,16 +4,15 @@ using namespace JGL; -std::array JGL::SkeletalVertex::GetAffectingBoneIDs() const { +std::array JGL::SkeletalVertexAttribute::GetAffectingBoneIDs() const { return bone_ids; } -std::array JGL::SkeletalVertex::GetAffectingBoneWeights() const { +std::array JGL::SkeletalVertexAttribute::GetAffectingBoneWeights() const { return bone_weights; } -JGL::SkeletalVertex::SkeletalVertex(const Vector3& rhs, const std::vector& bone_ids, const std::vector& bone_weights) { - x = rhs.x; y = rhs.y; z = rhs.z; +JGL::SkeletalVertexAttribute::SkeletalVertexAttribute(const std::vector& ids, const std::vector& weights) { if (bone_ids.size() > 4 || bone_weights.size() > 4) Logger::Fatal("Initialization of a skeletal vertex that is effected by more than 4 bones."); @@ -52,8 +51,8 @@ std::vector JGL::Bone::GetChildren() const { return children; } -void Bone::SetParent(int parent_id) { - this->parent_id = parent_id; +void Bone::SetParent(int parent_identifier) { + parent_id = parent_identifier; } void Bone::AppendChild(int new_child) { @@ -141,9 +140,13 @@ KeyFrame::KeyFrame(const Skeleton& pose, float time_stamp) { this->time_stamp = time_stamp; } -Animation::Animation(float duration, const std::vector& key_frames) { +Animation::Animation(int id, float duration, const std::vector& key_frames, const std::vector& skeletal_vertex_attributes, + const std::string& name) { length = duration; this->key_frames = key_frames; + this->id = id; + this->name = name; + this->vertex_attributes = skeletal_vertex_attributes; } float Animation::GetDuratrion() const { @@ -161,3 +164,23 @@ void Animation::AppendKeyFrame(const KeyFrame& new_key) { void Animation::SetDuration(float duration) { length = duration; } + +int Animation::GetID() const { + return id; +} + +std::string Animation::GetName() const { + return name; +} + +void Animation::SetID(int identifier) { + id = identifier; +} + +void Animation::SetName(const std::string& name_id) { + name = name_id; +} + +std::vector Animation::GetSkeletalVertexAttributes() const { + return vertex_attributes; +} diff --git a/src/types/VRamList.cpp b/src/types/VRamList.cpp index 36faa46..ff34168 100644 --- a/src/types/VRamList.cpp +++ b/src/types/VRamList.cpp @@ -55,7 +55,7 @@ long JGL::VRamList::GetLength() const { return num_elements; } -size_t JGL::VRamList::GetSize() const { +size_t JGL::VRamList::GetDataSize() const { if (element_array_buffer) return sizeof(GLuint) * num_elements; return sizeof(GLfloat) * num_elements; @@ -67,14 +67,11 @@ void JGL::VRamList::SetData(void* data, const long& length) { if (should_resize) { glDeleteBuffers(1, &list_handle); list_handle = 0; - - if (!element_array_buffer) - load((GLfloat*) data, sizeof(GLfloat) * length); - else - load((GLuint*) data, sizeof(GLuint) * length); + element_array_buffer ? load((GLuint*) data, sizeof(GLuint) * length) : load((GLfloat*) data, sizeof(GLfloat) * length); return; } + // if (!should resize) GLint current_buffer = 0; GLenum buffer_type = GL_ARRAY_BUFFER; GLenum buffer_binding = GL_ARRAY_BUFFER_BINDING; @@ -107,14 +104,14 @@ void JGL::VRamList::UpdateData(void* data, const long& offset, const long& lengt auto list_data = GetDataUI(); list_data.resize(list_data.size() + oob_delta); memcpy(list_data.data() + (offset * sizeof(GLuint)), data, length * sizeof(GLuint)); - SetData(list_data.data(), list_data.size()); - } - else { - auto list_data = GetDataF(); - list_data.resize(list_data.size() + oob_delta); - memcpy(list_data.data() + (offset * sizeof(GLfloat)), data, length * sizeof(GLfloat)); - SetData(list_data.data(), list_data.size()); + return SetData(list_data.data(), list_data.size()); } + + // if (!element_array_buffer) + auto list_data = GetDataF(); + list_data.resize(list_data.size() + oob_delta); + memcpy(list_data.data() + (offset * sizeof(GLfloat)), data, length * sizeof(GLfloat)); + return SetData(list_data.data(), list_data.size()); } GLint current_buffer = 0; diff --git a/src/types/VertexArray.cpp b/src/types/VertexArray.cpp index f613116..e33f6ed 100644 --- a/src/types/VertexArray.cpp +++ b/src/types/VertexArray.cpp @@ -164,3 +164,28 @@ VertexArray::VertexArray(const Vector3* vertex_positions, const long& vp_length, } } + +VertexArray::VertexArray(const std::vector& vertex_positions, const std::vector& vertex_indices, + const std::vector& vertex_normals, const std::vector& texture_coordinates) { + vertices = VRamList(vertex_positions.data(), vertex_positions.size()); + local_vertices = vertex_positions; + + if (!vertex_indices.empty()) { + indices = VRamList(vertex_indices.data(), vertex_indices.size()); + local_indices = vertex_indices; + } + + if (!vertex_normals.empty()) { + normals = VRamList(vertex_normals.data(), vertex_normals.size()); + local_normals = vertex_normals; + } + + if (!texture_coordinates.empty()){ + this->texture_coordinates = VRamList(texture_coordinates.data(), texture_coordinates.size()); + local_texture_coordinates = texture_coordinates; + } +} + +bool VertexArray::Static() { + return animations.empty(); +}