diff --git a/3rdparty/tinygltf/tiny_gltf.h b/3rdparty/tinygltf/tiny_gltf.h index 23c1ebb..500923e 100644 --- a/3rdparty/tinygltf/tiny_gltf.h +++ b/3rdparty/tinygltf/tiny_gltf.h @@ -732,7 +732,7 @@ typedef bool (*LoadImageDataFunction)(Image *, std::string *, int, int, #ifndef TINYGLTF_NO_STB_IMAGE // Declaration of default image loader callback -static bool LoadImageData(Image *image, std::string *err, int req_width, +bool LoadImageData(Image *image, std::string *err, int req_width, int req_height, const unsigned char *bytes, int size, void *); #endif @@ -1197,7 +1197,7 @@ void TinyGLTF::SetImageLoader(LoadImageDataFunction func, void *user_data) { } #ifndef TINYGLTF_NO_STB_IMAGE -static bool LoadImageData(Image *image, std::string *err, int req_width, +bool LoadImageData(Image *image, std::string *err, int req_width, int req_height, const unsigned char *bytes, int size, void *) { int w, h, comp; diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 5ee30ca..9588c74 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES ( ADD_LIBRARY (RenderModule SHARED RenderModule.cc RenderUtils.cc + gltf_implementation.cc ) ADD_LIBRARY (TestModule SHARED diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index 7a232f8..a6378c3 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -10,8 +10,13 @@ using namespace SimpleMath::GL; +typedef tinygltf::Model Model; +typedef tinygltf::TinyGLTF GLTFLoader; + struct Renderer; +float moving_factor = 1.0f; + struct RendererSettings { bool DrawDepth = false; bool DrawLightDepth = false; @@ -59,6 +64,9 @@ VertexArrayMesh gXZPlaneMesh; VertexArrayMesh gUnitCubeMesh; VertexArrayMesh gScreenQuad; +Model gModel; +GLTFLoader gLoader; + // // Module // @@ -386,6 +394,16 @@ void Renderer::Initialize(int width, int height) { mLight.mShadowMapTarget.mQuadMesh = &gScreenQuad; mLight.mShadowMapTarget.mLinearizeDepthProgram = mRenderQuadProgramDepth; mLight.mShadowMapTarget.mLinearizeDepthProgram.RegisterFileModification(); + + // Model + std::string model_file = "data/models/Cube/Cube.gltf"; + std::string err; + bool result = gLoader.LoadASCIIFromFile(&gModel, &err, model_file.c_str()); + if (!err.empty()) { + gLog("Error loading model '%s': %s", model_file.c_str(), err.c_str()); + } else { + gLog("Successfully loaded model '%s'", model_file.c_str()); + } } void Renderer::Shutdown() { @@ -539,7 +557,7 @@ void Renderer::RenderScene(RenderProgram &program, const Camera& camera) { program.SetMat44("uModelMatrix", RotateMat44(200.0f, 0.0f, 1.0f, 0.0f) - * TranslateMat44(-2.0f, 1.0f, -8.0f) + * TranslateMat44(moving_factor * sin(gTimer->mCurrentTime), 1.0f, 0.0f) * ScaleMat44(0.5f, 0.5f, 0.5f)); program.SetVec4("uColor", Vector4f (1.0f, 1.0f, 1.0f, 1.0f)); @@ -582,6 +600,9 @@ void Renderer::RenderGui() { ImGui::EndDock(); if (ImGui::BeginDock("Render Settings")) { + ImGui::Text("Scene"); + ImGui::SliderFloat("Moving Factor", &moving_factor, -10.0f, 10.0f); + ImGui::Text("Camera"); mCamera.DrawGui(); diff --git a/src/modules/RenderUtils.cc b/src/modules/RenderUtils.cc index 4916401..a937116 100644 --- a/src/modules/RenderUtils.cc +++ b/src/modules/RenderUtils.cc @@ -12,10 +12,6 @@ #include "imgui/imgui.h" #include "imgui_dock.h" -#define STB_IMAGE_IMPLEMENTATION - -#include "stb/stb_image.h" - using namespace SimpleMath; using namespace SimpleMath::GL; diff --git a/src/modules/RenderUtils.h b/src/modules/RenderUtils.h index d3007e3..42b3800 100644 --- a/src/modules/RenderUtils.h +++ b/src/modules/RenderUtils.h @@ -7,6 +7,8 @@ #include "FileModificationObserver.h" +#include "tinygltf/tiny_gltf.h" + #include // Forward declarations @@ -288,7 +290,7 @@ struct Texture { }; /** - * Multiple VertexArrayMeshes can be stored in a single VertexArray. + * Storage for (multiple) VertexArrayMeshes * Storage order is: * (VVVV)(NNNN)(UV)(CCCC) */ @@ -413,4 +415,17 @@ struct VertexArrayMesh { void Draw(GLenum mode); }; +struct RenderCommand { + typedef enum { + EnableShadowPass = 1 + } Flags; + + int mFlags; + GLenum mDrawMode; + Vector4f mColor = Vector4f (1.0f, 1.0f, 1.0f, 1.0f); + + Matrix44f mTransform; + VertexArrayMesh *mMesh; +}; + #endif diff --git a/src/modules/gltf_implementation.cc b/src/modules/gltf_implementation.cc new file mode 100644 index 0000000..61e7fda --- /dev/null +++ b/src/modules/gltf_implementation.cc @@ -0,0 +1,4 @@ +#define TINYGLTF_IMPLEMENTATION +#define STB_IMAGE_IMPLEMENTATION +//#include "stb/stb_image.h" +#include "tinygltf/tiny_gltf.h"