Compare commits
8 Commits
Feature/In
...
db6def3bc9
Author | SHA1 | Date | |
---|---|---|---|
db6def3bc9 | |||
ab5599f1fc | |||
3639f967e1 | |||
5a06b068f3 | |||
e31fd036ea | |||
6a2e8d3b2f | |||
f8b390923e | |||
b7e3465406 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -4,12 +4,14 @@
|
||||
[submodule "glm"]
|
||||
path = libs/glm
|
||||
url = https://github.com/nigelbarink/glm.git
|
||||
ignore = untracked
|
||||
[submodule "spdlog"]
|
||||
path = libs/spdlog
|
||||
url = https://github.com/nigelbarink/spdlog.git
|
||||
[submodule "tinygltf"]
|
||||
path = libs/tinygltf
|
||||
url = https://github.com/syoyo/tinygltf.git
|
||||
ignore = untracked
|
||||
[submodule "GorrillaAudio"]
|
||||
path = libs/GorillaAudio
|
||||
url = https://github.com/mewspring/gorilla-audio.git
|
||||
@ -22,6 +24,7 @@
|
||||
[submodule "libs/steam-audio"]
|
||||
path = libs/steam-audio
|
||||
url = https://github.com/ValveSoftware/steam-audio.git
|
||||
ignore = untracked
|
||||
[submodule "libs/physx"]
|
||||
path = libs/physx
|
||||
url = https://git.barink.dev/Nigel/PhysX.git
|
||||
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -1,6 +0,0 @@
|
||||
{
|
||||
"cmake.configureOnOpen": true,
|
||||
"files.associations": {
|
||||
"iosfwd": "cpp"
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
||||
|
||||
#include "Graphics/Mesh.h"
|
||||
@ -9,18 +10,25 @@
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <string>
|
||||
#include "Scene/SceneNodeTypes.h"
|
||||
|
||||
class ModelImporter {
|
||||
private:
|
||||
void ImportFBX(std::string path);
|
||||
void ImportBlend(std::string path);
|
||||
void ImportGLTF(std::string path);
|
||||
void ImportOBJ(std::string path);
|
||||
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
|
||||
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
|
||||
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
|
||||
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
|
||||
|
||||
public:
|
||||
void Import(std::string path);
|
||||
namespace BarinkEngine {
|
||||
class ModelImporter {
|
||||
|
||||
static std::vector<BarinkEngine::Mesh> Test();
|
||||
};
|
||||
public:
|
||||
|
||||
SceneObject* Import(const std::string path);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
|
||||
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -15,10 +15,7 @@
|
||||
#include "Scene.h"
|
||||
#include "PerfCounter.h"
|
||||
|
||||
|
||||
extern void Start();
|
||||
extern void Update();
|
||||
extern void ImmediateGraphicsDraw();
|
||||
extern void Stop();
|
||||
|
||||
extern BarinkEngine::InputManager InputSystem;
|
7
BarinkEngine/Include/ECS/Component.h
Normal file
7
BarinkEngine/Include/ECS/Component.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
namespace BECS {
|
||||
|
||||
struct Component {
|
||||
|
||||
};
|
||||
}
|
13
BarinkEngine/Include/ECS/Entity.h
Normal file
13
BarinkEngine/Include/ECS/Entity.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "Component.h"
|
||||
|
||||
|
||||
namespace BECS {
|
||||
|
||||
typedef unsigned long int Entity;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
7
BarinkEngine/Include/ECS/System.h
Normal file
7
BarinkEngine/Include/ECS/System.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
namespace BECS {
|
||||
|
||||
struct System {
|
||||
|
||||
};
|
||||
}
|
17
BarinkEngine/Include/ECS/World.h
Normal file
17
BarinkEngine/Include/ECS/World.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "System.h"
|
||||
#include <vector>
|
||||
#include "Component.h"
|
||||
#include "Entity.h"
|
||||
|
||||
|
||||
namespace BECS {
|
||||
struct World {
|
||||
|
||||
private:
|
||||
std::vector<System> systems;
|
||||
std::vector<Component> components;
|
||||
std::vector<Entity> entities;
|
||||
|
||||
};
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#include "EventListener.h"
|
||||
|
||||
void EventListener::ReceiveEvent(Event& incident)
|
||||
{
|
||||
}
|
@ -1,8 +1,12 @@
|
||||
#pragma once
|
||||
#include "Event.h"
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "Event.h"
|
||||
|
||||
class EventListener{
|
||||
public:
|
||||
virtual void ReceiveEvent(Event& incident);
|
||||
virtual void ReceiveEvent(Event& incident) = 0 ;
|
||||
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
class Buffer {
|
||||
class GpuBuffer {
|
||||
private:
|
||||
unsigned int id;
|
||||
public:
|
||||
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
#include "VertexArray.h"
|
||||
#include "Buffer.h"
|
||||
|
||||
namespace BarinkEngine{
|
||||
|
||||
|
||||
struct Vertex {
|
||||
glm::vec3 vertices;
|
||||
glm::vec2 uv;
|
||||
@ -13,8 +14,13 @@ namespace BarinkEngine{
|
||||
class Mesh {
|
||||
public:
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<unsigned int > elements;
|
||||
std::vector<unsigned int> elements;
|
||||
|
||||
private:
|
||||
GpuBuffer vertexBuffer;
|
||||
GpuBuffer elementBuffer;
|
||||
VertexArray VAO;
|
||||
unsigned int UV_id;
|
||||
};
|
||||
|
||||
}
|
@ -20,8 +20,8 @@ private:
|
||||
std::vector<unsigned int > indices;
|
||||
|
||||
|
||||
Buffer vertexBuffer;
|
||||
Buffer elementBuffer;
|
||||
GpuBuffer vertexBuffer;
|
||||
GpuBuffer elementBuffer;
|
||||
|
||||
VertexArray VAO;
|
||||
|
||||
|
@ -1,37 +1,23 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "Mesh.h"
|
||||
#include "Buffer.h"
|
||||
|
||||
#include "Material.h"
|
||||
#include "Texture.h"
|
||||
#include "VertexArray.h"
|
||||
|
||||
#include "Scene.h"
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
class Renderable : public SceneNode {
|
||||
public:
|
||||
/*
|
||||
* NOTE: Should combine into a Mesh!!
|
||||
*/
|
||||
Buffer vertexBuffer;
|
||||
Buffer elementBuffer;
|
||||
//Buffer uv;
|
||||
VertexArray VAO;
|
||||
class Renderable {
|
||||
public:
|
||||
Mesh mesh;
|
||||
Material* material;
|
||||
Texture* texture;
|
||||
|
||||
Shader* shader;
|
||||
|
||||
GLuint UV_id;
|
||||
Material* material;
|
||||
Texture* texture;
|
||||
|
||||
|
||||
Shader* shader;
|
||||
|
||||
~Renderable();
|
||||
|
||||
static Renderable* Load();
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
std::vector<BarinkEngine::Mesh> meshes;
|
||||
Renderable();
|
||||
};
|
||||
Renderable();
|
||||
~Renderable();
|
||||
};
|
||||
}
|
11
BarinkEngine/Include/Graphics/Transform.h
Normal file
11
BarinkEngine/Include/Graphics/Transform.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
struct Transform {
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Rotation;
|
||||
glm::vec3 Scale;
|
||||
|
||||
glm::mat4 ModelMatrix;
|
||||
};
|
||||
|
||||
|
@ -2,12 +2,15 @@
|
||||
#define GLFW_STATIC
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "../Include/EventSystem/EventListener.h"
|
||||
|
||||
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "EventSystem/Event.h"
|
||||
#include "EventSystem/EventListener.h"
|
||||
|
||||
class BarinkWindow : EventListener {
|
||||
private:
|
||||
@ -18,16 +21,13 @@ class BarinkWindow : EventListener {
|
||||
|
||||
static bool InitGLFW();
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
BarinkWindow(const int width, const int height);
|
||||
~BarinkWindow();
|
||||
|
||||
GLFWwindow* windowptr();
|
||||
|
||||
void ReceiveEvent(Event& incident) override;
|
||||
void ReceiveEvent(Event& incident) override ;
|
||||
bool WindowShouldClose();
|
||||
|
||||
void Poll();
|
||||
|
@ -1,7 +1,11 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "Graphics/Window.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "EventSystem/EventEmitter.h"
|
||||
#include "EventSystem/EventListener.h"
|
||||
#include "Graphics/Window.h"
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
@ -12,8 +16,6 @@ namespace BarinkEngine {
|
||||
void PollEvents();
|
||||
void attach(BarinkWindow* window);
|
||||
|
||||
|
||||
|
||||
// GLFW Handlers
|
||||
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void CursorPositionCallback(GLFWwindow* window, double x, double y);
|
||||
@ -25,3 +27,5 @@ namespace BarinkEngine {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
extern BarinkEngine::InputManager InputSystem;
|
@ -3,13 +3,13 @@
|
||||
#include <imgui.h>
|
||||
|
||||
struct EngineStatistics {
|
||||
uint32_t lastSampleTime;
|
||||
long long lastSampleTime;
|
||||
float frameTime;
|
||||
uint32_t verts;
|
||||
uint32_t DC;
|
||||
|
||||
uint64_t frames;
|
||||
uint64_t FPS;
|
||||
long long frames;
|
||||
long long FPS;
|
||||
};
|
||||
extern EngineStatistics* ES;
|
||||
|
||||
@ -18,15 +18,15 @@ inline void PerfomanceSamplerInit(){
|
||||
ES->frames = 0;
|
||||
ES->lastSampleTime = 0;
|
||||
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
|
||||
|
||||
}
|
||||
|
||||
inline void SamplePerformance(void) {
|
||||
ES->frames++;
|
||||
ES->DC = 0;
|
||||
ES->verts = 0;
|
||||
unsigned int now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
unsigned int MilliSecondsPast = now - ES->lastSampleTime;
|
||||
unsigned long long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
unsigned long long MilliSecondsPast = now - ES->lastSampleTime;
|
||||
if (MilliSecondsPast >= 1000) {
|
||||
|
||||
ES->frameTime = (float)1000 / ES->frames;
|
||||
|
@ -2,46 +2,22 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
#include "Graphics/Transform.h"
|
||||
#include "Scene/Node.h"
|
||||
/*
|
||||
* Scene should be a description of a game world
|
||||
*/
|
||||
|
||||
struct Transform {
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Rotation;
|
||||
glm::vec3 Scale;
|
||||
|
||||
glm::mat4 ModelMatrix;
|
||||
};
|
||||
|
||||
|
||||
class SceneNode {
|
||||
public:
|
||||
std::string name;
|
||||
Transform transform;
|
||||
SceneNode* parent;
|
||||
std::vector<SceneNode*> children;
|
||||
|
||||
|
||||
void addChild(SceneNode& node);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class Scene {
|
||||
|
||||
public:
|
||||
SceneNode& GetSceneNode(std::string);
|
||||
SceneNode& GetRoot();
|
||||
Node& GetSceneNode(std::string);
|
||||
Node& GetRoot();
|
||||
|
||||
Scene(std::string SceneName = "Default Scene");
|
||||
Scene(const std::string& sceneName = "Default Scene");
|
||||
~Scene();
|
||||
|
||||
|
||||
private:
|
||||
SceneNode* root;
|
||||
Node* root;
|
||||
|
||||
};
|
||||
|
||||
|
24
BarinkEngine/Include/Scene/Node.h
Normal file
24
BarinkEngine/Include/Scene/Node.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Graphics/Transform.h"
|
||||
|
||||
class Node {
|
||||
public:
|
||||
Node(const std::string& name);
|
||||
std::string name;
|
||||
Node* parent;
|
||||
std::vector<Node*> children;
|
||||
|
||||
void addChild(Node& node);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Group : public Node {
|
||||
public:
|
||||
Group(const std::string& name);
|
||||
Transform& transform;
|
||||
|
||||
};
|
15
BarinkEngine/Include/Scene/SceneBuilder.h
Normal file
15
BarinkEngine/Include/Scene/SceneBuilder.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "Graphics/Renderable.h"
|
||||
#include "Scene/SceneNodeTypes.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "../../src/Scene/SceneNodeTypes.cpp"
|
||||
/*
|
||||
* Define a helper class to more easily build a proper scene
|
||||
*/
|
||||
static class SceneBuilder {
|
||||
|
||||
static Group* AddGroup(std::string name);
|
||||
static BarinkEngine::SceneObject* AddVisual(std::string name, BarinkEngine::Renderable& object, glm::vec3 position );
|
||||
|
||||
};
|
17
BarinkEngine/Include/Scene/SceneManager.h
Normal file
17
BarinkEngine/Include/Scene/SceneManager.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "Scene.h"
|
||||
class SceneManager {
|
||||
|
||||
public:
|
||||
static Scene* CreateScene(const std::string& name );
|
||||
static Scene& GetScene(const std::string& name);
|
||||
|
||||
static void LoadScene(Scene& scene);
|
||||
|
||||
private:
|
||||
static Scene* CurrentScene;
|
||||
static std::map<std::string, Scene*> Scenes;
|
||||
|
||||
};
|
22
BarinkEngine/Include/Scene/SceneNodeTypes.h
Normal file
22
BarinkEngine/Include/Scene/SceneNodeTypes.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "Graphics/Camera.h"
|
||||
#include "Graphics/Renderable.h"
|
||||
#include "Scene/Node.h"
|
||||
|
||||
namespace BarinkEngine {
|
||||
class SceneCamera : public Group
|
||||
{
|
||||
public:
|
||||
Camera& camera;
|
||||
SceneCamera();
|
||||
};
|
||||
|
||||
|
||||
class SceneObject : public Group
|
||||
{
|
||||
public:
|
||||
SceneObject(std::string name, Renderable* visual);
|
||||
~SceneObject();
|
||||
Renderable* renderable;
|
||||
};
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#include "Scene.h"
|
||||
|
||||
|
||||
SceneNode* SearchInChildren(SceneNode* root, std::string name ) {
|
||||
|
||||
if (root->name == name)
|
||||
return root;
|
||||
|
||||
SceneNode* found = nullptr;
|
||||
for (auto child : root->children) {
|
||||
found = SearchInChildren(child, name);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
SceneNode& Scene::GetSceneNode(std::string name)
|
||||
{
|
||||
return *SearchInChildren(root, name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
SceneNode& Scene::GetRoot()
|
||||
{
|
||||
return *root;
|
||||
}
|
||||
|
||||
Scene::Scene(std::string sceneName)
|
||||
{
|
||||
// Create a root node
|
||||
root = new SceneNode();
|
||||
root->name = sceneName;
|
||||
root->transform = Transform();
|
||||
|
||||
root->transform.Position = glm::vec3(0);
|
||||
root->transform.Rotation = glm::vec3(0);
|
||||
root->transform.Scale = glm::vec3(0);
|
||||
|
||||
root->transform.ModelMatrix = glm::mat4(0);
|
||||
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
// Destruct scene!
|
||||
}
|
||||
|
||||
void SceneNode::addChild(SceneNode& node)
|
||||
{
|
||||
children.push_back(&node);
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
#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!");
|
||||
}
|
||||
|
||||
std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
|
||||
|
||||
/*
|
||||
spdlog::info("====== Tiny GLTF ======");
|
||||
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());
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//spdlog::info("======= Assimp ======");
|
||||
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Models/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||
|
||||
aiNode* currentNode = scene->mRootNode;
|
||||
|
||||
return processNode(currentNode, scene);
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) {
|
||||
std::vector<BarinkEngine::Mesh> meshes;
|
||||
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
meshes.push_back(processMesh(mesh, scene));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
||||
auto m2 = processNode(node->mChildren[i], scene);
|
||||
|
||||
for(auto m : m2) {
|
||||
meshes.push_back(m);
|
||||
}
|
||||
}
|
||||
|
||||
return meshes;
|
||||
}
|
||||
|
||||
BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||
std::vector<unsigned int> indices;
|
||||
std::vector<BarinkEngine::Vertex> vertices;
|
||||
|
||||
// Process vertices
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||
BarinkEngine::Vertex v{};
|
||||
glm::vec3 vector;
|
||||
vector.x = mesh->mVertices[i].x;
|
||||
vector.y = mesh->mVertices[i].y;
|
||||
vector.z = mesh->mVertices[i].z;
|
||||
|
||||
v.vertices = vector;
|
||||
|
||||
if (mesh->mTextureCoords[0]) {
|
||||
|
||||
glm::vec2 texCoord;
|
||||
|
||||
texCoord.x = mesh->mTextureCoords[0][i].x;
|
||||
texCoord.y = mesh->mTextureCoords[0][i].y;
|
||||
|
||||
v.uv = texCoord;
|
||||
|
||||
}
|
||||
|
||||
vertices.push_back(v);
|
||||
}
|
||||
|
||||
// Process Indices
|
||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||
aiFace face = mesh->mFaces[i];
|
||||
if (face.mNumIndices < 3)
|
||||
continue;
|
||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||
indices.push_back(face.mIndices[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
BarinkEngine::Mesh result;
|
||||
|
||||
|
||||
result.vertices = vertices;
|
||||
result.elements = indices;
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
#include "Graphics/Renderable.h"
|
||||
#include "AssetManager/ModelImporter.h"
|
||||
#include "PerfCounter.h"
|
||||
|
||||
|
||||
Renderable* Renderable::Load()
|
||||
{
|
||||
return new Renderable();
|
||||
}
|
||||
|
||||
Renderable::Renderable()
|
||||
{
|
||||
meshes = ModelImporter::Test();
|
||||
|
||||
transform.Scale = glm::vec3(1.0f);
|
||||
transform.Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
transform.Position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
VAO.Create();
|
||||
VAO.Bind();
|
||||
|
||||
|
||||
vertexBuffer.createBuffer();
|
||||
vertexBuffer.Bind(false);
|
||||
vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
||||
|
||||
elementBuffer.createBuffer();
|
||||
elementBuffer.Bind(true);
|
||||
elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
|
||||
|
||||
VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
|
||||
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices));
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
vertexBuffer.Unbind(false);
|
||||
|
||||
VAO.Unbind();
|
||||
|
||||
|
||||
}
|
||||
|
||||
Renderable::~Renderable()
|
||||
{
|
||||
glDeleteBuffers(1, &UV_id);
|
||||
}
|
||||
|
||||
void Renderable::Draw()
|
||||
{
|
||||
VAO.Bind();
|
||||
elementBuffer.Bind(true);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0);
|
||||
texture->Bind();
|
||||
|
||||
ES->verts = meshes[0].vertices.size();
|
||||
ES->DC++;
|
||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
|
||||
VAO.Unbind();
|
||||
|
||||
}
|
@ -52,10 +52,10 @@ project "BarinkEngine"
|
||||
files {
|
||||
"../libs/glad/src/glad.c",
|
||||
|
||||
"./*.cpp",
|
||||
"./*.h",
|
||||
"./**/*.cpp",
|
||||
"./**/*.h"
|
||||
"./src/*.cpp",
|
||||
"./Include/*.h",
|
||||
"./src/**/*.cpp",
|
||||
"./Include/**/*.h"
|
||||
}
|
||||
|
||||
|
||||
@ -63,10 +63,10 @@ project "BarinkEngine"
|
||||
filter { "system:windows"}
|
||||
prebuildcommands {
|
||||
-- Copy shaders
|
||||
"copy graphics\\shaders\\fragment.shader ..\\build\\SandboxApplication\\Debug\\test.fs",
|
||||
"copy graphics\\shaders\\vertex.shader ..\\build\\SandboxApplication\\Debug\\test.vs",
|
||||
"copy graphics\\shaders\\RenderSurfaceFrag.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.fs",
|
||||
"copy graphics\\shaders\\RenderSurfaceVert.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.vs"
|
||||
"copy src\\graphics\\shaders\\fragment.shader ..\\build\\SandboxApplication\\Debug\\test.fs",
|
||||
"copy src\\graphics\\shaders\\vertex.shader ..\\build\\SandboxApplication\\Debug\\test.vs",
|
||||
"copy src\\graphics\\shaders\\RenderSurfaceFrag.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.fs",
|
||||
"copy src\\graphics\\shaders\\RenderSurfaceVert.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.vs"
|
||||
}
|
||||
|
||||
|
||||
@ -74,10 +74,10 @@ project "BarinkEngine"
|
||||
filter { "system:linux" }
|
||||
prebuildcommands {
|
||||
-- Copy shaders
|
||||
"cp graphics/shaders/fragment.shader ../build/SandboxApplication/Debug/test.fs",
|
||||
"cp graphics/shaders/vertex.shader ../build/SandboxApplication/Debug/test.vs",
|
||||
"cp graphics/shaders/RenderSurfaceFrag.shader ../build/SandboxApplication/Debug/RenderSurface.fs",
|
||||
"cp graphics/shaders/RenderSurfaceVert.shader ../build/SandboxApplication/Debug/RenderSurface.vs"
|
||||
"cp src/graphics/shaders/fragment.shader ../build/SandboxApplication/Debug/test.fs",
|
||||
"cp src/graphics/shaders/vertex.shader ../build/SandboxApplication/Debug/test.vs",
|
||||
"cp src/graphics/shaders/RenderSurfaceFrag.shader ../build/SandboxApplication/Debug/RenderSurface.fs",
|
||||
"cp src/graphics/shaders/RenderSurfaceVert.shader ../build/SandboxApplication/Debug/RenderSurface.vs"
|
||||
}
|
||||
|
||||
include('../ImGui')
|
||||
|
@ -1,64 +1,62 @@
|
||||
#include "BarinkEngine.h"
|
||||
#include <phonon.h>
|
||||
|
||||
EngineStatistics* ES;
|
||||
BarinkEngine::InputManager InputSystem;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Setup performance sampler
|
||||
PerfomanceSamplerInit();
|
||||
|
||||
|
||||
// Startup services
|
||||
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
||||
|
||||
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
|
||||
InputSystem = BarinkEngine::InputManager();
|
||||
|
||||
InputSystem.attach(&MainWindow);
|
||||
|
||||
GUIManager GUISystem = GUIManager(&MainWindow);
|
||||
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
|
||||
// First call to setup game
|
||||
Start();
|
||||
|
||||
|
||||
|
||||
// Runtime loop
|
||||
while (!MainWindow.WindowShouldClose()) {
|
||||
|
||||
SamplePerformance();
|
||||
|
||||
|
||||
// Execute main logic
|
||||
InputSystem.PollEvents();
|
||||
|
||||
Update();
|
||||
|
||||
renderer.Render();
|
||||
|
||||
ImmediateGraphicsDraw();
|
||||
|
||||
GUISystem.Render();
|
||||
|
||||
|
||||
|
||||
MainWindow.SwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
// Shutdown game
|
||||
Stop();
|
||||
|
||||
|
||||
// Shutdown Services
|
||||
delete ES;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "BarinkEngine.h"
|
||||
|
||||
EngineStatistics* ES;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Setup performance sampler
|
||||
PerfomanceSamplerInit();
|
||||
|
||||
|
||||
// Startup services
|
||||
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
||||
|
||||
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
|
||||
InputSystem = BarinkEngine::InputManager();
|
||||
|
||||
InputSystem.attach(&MainWindow);
|
||||
|
||||
GUIManager GUISystem = GUIManager(&MainWindow);
|
||||
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
|
||||
// First call to setup game
|
||||
Start();
|
||||
|
||||
|
||||
|
||||
// Runtime loop
|
||||
while (!MainWindow.WindowShouldClose()) {
|
||||
|
||||
SamplePerformance();
|
||||
|
||||
|
||||
// Execute main logic
|
||||
InputSystem.PollEvents();
|
||||
|
||||
Update();
|
||||
|
||||
renderer.Render();
|
||||
|
||||
ImmediateGraphicsDraw();
|
||||
|
||||
GUISystem.Render();
|
||||
|
||||
|
||||
|
||||
MainWindow.SwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
// Shutdown game
|
||||
Stop();
|
||||
|
||||
|
||||
// Shutdown Services
|
||||
delete ES;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,47 +1,47 @@
|
||||
#include "Graphics/Buffer.h"
|
||||
|
||||
|
||||
int Buffer::getBufferID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void Buffer::createBuffer() {
|
||||
glGenBuffers(1, (GLuint*) &id);
|
||||
}
|
||||
|
||||
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
||||
|
||||
if (elementBuffer) {
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||
|
||||
}
|
||||
else {
|
||||
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Buffer::Bind(bool elementBuffer = false ) {
|
||||
if (elementBuffer) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||
|
||||
}
|
||||
else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Buffer::Unbind(bool elementBuffer = false) {
|
||||
if (elementBuffer) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Buffer::Delete() {
|
||||
glDeleteBuffers(1, (GLuint*) &id);
|
||||
#include "Graphics/Buffer.h"
|
||||
|
||||
|
||||
int GpuBuffer::getBufferID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void GpuBuffer::createBuffer() {
|
||||
glGenBuffers(1, (GLuint*) &id);
|
||||
}
|
||||
|
||||
void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
||||
|
||||
if (elementBuffer) {
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||
|
||||
}
|
||||
else {
|
||||
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GpuBuffer::Bind(bool elementBuffer = false ) {
|
||||
if (elementBuffer) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||
|
||||
}
|
||||
else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void GpuBuffer::Unbind(bool elementBuffer = false) {
|
||||
if (elementBuffer) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void GpuBuffer::Delete() {
|
||||
glDeleteBuffers(1, (GLuint*) &id);
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
#include "../Include/Graphics/Material.h"
|
||||
|
||||
Material::Material(const Shader& shader) :
|
||||
shader(shader) {
|
||||
}
|
||||
|
||||
|
||||
void Material::Apply() {
|
||||
shader.setUniformVec3("Color", Color);
|
||||
#include "../Include/Graphics/Material.h"
|
||||
|
||||
Material::Material(const Shader& shader) :
|
||||
shader(shader) {
|
||||
}
|
||||
|
||||
|
||||
void Material::Apply() {
|
||||
shader.setUniformVec3("Color", Color);
|
||||
}
|
95
BarinkEngine/src/Graphics/ModelImporter.cpp
Normal file
95
BarinkEngine/src/Graphics/ModelImporter.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
#include "AssetManager/ModelImporter.h"
|
||||
|
||||
|
||||
BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)
|
||||
{
|
||||
|
||||
SceneObject* root = new SceneObject(std::string(path), nullptr);
|
||||
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||
|
||||
aiNode* currentNode = scene->mRootNode;
|
||||
|
||||
std::vector<BarinkEngine::Mesh> meshes = processNode(currentNode, scene);
|
||||
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
|
||||
std::vector<BarinkEngine::Mesh> BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene)
|
||||
{
|
||||
|
||||
std::vector<BarinkEngine::Mesh> meshes;
|
||||
|
||||
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
meshes.push_back(processMesh(mesh, scene));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
||||
auto m2 = processNode(node->mChildren[i], scene);
|
||||
|
||||
for(auto m : m2) {
|
||||
meshes.push_back(m);
|
||||
}
|
||||
}
|
||||
|
||||
return meshes;
|
||||
}
|
||||
|
||||
BarinkEngine::Mesh BarinkEngine::ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||
std::vector<unsigned int> indices;
|
||||
std::vector<BarinkEngine::Vertex> vertices;
|
||||
|
||||
ProcessVertices(mesh, vertices);
|
||||
|
||||
ProcessIndices(mesh, indices);
|
||||
|
||||
BarinkEngine::Mesh result;
|
||||
result.vertices = vertices;
|
||||
result.elements = indices;
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices) {
|
||||
// Process vertices
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||
BarinkEngine::Vertex v{};
|
||||
glm::vec3 vector;
|
||||
vector.x = mesh->mVertices[i].x;
|
||||
vector.y = mesh->mVertices[i].y;
|
||||
vector.z = mesh->mVertices[i].z;
|
||||
|
||||
v.vertices = vector;
|
||||
|
||||
if (mesh->mTextureCoords[0]) {
|
||||
|
||||
glm::vec2 texCoord;
|
||||
|
||||
texCoord.x = mesh->mTextureCoords[0][i].x;
|
||||
texCoord.y = mesh->mTextureCoords[0][i].y;
|
||||
|
||||
v.uv = texCoord;
|
||||
|
||||
}
|
||||
|
||||
out_vertices.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
|
||||
// Process Indices
|
||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||
aiFace face = mesh->mFaces[i];
|
||||
if (face.mNumIndices < 3)
|
||||
continue;
|
||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||
out_indices.push_back(face.mIndices[j]);
|
||||
}
|
||||
}
|
||||
}
|
53
BarinkEngine/src/Graphics/Renderable.cpp
Normal file
53
BarinkEngine/src/Graphics/Renderable.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "Graphics/Renderable.h"
|
||||
#include "AssetManager/ModelImporter.h"
|
||||
#include "PerfCounter.h"
|
||||
|
||||
|
||||
BarinkEngine::Renderable::Renderable()
|
||||
{
|
||||
/*
|
||||
|
||||
VAO.Create();
|
||||
VAO.Bind();
|
||||
|
||||
|
||||
vertexBuffer.createBuffer();
|
||||
vertexBuffer.Bind(false);
|
||||
vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
||||
|
||||
elementBuffer.createBuffer();
|
||||
elementBuffer.Bind(true);
|
||||
elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
|
||||
|
||||
VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
|
||||
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices));
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
//vertexBuffer.Unbind(false);
|
||||
|
||||
VAO.Unbind();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
BarinkEngine::Renderable::~Renderable()
|
||||
{
|
||||
// glDeleteBuffers(1, &UV_id);
|
||||
}
|
||||
|
||||
// Draw call Example !!
|
||||
/*
|
||||
VAO.Bind();
|
||||
elementBuffer.Bind(true);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0);
|
||||
texture->Bind();
|
||||
|
||||
ES->verts = meshes[0].vertices.size();
|
||||
ES->DC++;
|
||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
|
||||
VAO.Unbind();
|
||||
*/
|
||||
|
@ -1,25 +1,25 @@
|
||||
#include "Graphics/Renderer.h"
|
||||
|
||||
BarinkEngine::Renderer::Renderer()
|
||||
{
|
||||
models = std::vector<Renderable*>();
|
||||
}
|
||||
|
||||
BarinkEngine::Renderer::~Renderer()
|
||||
{
|
||||
// CleanUp!
|
||||
}
|
||||
|
||||
void BarinkEngine::Renderer::Render()
|
||||
{
|
||||
|
||||
for (auto model : models) {
|
||||
model->Draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::Renderer::Submit(Renderable* model)
|
||||
{
|
||||
models.push_back(model);
|
||||
}
|
||||
#include "Graphics/Renderer.h"
|
||||
|
||||
BarinkEngine::Renderer::Renderer()
|
||||
{
|
||||
models = std::vector<Renderable*>();
|
||||
}
|
||||
|
||||
BarinkEngine::Renderer::~Renderer()
|
||||
{
|
||||
// CleanUp!
|
||||
}
|
||||
|
||||
void BarinkEngine::Renderer::Render()
|
||||
{
|
||||
|
||||
for (auto model : models) {
|
||||
//model->Draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::Renderer::Submit(Renderable* model)
|
||||
{
|
||||
models.push_back(model);
|
||||
}
|
@ -1,40 +1,40 @@
|
||||
#include "../Include/Graphics/Texture.h"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "Graphics/stb_image.h"
|
||||
#include <iostream>
|
||||
|
||||
Texture::Texture(const std::string texturePath) {
|
||||
|
||||
int width, height, channels;
|
||||
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
||||
std::cout << channels << std::endl;
|
||||
|
||||
if (data) {
|
||||
glGenTextures(1, &Id);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, Id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
}
|
||||
else {
|
||||
spdlog::error("Failed to load image (%s)", texturePath );
|
||||
}
|
||||
stbi_image_free(data);
|
||||
|
||||
}
|
||||
|
||||
void Texture::Bind() {
|
||||
glBindTexture(GL_TEXTURE_2D, Id);
|
||||
}
|
||||
|
||||
void Texture::Unbind() {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
#include "../Include/Graphics/Texture.h"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "Graphics/stb_image.h"
|
||||
#include <iostream>
|
||||
|
||||
Texture::Texture(const std::string texturePath) {
|
||||
|
||||
int width, height, channels;
|
||||
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
||||
std::cout << channels << std::endl;
|
||||
|
||||
if (data) {
|
||||
glGenTextures(1, &Id);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, Id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
}
|
||||
else {
|
||||
spdlog::error("Failed to load image (%s)", texturePath );
|
||||
}
|
||||
stbi_image_free(data);
|
||||
|
||||
}
|
||||
|
||||
void Texture::Bind() {
|
||||
glBindTexture(GL_TEXTURE_2D, Id);
|
||||
}
|
||||
|
||||
void Texture::Unbind() {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
@ -1,25 +1,25 @@
|
||||
#include "Graphics/VertexArray.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
void VertexArray::Create(){
|
||||
glGenVertexArrays(1, &id);
|
||||
}
|
||||
|
||||
void VertexArray::Bind(){
|
||||
glBindVertexArray(id);
|
||||
}
|
||||
|
||||
void VertexArray::Unbind(){
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void VertexArray::Delete() {
|
||||
glDeleteVertexArrays(1, &id);
|
||||
}
|
||||
|
||||
|
||||
void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){
|
||||
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
}
|
||||
|
||||
#include "Graphics/VertexArray.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
void VertexArray::Create(){
|
||||
glGenVertexArrays(1, &id);
|
||||
}
|
||||
|
||||
void VertexArray::Bind(){
|
||||
glBindVertexArray(id);
|
||||
}
|
||||
|
||||
void VertexArray::Unbind(){
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void VertexArray::Delete() {
|
||||
glDeleteVertexArrays(1, &id);
|
||||
}
|
||||
|
||||
|
||||
void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){
|
||||
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
#version 440 core
|
||||
|
||||
out vec4 FragColor;
|
||||
uniform vec3 Color;
|
||||
in vec2 TexCoord;
|
||||
uniform sampler2D Texture;
|
||||
|
||||
|
||||
void main(){
|
||||
FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f);
|
||||
#version 440 core
|
||||
|
||||
out vec4 FragColor;
|
||||
uniform vec3 Color;
|
||||
in vec2 TexCoord;
|
||||
uniform sampler2D Texture;
|
||||
|
||||
|
||||
void main(){
|
||||
FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f);
|
||||
}
|
@ -1,84 +1,77 @@
|
||||
#include "Graphics/Window.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "../Include/EventSystem/Event.h"
|
||||
|
||||
bool BarinkWindow::InitGLFW(){
|
||||
if(!glfwInit())
|
||||
{
|
||||
spdlog::error("Failed to initialise GLFW!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BarinkWindow::BarinkWindow(const int width, const int height) :
|
||||
Width(width), Height(height), FullScreen(false){
|
||||
if (InitGLFW()==false) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
||||
|
||||
if( !window)
|
||||
{
|
||||
spdlog::error("GLFW failed to create window!");
|
||||
glfwTerminate();
|
||||
return;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
printf("Failed to initialize GLAD!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Set vsync off !!
|
||||
glfwSwapInterval(0);
|
||||
|
||||
VulkanSupported = glfwVulkanSupported();
|
||||
|
||||
glfwGetFramebufferSize(window, &Width, &Height);
|
||||
glViewport(0,0, Width, Height);
|
||||
|
||||
|
||||
|
||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
BarinkWindow::~BarinkWindow(){
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
GLFWwindow* BarinkWindow::windowptr()
|
||||
{
|
||||
return window;
|
||||
}
|
||||
|
||||
bool BarinkWindow::WindowShouldClose(){
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void BarinkWindow::Poll()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void BarinkWindow::SwapBuffers()
|
||||
{
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
|
||||
void BarinkWindow::ReceiveEvent(Event& incident)
|
||||
{
|
||||
std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
|
||||
|
||||
}
|
||||
#include "Graphics/Window.h"
|
||||
|
||||
bool BarinkWindow::InitGLFW(){
|
||||
if(!glfwInit())
|
||||
{
|
||||
spdlog::error("Failed to initialise GLFW!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BarinkWindow::BarinkWindow(const int width, const int height) :
|
||||
Width(width), Height(height), FullScreen(false){
|
||||
if (InitGLFW()==false) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
||||
|
||||
if( !window)
|
||||
{
|
||||
spdlog::error("GLFW failed to create window!");
|
||||
glfwTerminate();
|
||||
return;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
printf("Failed to initialize GLAD!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Set vsync off !!
|
||||
glfwSwapInterval(0);
|
||||
|
||||
VulkanSupported = glfwVulkanSupported();
|
||||
|
||||
glfwGetFramebufferSize(window, &Width, &Height);
|
||||
glViewport(0,0, Width, Height);
|
||||
|
||||
|
||||
|
||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
BarinkWindow::~BarinkWindow(){
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
GLFWwindow* BarinkWindow::windowptr()
|
||||
{
|
||||
return window;
|
||||
}
|
||||
|
||||
bool BarinkWindow::WindowShouldClose(){
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void BarinkWindow::Poll()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void BarinkWindow::SwapBuffers()
|
||||
{
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
void BarinkWindow::ReceiveEvent(Event& incident)
|
||||
{
|
||||
std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
|
||||
}
|
||||
|
@ -1,118 +1,118 @@
|
||||
#include "BarinkEngine.h"
|
||||
#include "Input/InputManager.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <iostream>
|
||||
void BarinkEngine::InputManager::PollEvents()
|
||||
{
|
||||
for (auto it = windows.begin(); it != windows.end(); ++it) {
|
||||
(*it)->Poll();
|
||||
}
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
|
||||
Event KeyEvent{};
|
||||
KeyEvent.name = "KEY";
|
||||
|
||||
InputSystem.EmitEvent(KeyEvent);
|
||||
|
||||
|
||||
if (key == GLFW_KEY_A && action == GLFW_PRESS)
|
||||
{
|
||||
|
||||
std::cout << "'a' key was pressed" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
//std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl;
|
||||
Event CursorPosUpdate{};
|
||||
CursorPosUpdate.name = "UPDATE::CURSOR:POSITION";
|
||||
|
||||
InputSystem.EmitEvent(CursorPosUpdate);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
|
||||
{
|
||||
if (entered) {
|
||||
Event mouseEntered {};
|
||||
mouseEntered.name = "Mouse Entered Window's confines!";
|
||||
mouseEntered.argc = 0;
|
||||
|
||||
InputSystem.EmitEvent(mouseEntered);
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
Event mouseLeft{};
|
||||
mouseLeft.name = "Mouse Left Window's confines!";
|
||||
mouseLeft.argc = 0;
|
||||
|
||||
InputSystem.EmitEvent(mouseLeft);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
|
||||
Event MouseButtonEvent{};
|
||||
MouseButtonEvent.name = "MOUSEBUTTON";
|
||||
|
||||
InputSystem.EmitEvent(MouseButtonEvent);
|
||||
|
||||
|
||||
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
|
||||
std::cout << "Right mouse button was pressed!" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
|
||||
|
||||
Event ScrollEvent{};
|
||||
ScrollEvent.name = "SCROLL";
|
||||
|
||||
InputSystem.EmitEvent(ScrollEvent);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BarinkEngine::InputManager::attach(BarinkWindow* window)
|
||||
{
|
||||
|
||||
windows.push_back(window);
|
||||
|
||||
// Attach callbacks
|
||||
glfwSetKeyCallback(window->windowptr(), KeyCallback);
|
||||
glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback);
|
||||
glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback);
|
||||
glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback);
|
||||
glfwSetScrollCallback(window->windowptr(), ScrollCallback);
|
||||
|
||||
this->Subscribe( (EventListener&)(*window));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
BarinkEngine::InputManager::InputManager() : EventEmitter ()
|
||||
{
|
||||
windows = std::vector<BarinkWindow*>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "Input/InputManager.h"
|
||||
BarinkEngine::InputManager InputSystem;
|
||||
|
||||
void BarinkEngine::InputManager::PollEvents()
|
||||
{
|
||||
for (auto it = windows.begin(); it != windows.end(); ++it) {
|
||||
auto window = *it;
|
||||
window->Poll();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
|
||||
Event KeyEvent{};
|
||||
KeyEvent.name = "KEY";
|
||||
|
||||
InputSystem.EmitEvent(KeyEvent);
|
||||
|
||||
|
||||
if (key == GLFW_KEY_A && action == GLFW_PRESS)
|
||||
{
|
||||
|
||||
std::cout << "'a' key was pressed" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
//std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl;
|
||||
Event CursorPosUpdate{};
|
||||
CursorPosUpdate.name = "UPDATE::CURSOR:POSITION";
|
||||
|
||||
InputSystem.EmitEvent(CursorPosUpdate);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
|
||||
{
|
||||
if (entered) {
|
||||
Event mouseEntered {};
|
||||
mouseEntered.name = "Mouse Entered Window's confines!";
|
||||
mouseEntered.argc = 0;
|
||||
|
||||
InputSystem.EmitEvent(mouseEntered);
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
Event mouseLeft{};
|
||||
mouseLeft.name = "Mouse Left Window's confines!";
|
||||
mouseLeft.argc = 0;
|
||||
|
||||
InputSystem.EmitEvent(mouseLeft);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
|
||||
Event MouseButtonEvent{};
|
||||
MouseButtonEvent.name = "MOUSEBUTTON";
|
||||
|
||||
InputSystem.EmitEvent(MouseButtonEvent);
|
||||
|
||||
|
||||
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
|
||||
std::cout << "Right mouse button was pressed!" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
|
||||
|
||||
Event ScrollEvent{};
|
||||
ScrollEvent.name = "SCROLL";
|
||||
|
||||
InputSystem.EmitEvent(ScrollEvent);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BarinkEngine::InputManager::attach(BarinkWindow* window)
|
||||
{
|
||||
|
||||
windows.push_back(window);
|
||||
|
||||
// Attach callbacks
|
||||
glfwSetKeyCallback(window->windowptr(), KeyCallback);
|
||||
glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback);
|
||||
glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback);
|
||||
glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback);
|
||||
glfwSetScrollCallback(window->windowptr(), ScrollCallback);
|
||||
|
||||
this->Subscribe( (EventListener&)(*window));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
BarinkEngine::InputManager::InputManager() : EventEmitter ()
|
||||
{
|
||||
windows = std::vector<BarinkWindow*>();
|
||||
}
|
||||
|
||||
|
||||
|
66
BarinkEngine/src/Scene.cpp
Normal file
66
BarinkEngine/src/Scene.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include "Scene.h"
|
||||
#include "Scene.h"
|
||||
#include "Scene/Node.h"
|
||||
void DeleteSubGraph(Node* tree);
|
||||
|
||||
Scene::Scene(const std::string& sceneName)
|
||||
{
|
||||
// Create a root node
|
||||
root = new Group(sceneName);
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
// Delete all nodes in the graph.
|
||||
DeleteSubGraph(root);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Node* SearchInChildren(Node* root, const std::string name ) {
|
||||
|
||||
if (root->name == name)
|
||||
return root;
|
||||
|
||||
Node* found = nullptr;
|
||||
for (auto child : root->children) {
|
||||
found = SearchInChildren(child, name);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
Node& Scene::GetSceneNode(std::string name)
|
||||
{
|
||||
return *SearchInChildren(root, name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Node& Scene::GetRoot()
|
||||
{
|
||||
return *root;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Node::addChild(Node& node)
|
||||
{
|
||||
children.push_back(&node);
|
||||
}
|
||||
|
||||
|
||||
void DeleteSubGraph(Node* tree)
|
||||
{
|
||||
if (tree->children.size() == 0) {
|
||||
delete tree;
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto child : tree->children) {
|
||||
if (child->children.size() > 0) {
|
||||
DeleteSubGraph(child);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
7
BarinkEngine/src/Scene/Node.cpp
Normal file
7
BarinkEngine/src/Scene/Node.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "Scene/Node.h"
|
||||
|
||||
Node::Node(const std::string& name)
|
||||
: name(name), parent(nullptr), children(std::vector<Node*>()) {}
|
||||
|
||||
Group::Group(const std::string& name )
|
||||
: Node(name), transform(Transform()) {}
|
22
BarinkEngine/src/Scene/SceneManager.cpp
Normal file
22
BarinkEngine/src/Scene/SceneManager.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "Scene/SceneManager.h"
|
||||
|
||||
Scene* SceneManager::CreateScene(const std::string& name)
|
||||
{
|
||||
/*
|
||||
Scenes = std::map<std::string, Scene*>();
|
||||
SceneManager::Scenes[name] = new Scene(name);
|
||||
*/
|
||||
|
||||
return new Scene(name);
|
||||
}
|
||||
|
||||
Scene& SceneManager::GetScene(const std::string& name)
|
||||
{
|
||||
return Scene();
|
||||
//return *SceneManager::Scenes[name];
|
||||
}
|
||||
|
||||
void SceneManager::LoadScene( Scene& scene)
|
||||
{
|
||||
//SceneManager::CurrentScene = &scene;
|
||||
}
|
12
BarinkEngine/src/Scene/SceneNodeTypes.cpp
Normal file
12
BarinkEngine/src/Scene/SceneNodeTypes.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "Scene/SceneNodeTypes.h"
|
||||
|
||||
BarinkEngine::SceneCamera::SceneCamera()
|
||||
: Group(std::string("Camera")), camera(Camera(glm::vec3(0.0f), glm::vec3(0.0f), 0))
|
||||
{}
|
||||
|
||||
BarinkEngine::SceneObject::SceneObject(std::string name, Renderable* visual)
|
||||
: Group(name), renderable(visual)
|
||||
{}
|
||||
|
||||
BarinkEngine::SceneObject::~SceneObject()
|
||||
{}
|
@ -1,5 +1,35 @@
|
||||
#include "GUI.h"
|
||||
|
||||
void SceneExplorer(Scene& scene, std::string PanelName) {
|
||||
if (ImGui::Begin(PanelName.c_str())) {
|
||||
ImGui::ListBoxHeader("##ObjectList");
|
||||
|
||||
Node& current = scene.GetRoot();
|
||||
|
||||
Node* next = ¤t;
|
||||
|
||||
// Show first node
|
||||
ImGui::Selectable(next->name.c_str(), true);
|
||||
|
||||
ImGui::Indent();
|
||||
|
||||
if (next->children.size() != 0) {
|
||||
for (auto child : next->children)
|
||||
{
|
||||
std::string& name = child->name;
|
||||
ImGui::Selectable(name.c_str(), false);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::ListBoxFooter();
|
||||
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CameraTool(Camera* cam) {
|
||||
|
||||
ImGui::Begin("Camera");
|
||||
|
@ -5,4 +5,5 @@
|
||||
void CameraTool(Camera* camera);
|
||||
void ScriptingTool(char* code);
|
||||
void transformWindow(Transform& transform, std::string PanelName);
|
||||
void materialWindow(Material& material, std::string PanelName);
|
||||
void materialWindow(Material& material, std::string PanelName);
|
||||
void SceneExplorer(Scene& scene, std::string PanelName);
|
||||
|
@ -1,4 +1,8 @@
|
||||
#include "BarinkEngine.h"
|
||||
#include "Scene\SceneManager.h"
|
||||
#include "Scene\SceneNodeTypes.h"
|
||||
#include "AssetManager/ModelImporter.h"
|
||||
|
||||
#include "imgui.h"
|
||||
#include "GUI.h"
|
||||
#include "Util.h"
|
||||
@ -7,86 +11,52 @@
|
||||
* Define globals
|
||||
*/
|
||||
Camera* cam;
|
||||
|
||||
|
||||
Shader* shader;
|
||||
|
||||
Renderable* Cube;
|
||||
Material* matCube;
|
||||
Texture* textureCube;
|
||||
|
||||
Renderable* Cube2;
|
||||
Material* matCube2;
|
||||
|
||||
char* code = new char[254];
|
||||
|
||||
|
||||
const std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
||||
const std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
||||
|
||||
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
|
||||
|
||||
|
||||
Scene* Level1;
|
||||
// BarinkEngine::SceneObject* cube;
|
||||
/*
|
||||
* Runs once at startup
|
||||
* - USe to initialize the game/sandbox/demo
|
||||
*/
|
||||
void Start() {
|
||||
// Build a basic test scene
|
||||
// NOTE: This will later be done through an editor
|
||||
|
||||
/*
|
||||
Building a very basic scene graph
|
||||
*/
|
||||
SceneNode MyCube = SceneNode();
|
||||
MyCube.name = "MyCube";
|
||||
// Create a level and load it as the current level
|
||||
std::string levelName("Test Level");
|
||||
Level1 = SceneManager::CreateScene(levelName);
|
||||
SceneManager::LoadScene(*Level1);
|
||||
|
||||
SceneNode MyBaby = SceneNode();
|
||||
MyBaby.name = "Baby";
|
||||
// Create a cube node
|
||||
|
||||
// Load a model
|
||||
//cube = MI->Import("build/SandboxApplication/Debug/Models/Cube.obj");
|
||||
|
||||
//Level1->GetRoot().addChild(*cube);
|
||||
|
||||
std::string groupName("Nested-Group");
|
||||
auto testGroup = new Group(groupName);
|
||||
Level1->GetRoot().addChild( *testGroup);
|
||||
|
||||
SceneNode MySecondCube = SceneNode();
|
||||
MySecondCube.name = "MySecondCube";
|
||||
std::string group2Name("Nested-Group2");
|
||||
auto testGroup2 = new Group(group2Name);
|
||||
Level1->GetRoot().addChild(*testGroup2);
|
||||
|
||||
|
||||
MyCube.addChild(MyBaby);
|
||||
|
||||
|
||||
Scene scene = Scene("My awesome Game Scene");
|
||||
scene.GetRoot().addChild(MyCube);
|
||||
scene.GetRoot().addChild(MySecondCube);
|
||||
|
||||
|
||||
// Walk scene graph
|
||||
PrintSceneTree(scene.GetRoot(),0);
|
||||
// Walk scene graph
|
||||
PrintSceneTree(Level1->GetRoot(),0);
|
||||
|
||||
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
||||
|
||||
textureCube = new Texture("build/SandboxApplication/Debug/Textures/wall.jpg");
|
||||
|
||||
matCube = new Material(*shader);
|
||||
matCube->Color = glm::vec3(1.0, 0.0, 0.0);
|
||||
|
||||
matCube2 = new Material(*shader);
|
||||
matCube2->Color = glm::vec3(0.0, 1.0f, 0.0);
|
||||
|
||||
/*
|
||||
* load meshes
|
||||
*/
|
||||
Cube = Renderable::Load();
|
||||
Cube2 = Renderable::Load();
|
||||
Cube->addChild(*Cube2);
|
||||
|
||||
Cube->shader = shader;
|
||||
Cube2->shader = shader;
|
||||
|
||||
Cube->texture = textureCube;
|
||||
Cube2->texture = textureCube;
|
||||
|
||||
Cube2->transform.Position = glm::vec3(-9.0f, 0.0f, 0.0f);
|
||||
|
||||
Cube->transform.Position = glm::vec3(-8.0f, 0.0f, -2.0f);
|
||||
|
||||
cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
||||
|
||||
memset(code, '\0', 254);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -101,24 +71,14 @@ void ImmediateGraphicsDraw() {
|
||||
// at possible GUI elements to use
|
||||
ImGui::ShowDemoWindow();
|
||||
|
||||
|
||||
// Show internal BarinkEngine stats
|
||||
ShowStats();
|
||||
|
||||
|
||||
// Show different tooling for this specific sandbox
|
||||
CameraTool(cam);
|
||||
ScriptingTool(code);
|
||||
|
||||
transformWindow(Cube->transform, "Transform (Cube)");
|
||||
|
||||
transformWindow(Cube2->transform, "Transform (Cube2)");
|
||||
|
||||
materialWindow(*matCube, "Material Cube");
|
||||
materialWindow(*matCube2, "Material Cube2");
|
||||
|
||||
|
||||
|
||||
SceneExplorer(*Level1, "Scene Explorer");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -127,29 +87,26 @@ void ImmediateGraphicsDraw() {
|
||||
*/
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* NOTE: this needs to move to the renderer
|
||||
* Render code should not appear in the sandbox file
|
||||
*/
|
||||
glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
||||
//glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
shader->Use();
|
||||
shader->setUniformMat4("P", projection);
|
||||
shader->setUniformMat4("M", CalculateModelMat(Cube->transform));
|
||||
//shader->setUniformMat4("P", projection);
|
||||
//shader->setUniformMat4("M", CalculateModelMat(cube->transform));
|
||||
|
||||
shader->setUniformMat4("V", cam->GetViewMatrix());
|
||||
matCube->Apply();
|
||||
|
||||
//cube->renderable->material->Apply();
|
||||
|
||||
Cube->Draw();
|
||||
|
||||
shader->setUniformMat4("M", CalculateModelMat(Cube2->transform));
|
||||
matCube2->Apply();
|
||||
|
||||
Cube2->Draw();
|
||||
//Cube->Draw();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -157,18 +114,6 @@ void Update()
|
||||
* - Meant for cleanup
|
||||
*/
|
||||
void Stop() {
|
||||
// Cleanup
|
||||
Cube->VAO.Delete();
|
||||
Cube->elementBuffer.Delete();
|
||||
|
||||
Cube2->VAO.Delete();
|
||||
Cube2->elementBuffer.Delete();
|
||||
|
||||
delete Cube2;
|
||||
delete Cube;
|
||||
|
||||
delete matCube;
|
||||
delete matCube2;
|
||||
|
||||
delete MI;
|
||||
delete shader;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "Util.h"
|
||||
|
||||
void PrintSceneTree(SceneNode& node, int depth) {
|
||||
void PrintSceneTree(Node& node, int depth) {
|
||||
// Indent name based on depth
|
||||
std::cout << " ";
|
||||
for (int i = 0; i < depth; i++) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "BarinkEngine.h"
|
||||
|
||||
void PrintSceneTree(SceneNode& node, int depth);
|
||||
void PrintSceneTree(Node& node, int depth);
|
||||
|
||||
glm::mat4 CalculateModelMat(Transform& transform);
|
Reference in New Issue
Block a user