Can now load gltf models (but not display them yet)

simple_math_single_header
Martin Felis 2018-03-19 23:01:46 +01:00
parent 8b2dc08ec3
commit a51c1936f2
6 changed files with 45 additions and 8 deletions

View File

@ -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;

View File

@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES (
ADD_LIBRARY (RenderModule SHARED
RenderModule.cc
RenderUtils.cc
gltf_implementation.cc
)
ADD_LIBRARY (TestModule SHARED

View File

@ -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();

View File

@ -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;

View File

@ -7,6 +7,8 @@
#include "FileModificationObserver.h"
#include "tinygltf/tiny_gltf.h"
#include <vector>
// 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

View File

@ -0,0 +1,4 @@
#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
//#include "stb/stb_image.h"
#include "tinygltf/tiny_gltf.h"