Added Gorrilla-Audio and Tinygltf Library
Started laying out a assetManager / ModelImporter
This commit is contained in:
parent
8efa1d1d0a
commit
9c92cc05b7
10
.gitignore
vendored
10
.gitignore
vendored
@ -6,3 +6,13 @@ Makefile
|
||||
.vscode/
|
||||
libs/lua
|
||||
libs/glad
|
||||
Debug/
|
||||
*.sln
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
*.vcxproj.user
|
||||
.vs/
|
||||
x64/
|
||||
|
||||
*.gltf
|
||||
!sponza.gltf
|
||||
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -7,3 +7,9 @@
|
||||
[submodule "spdlog"]
|
||||
path = libs/spdlog
|
||||
url = https://github.com/nigelbarink/spdlog.git
|
||||
[submodule "tinygltf"]
|
||||
path = libs/tinygltf
|
||||
url = https://github.com/syoyo/tinygltf.git
|
||||
[submodule "GorrillaAudio"]
|
||||
path = libs/GorillaAudio
|
||||
url = https://github.com/mewspring/gorilla-audio.git
|
||||
|
22
MyGraphicsEngine/Camera.cpp
Normal file
22
MyGraphicsEngine/Camera.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <MyGraphicsEngine/Camera.h>
|
||||
|
||||
Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom)
|
||||
: Position(position), Rotation(rotation), Zoom(zoom) {
|
||||
|
||||
Front = glm::vec3(-1.0f, 0.0f, 0.0f);
|
||||
Right = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
|
||||
}
|
||||
|
||||
Camera::~Camera() {
|
||||
|
||||
}
|
||||
|
||||
glm::mat4 Camera::GetViewMatrix() {
|
||||
return glm::lookAt(
|
||||
Position,
|
||||
Position + Front,
|
||||
Up
|
||||
);
|
||||
}
|
47
MyGraphicsEngine/ModelImporter.cpp
Normal file
47
MyGraphicsEngine/ModelImporter.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include "include/AssetManager/ModelImporter.h"
|
||||
|
||||
void ModelImporter::ImportFBX(std::string path)
|
||||
{
|
||||
spdlog::warn("ImportFBX not implemented!");
|
||||
}
|
||||
|
||||
void ModelImporter::ImportBlend(std::string path)
|
||||
{
|
||||
spdlog::warn("ImportBlend not implemented!");
|
||||
}
|
||||
|
||||
void ModelImporter::ImportGLTF(std::string path)
|
||||
{
|
||||
spdlog::warn("ImportGLTF not implemented!");
|
||||
}
|
||||
|
||||
void ModelImporter::ImportOBJ(std::string path)
|
||||
{
|
||||
spdlog::warn("ImportOBJ not implemented!");
|
||||
}
|
||||
|
||||
void ModelImporter::Import(std::string path)
|
||||
{
|
||||
spdlog::warn("Import not implemented!");
|
||||
}
|
||||
|
||||
void ModelImporter::Test() {
|
||||
tinygltf::Model loadedModel;
|
||||
tinygltf::TinyGLTF loader;
|
||||
std::string error;
|
||||
std::string warn;
|
||||
bool ret = loader.LoadASCIIFromFile(&loadedModel, &error, &warn, "./Build/SandboxApplication/Debug/sponza.gltf");
|
||||
|
||||
if (!warn.empty())
|
||||
spdlog::warn("TinyGLTF Warning: {}", warn);
|
||||
if (!error.empty())
|
||||
spdlog::error("TinyGLTF Error: {}", error);
|
||||
if (!ret) {
|
||||
spdlog::error("TinyGLTF Error: Failed to parse glTF");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
spdlog::info("Meshes in model: {}", loadedModel.meshes.size());
|
||||
spdlog::info("Primitives in mesh: {}", loadedModel.meshes[0].primitives.size());
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
|
||||
int succes;
|
||||
|
||||
char* vertexCode = readFile(vertexShaderPath.c_str());
|
||||
spdlog::info(vertexCode);
|
||||
unsigned int vertId = glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
glShaderSource(vertId, 1, &vertexCode, NULL);
|
||||
@ -20,7 +21,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
|
||||
|
||||
|
||||
char* fragmentCode = readFile(fragmentShaderPath.c_str());
|
||||
|
||||
spdlog::info(fragmentCode);
|
||||
unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
|
||||
@ -93,3 +94,31 @@ void Shader::Use()
|
||||
{
|
||||
glUseProgram(id);
|
||||
}
|
||||
|
||||
|
||||
void Shader::setUniformMat4(std::string uniformName, glm::mat4 matrix4)
|
||||
{
|
||||
glUniformMatrix4fv(glGetUniformLocation(id, uniformName.c_str()), 1, GL_FALSE, glm::value_ptr(matrix4));
|
||||
}
|
||||
void Shader::setUniformVec4(std::string uniformName, glm::vec4 vector4)
|
||||
{
|
||||
glUniform4fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector4));
|
||||
}
|
||||
void Shader::setUniformVec3(std::string uniformName, glm::vec3 vector3)
|
||||
{
|
||||
glUniform3fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector3));
|
||||
}
|
||||
void Shader::setUniformVec2(std::string uniformName, glm::vec2 vector2)
|
||||
{
|
||||
glUniform2fv(glGetUniformLocation(id, uniformName.c_str()),1, glm::value_ptr(vector2));
|
||||
}
|
||||
|
||||
void Shader::setUniformFloat(std::string uniformName, float value)
|
||||
{
|
||||
glUniform1f(glGetUniformLocation(id, uniformName.c_str()), value);
|
||||
}
|
||||
|
||||
void Shader::setUniformInt(std::string uniformName, int value)
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(id, uniformName.c_str()), value);
|
||||
}
|
22
MyGraphicsEngine/include/AssetManager/ModelImporter.h
Normal file
22
MyGraphicsEngine/include/AssetManager/ModelImporter.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
||||
|
||||
#include <tiny_gltf.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <string>
|
||||
|
||||
class ModelImporter {
|
||||
private:
|
||||
void ImportFBX(std::string path);
|
||||
void ImportBlend(std::string path);
|
||||
void ImportGLTF(std::string path);
|
||||
void ImportOBJ(std::string path);
|
||||
|
||||
public:
|
||||
void Import(std::string path);
|
||||
|
||||
static void Test();
|
||||
};
|
@ -1,10 +1,19 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
struct Camera {
|
||||
class Camera {
|
||||
public:
|
||||
glm::vec3 Position;
|
||||
glm::mat4 ViewMat;
|
||||
glm::vec3 Rotation;
|
||||
float Zoom;
|
||||
|
||||
Camera(glm::vec3 position, glm::vec3 rotation, float zoom );
|
||||
~Camera();
|
||||
|
||||
glm::mat4 GetViewMatrix();
|
||||
|
||||
|
||||
private:
|
||||
glm::vec3 Front;
|
||||
glm::vec3 Right;
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Mesh {
|
||||
public:
|
||||
std::vector<float> vertices;
|
||||
std::vector<int> elements;
|
||||
std::vector<float> uv;
|
||||
|
||||
std::vector<glm::vec3> vertices;
|
||||
std::vector<GLushort> elements;
|
||||
std::vector<glm::vec2> uv;
|
||||
};
|
@ -4,15 +4,23 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
|
||||
class Shader {
|
||||
private:
|
||||
int id;
|
||||
const size_t CHUNK_SIZE = 10;
|
||||
char* readFile (const char* filePath);
|
||||
public:
|
||||
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
||||
void Use();
|
||||
void setUniformMat4(std::string uniformName, glm::mat4 matrix4);
|
||||
void setUniformVec4(std::string uniformName, glm::vec4 vector4);
|
||||
void setUniformVec3(std::string uniformName, glm::vec3 vector3);
|
||||
void setUniformVec2(std::string uniformName, glm::vec2 vector2);
|
||||
void setUniformFloat(std::string uniformName, float value);
|
||||
void setUniformInt(std::string uniformName, int value);
|
||||
|
||||
|
||||
};
|
@ -1,8 +1,7 @@
|
||||
#include <glad/glad.h>
|
||||
#include <MyGraphicsEngine/Shader.h>
|
||||
#include <MyGraphicsEngine/Window.h>
|
||||
#include <MyGraphicsEngine/Camera.h>
|
||||
#include <MyGraphicsEngine/Mesh.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
@ -13,16 +12,26 @@
|
||||
#include "lualib.h"
|
||||
}
|
||||
*/
|
||||
//#include <include/AssetManager/ModelImporter.h>
|
||||
|
||||
#include <gorilla/gau.h>
|
||||
#include <gorilla/ga.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
spdlog::info("Working directory: {}", argv[0]);
|
||||
|
||||
//ModelImporter::Test();
|
||||
|
||||
|
||||
|
||||
Mesh mesh;
|
||||
|
||||
mesh.vertices = {
|
||||
0.5f, 0.5f, 0.0f, // top, right
|
||||
0.5f, -0.5f, 0.0f, // bottom right
|
||||
-0.5f, -0.5f, 0.0f, // bottom left
|
||||
-0.5f, 0.5f, 0.0f // top left
|
||||
glm::vec3( 0.5f, 0.5f, 0.0f), // top, right
|
||||
glm::vec3( 0.5f, -0.5f, 0.0f), // bottom right
|
||||
glm::vec3(-0.5f, -0.5f, 0.0f), // bottom left
|
||||
glm::vec3(-0.5f, 0.5f, 0.0f) // top left
|
||||
};
|
||||
|
||||
|
||||
@ -30,6 +39,8 @@ int main (int argc, char *argv[] ){
|
||||
0,1,3,
|
||||
1,2,3
|
||||
};
|
||||
Camera cam(glm::vec3(2.0f, 0.0f, 0.0f), glm::vec3(0.0f,0.0f,0.0f), 90.0f);
|
||||
|
||||
|
||||
BarinkWindow GameWindow(800, 600);
|
||||
|
||||
@ -37,8 +48,6 @@ int main (int argc, char *argv[] ){
|
||||
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
||||
Shader shader (vertexShaderSource, fragmentShaderSource);
|
||||
|
||||
spdlog::info("Working directory: {}", argv[0]);
|
||||
|
||||
/*
|
||||
* lua_State* L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
@ -46,8 +55,8 @@ int main (int argc, char *argv[] ){
|
||||
luaL_dofile(L,"./script.lua");
|
||||
*/
|
||||
|
||||
|
||||
|
||||
spdlog::info("Vertices: {}, {} bytes", mesh.vertices.size(), sizeof(glm::vec3));
|
||||
spdlog::info("Elements: {}, {} bytes", mesh.elements.size(), sizeof(GLushort));
|
||||
|
||||
unsigned int VBO, VAO, EBO;
|
||||
|
||||
@ -55,35 +64,69 @@ int main (int argc, char *argv[] ){
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenBuffers(1, &EBO);
|
||||
|
||||
spdlog::info("Vertices: {}", mesh.vertices.size());
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * mesh.vertices.size() , &mesh.vertices[0], GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, mesh.vertices.size() * sizeof(glm::vec3), &mesh.vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * mesh.elements.size(), &mesh.elements[0], GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mesh.elements.size() * sizeof(GLushort), &mesh.elements[0], GL_STATIC_DRAW);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
||||
glm::vec3 rotation = glm::vec3(0.0f , 90.0f, 0.0f);
|
||||
|
||||
|
||||
glm::mat4 tran = glm::translate(glm::mat4(),glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
glm::mat4 scale = glm::scale(glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
glm::mat4 rot =
|
||||
glm::rotate(glm::mat4(), glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) *
|
||||
glm::rotate(glm::mat4(), glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) *
|
||||
glm::rotate(glm::mat4(), glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
|
||||
glm::mat4 model = tran * rot * scale;
|
||||
|
||||
|
||||
glm::mat4 projection = glm::perspective(cam.Zoom, (800.0f / 600.0f), 0.001f, 100.0f);
|
||||
|
||||
gau_Manager* mgr;
|
||||
ga_Mixer* mixer;
|
||||
ga_Sound sound;
|
||||
ga_Handle handle;
|
||||
gau_SampleSourceLoop* loopSrc = 0;
|
||||
gau_SampleSourceLoop** pLoopSrc = &loopSrc;
|
||||
gc_int32 loop = 0;
|
||||
gc_int32 quit = 0;
|
||||
|
||||
|
||||
gc_initialize(0);
|
||||
mgr = gau_manager_create();
|
||||
mixer = gau_manager_mixer(mgr);
|
||||
|
||||
|
||||
|
||||
|
||||
while (!GameWindow.WindowShouldClose()) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) ;
|
||||
|
||||
shader.Use();
|
||||
shader.setUniformMat4("P", projection);
|
||||
shader.setUniformMat4("M", model);
|
||||
shader.setUniformMat4("V", cam.GetViewMatrix());
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL);
|
||||
glBindVertexArray(0);
|
||||
|
||||
GameWindow.Poll();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
8573
SandboxApplication/sponza.gltf
Normal file
8573
SandboxApplication/sponza.gltf
Normal file
File diff suppressed because it is too large
Load Diff
1
libs/GorillaAudio
Submodule
1
libs/GorillaAudio
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit bd41dddf007f0b8f4366ce082a6a0b9bd1e20508
|
1
libs/tinygltf
Submodule
1
libs/tinygltf
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit a159945db9d97e79a30cb34e2aaa45fd28dea576
|
10
premake5.lua
10
premake5.lua
@ -13,8 +13,11 @@ workspace "BarinkEngine"
|
||||
|
||||
includedirs {
|
||||
"./libs/glad/include",
|
||||
"./MyGraphicsEngine",
|
||||
"./MyGraphicsEngine/include",
|
||||
"./libs/spdlog/include",
|
||||
"./libs/glm",
|
||||
"./libs/GorillaAudio/include",
|
||||
"./libs/lua/include",
|
||||
"./libs/glfw/include",
|
||||
}
|
||||
@ -37,6 +40,7 @@ workspace "BarinkEngine"
|
||||
}
|
||||
|
||||
defines {"DEBUG"}
|
||||
|
||||
symbols "On"
|
||||
|
||||
-- NOTE: make these copy instructions more flexible
|
||||
@ -46,6 +50,7 @@ workspace "BarinkEngine"
|
||||
ok, err = os.copyfile("MyGraphicsEngine/shaders/vertex.shader", "build/SandboxApplication/Debug/test.vs")
|
||||
if err then error("Copy vertex shader source failed!") end
|
||||
|
||||
|
||||
project "MyGraphicsEngine"
|
||||
kind "StaticLib"
|
||||
|
||||
@ -54,6 +59,7 @@ workspace "BarinkEngine"
|
||||
includedirs {
|
||||
"./libs/glad/include",
|
||||
"./libs/glfw/include",
|
||||
"./libs/tinygltf",
|
||||
"./libs/glew/include",
|
||||
"./libs/spdlog/include",
|
||||
"./libs/glm",
|
||||
@ -73,8 +79,8 @@ workspace "BarinkEngine"
|
||||
|
||||
files {
|
||||
"./libs/glad/src/glad.c",
|
||||
"MyGraphicsEngine/*.h",
|
||||
"MyGraphicsEngine/*.cpp"
|
||||
"./MyGraphicsEngine/**/*.*" ,
|
||||
"./MyGraphicsEngine/*.*"
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user