Compare commits
73 Commits
99eb5282e5
...
main
Author | SHA1 | Date | |
---|---|---|---|
391fd5a8a8
|
|||
7349c0eb16 | |||
19b630104c | |||
7ec13a7020 | |||
4a84df7c3e | |||
a297c7cb3a | |||
8ef886df83 | |||
817d0bdca9 | |||
c640ac574b | |||
0b2148ad55 | |||
95f77209cf | |||
f7e087ee8d | |||
e52db0fafd | |||
5bdc0034d1 | |||
ceb485018f | |||
daf26c304b | |||
550c1b6e5b | |||
c82398205a | |||
43fc721413 | |||
52747202d3 | |||
fef75ec64b | |||
3c38e2a988 | |||
e9852fe0e7 | |||
8e202f9d59 | |||
d8627d0357 | |||
ec8045c4f4 | |||
042dc3a457 | |||
28927d9a4e | |||
89f5b1497f | |||
7448017701 | |||
ba69726e33 | |||
7223c20f1d | |||
282844b905 | |||
145338d666 | |||
79b68fbff1 | |||
13f67a7cdb | |||
d5a6ddb9d5 | |||
0f9be33bd6 | |||
75aa577211 | |||
fe7e168e21 | |||
3722e63495 | |||
3a9c07aff9 | |||
2dcc3f1803 | |||
2a5c7811e7 | |||
3fa5455b43 | |||
ad79aa2865 | |||
fd68c5dde3 | |||
1f1a776686 | |||
e7f1bd7d52 | |||
a1ec94e983 | |||
4b84707f98 | |||
3d3596a3b6 | |||
628225af45 | |||
b5db500d48 | |||
f7a85d53ab | |||
c57177a1a9 | |||
9a9db279a5 | |||
210d535c41 | |||
b2688e843c | |||
28c64b43ba | |||
02e14aa8fa | |||
7343300dcb | |||
3b91516d6e | |||
c8ebc0fa17 | |||
41d5b87c7b | |||
b44c88d05c | |||
644b6db100 | |||
f37175a01e | |||
c62f3615d4 | |||
3e75406783 | |||
65ae892951 | |||
f0984b6117 | |||
adf2331ab1 |
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1 +1,4 @@
|
||||
*.png filter=lfs diff=lfs merge=lfs -text
|
||||
*.webp filter=lfs diff=lfs merge=lfs -text
|
||||
*.xcf filter=lfs diff=lfs merge=lfs -text
|
||||
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
||||
|
8
.gitignore
vendored
8
.gitignore
vendored
@ -17,3 +17,11 @@ x64/
|
||||
!sponza.gltf
|
||||
|
||||
imgui.ini
|
||||
libs/physx/physx/include/
|
||||
libs/physx/physx/compiler/
|
||||
libs/physx/physx/buildtools/
|
||||
libs/physx/physx/bin/
|
||||
libs/nativefiledialog/build/
|
||||
.docker
|
||||
|
||||
**/bin/
|
||||
|
27
.gitmodules
vendored
27
.gitmodules
vendored
@ -8,16 +8,13 @@
|
||||
[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
|
||||
[submodule "ImGui"]
|
||||
path = libs/ImGui
|
||||
url = https://github.com/ocornut/imgui.git
|
||||
ignore = dirty
|
||||
[submodule "assimp"]
|
||||
path = libs/assimp
|
||||
url = https://github.com/assimp/assimp.git
|
||||
@ -28,6 +25,28 @@
|
||||
[submodule "libs/physx"]
|
||||
path = libs/physx
|
||||
url = https://git.barink.dev/Nigel/PhysX.git
|
||||
ignore = dirty
|
||||
[submodule "libs/entt"]
|
||||
path = libs/entt
|
||||
url = https://github.com/skypjack/entt.git
|
||||
[submodule "libs/guizmo"]
|
||||
path = libs/guizmo
|
||||
url = https://github.com/CedricGuillemet/ImGuizmo.git
|
||||
ignore = dirty
|
||||
[submodule "libs/yaml-cpp"]
|
||||
path = libs/yaml-cpp
|
||||
url = https://git.barink.dev/Nigel/yaml-cpp.git
|
||||
ignore = dirty
|
||||
[submodule "libs/nativefiledialog"]
|
||||
path = libs/nativefiledialog
|
||||
url = https://git.barink.dev/Nigel/nativefiledialog.git
|
||||
ignore = dirty
|
||||
[submodule "libs/mINI"]
|
||||
path = libs/mINI
|
||||
url = https://github.com/pulzed/mINI.git
|
||||
[submodule "libs/imgui-filebrowser"]
|
||||
path = libs/imgui-filebrowser
|
||||
url = https://github.com/AirGuanZ/imgui-filebrowser.git
|
||||
[submodule "libs/googletest"]
|
||||
path = libs/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
|
@ -1,62 +0,0 @@
|
||||
project "BarinkEngine"
|
||||
kind "StaticLib"
|
||||
|
||||
buildmessage "Building BarinkEngine"
|
||||
|
||||
includedirs {
|
||||
"../libs/spdlog/include",
|
||||
"../libs/glm",
|
||||
|
||||
"../libs/glfw/include",
|
||||
"../libs/glew/include",
|
||||
"../libs/glad/include",
|
||||
|
||||
|
||||
"../libs/assimp/include",
|
||||
"../libs/entt/src",
|
||||
|
||||
"../libs/physx/physx/include",
|
||||
|
||||
"../libs/lua/include",
|
||||
|
||||
"../libs/GorillaAudio/include",
|
||||
"../libs/steam-audio/include",
|
||||
|
||||
|
||||
"../libs/ImGui",
|
||||
}
|
||||
|
||||
links {
|
||||
-- This needs to fall under the filter as the names can differ on different platforms
|
||||
"phonon",
|
||||
"lua54",
|
||||
"spdlog",
|
||||
"assimp-vc143-mtd",
|
||||
"glfw3",
|
||||
"ImGui",
|
||||
}
|
||||
|
||||
|
||||
libdirs {
|
||||
"../libs/steam-audio/lib/windows-x64",
|
||||
"../libs/lua",
|
||||
"../libs/spdlog/build/Release",
|
||||
"../libs/assimp/lib/Debug",
|
||||
"../libs/glfw/build/src/Debug",
|
||||
}
|
||||
|
||||
files {
|
||||
"../libs/glad/src/glad.c",
|
||||
|
||||
"./src/*.cpp",
|
||||
"./src/*.h",
|
||||
"./src/**/*.cpp",
|
||||
"./src/**/*.h"
|
||||
}
|
||||
|
||||
prebuildcommands
|
||||
{
|
||||
ok,err = os.copyfile("BarinkEngine/src/Graphics/shaders/*" ,"SandboxApp/build/Debug/")
|
||||
}
|
||||
|
||||
include('../ImGui')
|
@ -1,99 +0,0 @@
|
||||
#include "ModelImporter.h"
|
||||
#include "spdlog/spdlog.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);
|
||||
|
||||
std::cout << "[DEBUG]: Loaded "<< meshes.size() << " meshes!" << std::endl;
|
||||
|
||||
// create a renderable (per mesh ?? )
|
||||
root->renderable = new Renderable();
|
||||
root->renderable->mesh = new Mesh(meshes[0]);
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
||||
|
||||
#include "../Graphics/Primitives/Mesh.h"
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <string>
|
||||
#include "../Scene/TransformTree/SceneNodeTypes.h"
|
||||
|
||||
|
||||
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
|
||||
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
|
||||
|
||||
namespace BarinkEngine {
|
||||
class ModelImporter {
|
||||
|
||||
public:
|
||||
|
||||
BarinkEngine::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);
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
#include "BarinkEngine.h"
|
||||
|
||||
EngineStatistics ES;
|
||||
BarinkEngine::Renderer renderer;
|
||||
int main(int argc, char* argv[]) {
|
||||
// Setup performance sampler
|
||||
PerfomanceSamplerInit();
|
||||
|
||||
// Startup services
|
||||
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
||||
|
||||
renderer = BarinkEngine::Renderer();
|
||||
InputSystem = BarinkEngine::InputManager();
|
||||
ES = EngineStatistics();
|
||||
|
||||
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();
|
||||
|
||||
GUISystem.Render();
|
||||
|
||||
MainWindow.SwapBuffers();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
// Shutdown game
|
||||
Stop();
|
||||
|
||||
// Shutdown Services
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
#include "glm/glm.hpp"
|
||||
#include "graphics/Primitives/Shader.h"
|
||||
#include "Platform/Window.h"
|
||||
#include "graphics/Primitives/Texture.h"
|
||||
#include "graphics/Primitives/Camera.h"
|
||||
#include "graphics/Renderable.h"
|
||||
#include "Graphics/Renderer.h"
|
||||
#include "Graphics/Primitives/Material.h"
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include "Input/InputManager.h"
|
||||
#include "Graphics/Renderer.h"
|
||||
#include "GUI/GUIManager.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "PerfCounter.h"
|
||||
|
||||
|
||||
extern BarinkEngine::Renderer renderer;
|
||||
extern void Start();
|
||||
extern void Update();
|
||||
extern void ImmediateGraphicsDraw();
|
||||
extern void Stop();
|
@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
struct Event
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
int argc;
|
||||
void** argv;
|
||||
|
||||
};
|
@ -1,25 +0,0 @@
|
||||
#include "EventEmitter.h"
|
||||
|
||||
|
||||
void EventEmitter::Subscribe(EventListener& subscriber)
|
||||
{
|
||||
subscribers.push_back(&subscriber);
|
||||
}
|
||||
|
||||
void EventEmitter::Unsubscribe(EventListener& subscriber)
|
||||
{
|
||||
subscribers.remove(&subscriber);
|
||||
}
|
||||
|
||||
void EventEmitter::EmitEvent(Event& incident)
|
||||
{
|
||||
// Notify all subscribers an event has taken place
|
||||
for (auto it = subscribers.begin(); it != subscribers.end(); ++it)
|
||||
{
|
||||
(*it)->ReceiveEvent(incident);
|
||||
}
|
||||
}
|
||||
|
||||
EventEmitter::EventEmitter() {
|
||||
subscribers = std::list<EventListener*>{};
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include "Event.h"
|
||||
#include "EventListener.h"
|
||||
|
||||
class EventEmitter {
|
||||
public:
|
||||
void Subscribe (EventListener& subscriber);
|
||||
void Unsubscribe(EventListener& subscriber);
|
||||
|
||||
protected:
|
||||
std::list<EventListener*> subscribers;
|
||||
void EmitEvent(Event& incident);
|
||||
|
||||
EventEmitter();
|
||||
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "Event.h"
|
||||
|
||||
class EventListener{
|
||||
public:
|
||||
virtual void ReceiveEvent(Event& incident) = 0 ;
|
||||
|
||||
};
|
@ -1,53 +0,0 @@
|
||||
#include "GUIManager.h"
|
||||
#include "imgui.h"
|
||||
#include "backends/imgui_impl_opengl3.h"
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include "../BarinkEngine.h"
|
||||
|
||||
GUIManager::GUIManager(BarinkWindow* window)
|
||||
: currentwindow(window)
|
||||
{
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(currentwindow->windowptr(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 440");
|
||||
|
||||
|
||||
}
|
||||
|
||||
GUIManager::~GUIManager()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void GUIManager::Render()
|
||||
{
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::Begin("##App");
|
||||
|
||||
ImmediateGraphicsDraw();
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
GLFWwindow* last_context = glfwGetCurrentContext();
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
glfwMakeContextCurrent(last_context);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include "../Platform/Window.h"
|
||||
|
||||
|
||||
class GUIManager {
|
||||
public:
|
||||
GUIManager(BarinkWindow* window);
|
||||
~GUIManager();
|
||||
|
||||
void Render();
|
||||
|
||||
|
||||
private:
|
||||
BarinkWindow* currentwindow;
|
||||
};
|
@ -1,47 +0,0 @@
|
||||
#include "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,19 +0,0 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
class GpuBuffer {
|
||||
private:
|
||||
unsigned int id;
|
||||
public:
|
||||
|
||||
int getBufferID();
|
||||
|
||||
void createBuffer();
|
||||
|
||||
void setBufferData(void* data, size_t dataSize, bool elementBuffer );
|
||||
|
||||
void Bind(bool elementBuffer);
|
||||
void Unbind(bool elementBuffer);
|
||||
|
||||
void Delete();
|
||||
|
||||
};
|
@ -1,49 +0,0 @@
|
||||
#include "Framebuffer.h"
|
||||
#include <iostream>
|
||||
|
||||
Framebuffer::Framebuffer()
|
||||
{
|
||||
glGenFramebuffers(1, &Id);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, Id);
|
||||
|
||||
// Create a colour texture!
|
||||
glGenTextures(1, &ColourAttachment);
|
||||
glBindTexture(GL_TEXTURE_2D, ColourAttachment);
|
||||
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColourAttachment, 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
// Create a depth buffer
|
||||
glGenRenderbuffers(1, &DepthAttachment);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, DepthAttachment);
|
||||
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
|
||||
|
||||
glFramebufferRenderbuffer(GL_RENDERBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthAttachment);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
|
||||
|
||||
if (!glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
std::cout << "Framebuffer is incomplete!" << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << "Framebuffer is complete!" << std::endl;
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
Framebuffer::~Framebuffer()
|
||||
{
|
||||
glDeleteTextures(1, &ColourAttachment);
|
||||
glDeleteRenderbuffers(1, &DepthAttachment);
|
||||
glDeleteFramebuffers(1, &Id);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Framebuffer {
|
||||
|
||||
public:
|
||||
Framebuffer();
|
||||
~Framebuffer();
|
||||
|
||||
unsigned int GetId() { return Id; }
|
||||
unsigned int GetColourAttachment() { return ColourAttachment; }
|
||||
|
||||
private:
|
||||
unsigned int Id = 0;
|
||||
unsigned int ColourAttachment = 0;
|
||||
unsigned int DepthAttachment = 0;
|
||||
|
||||
|
||||
};
|
@ -1,25 +0,0 @@
|
||||
#include "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,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class VertexArray{
|
||||
private:
|
||||
unsigned int id;
|
||||
|
||||
|
||||
public:
|
||||
void Create();
|
||||
void Bind();
|
||||
void Unbind();
|
||||
|
||||
unsigned int getID() { return id; }
|
||||
|
||||
void Delete();
|
||||
|
||||
void AttachAttribute(unsigned int index, int size, int stride);
|
||||
|
||||
|
||||
};
|
@ -1,22 +0,0 @@
|
||||
#include "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
|
||||
);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
glm::vec3 Position;
|
||||
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;
|
||||
glm::vec3 Up;
|
||||
|
||||
};
|
@ -1,11 +0,0 @@
|
||||
#include "Material.h"
|
||||
|
||||
Material::Material(const Shader& shader) :
|
||||
shader(shader) {
|
||||
}
|
||||
|
||||
void Material::Apply() const {
|
||||
|
||||
shader.Use();
|
||||
shader.setUniformVec3("Color", Color);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
#include "Shader.h"
|
||||
|
||||
class Material {
|
||||
public:
|
||||
Material(const Shader& shader);
|
||||
|
||||
void Apply()const;
|
||||
glm::vec3 Color;
|
||||
const Shader& shader;
|
||||
|
||||
};
|
@ -1,129 +0,0 @@
|
||||
#include "Shader.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
|
||||
{
|
||||
char infoLog[512];
|
||||
int succes;
|
||||
|
||||
char* vertexCode = readFile(vertexShaderPath.c_str());
|
||||
//spdlog::info(vertexCode);
|
||||
unsigned int vertId = glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
glShaderSource(vertId, 1, &vertexCode, NULL);
|
||||
glCompileShader(vertId);
|
||||
|
||||
glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes);
|
||||
if(!succes){
|
||||
glGetShaderInfoLog(vertId, 512, NULL, infoLog);
|
||||
spdlog::error( "Vertex shader has compile error {}", infoLog);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char* fragmentCode = readFile(fragmentShaderPath.c_str());
|
||||
//spdlog::info(fragmentCode);
|
||||
unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
|
||||
|
||||
glShaderSource(fragId, 1, &fragmentCode, NULL);
|
||||
glCompileShader(fragId);
|
||||
|
||||
|
||||
glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes);
|
||||
if(!succes){
|
||||
glGetShaderInfoLog(fragId, 512, NULL, infoLog);
|
||||
spdlog::error("Fragment shader has compile error {}", infoLog);
|
||||
return;
|
||||
}
|
||||
|
||||
id = glCreateProgram();
|
||||
|
||||
glAttachShader(id, vertId);
|
||||
glAttachShader(id, fragId);
|
||||
glLinkProgram(id);
|
||||
|
||||
|
||||
int success;
|
||||
glGetProgramiv(id, GL_LINK_STATUS, &success);
|
||||
if(!success) {
|
||||
glGetProgramInfoLog(id, 512, NULL, infoLog);
|
||||
printf("ERROR::SHADER_PROGRAM::LINKING_FAILED\n %s", infoLog);
|
||||
}
|
||||
|
||||
|
||||
delete vertexCode;
|
||||
delete fragmentCode;
|
||||
|
||||
|
||||
}
|
||||
|
||||
char* Shader::readFile (const char* filePath){
|
||||
|
||||
spdlog::info("Opening {} ", filePath);
|
||||
|
||||
|
||||
std::ifstream file ;
|
||||
file.open(filePath);
|
||||
|
||||
if(file.is_open() == false){
|
||||
spdlog::info("File not found.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
// Determine the file size!
|
||||
file.seekg(0, std::ios::end);
|
||||
size_t filesize = file.tellg();
|
||||
|
||||
// Undo previous seek.
|
||||
file.seekg(0, std::ios::beg);
|
||||
//spdlog::info("filesize: {}", filesize);
|
||||
|
||||
|
||||
// Create a big enough buffer for the file
|
||||
|
||||
size_t bufferSize = filesize + 3;
|
||||
char* FileBuffer = new char[bufferSize];
|
||||
|
||||
memset(FileBuffer, '\0', bufferSize);
|
||||
|
||||
// read the whole file
|
||||
file.read(FileBuffer, filesize);
|
||||
|
||||
return FileBuffer;
|
||||
}
|
||||
|
||||
void Shader::Use() const
|
||||
{
|
||||
glUseProgram(id);
|
||||
}
|
||||
|
||||
|
||||
void Shader::setUniformMat4(std::string uniformName, glm::mat4 matrix4) const
|
||||
{
|
||||
glUniformMatrix4fv(glGetUniformLocation(id, uniformName.c_str()), 1, GL_FALSE, glm::value_ptr(matrix4));
|
||||
}
|
||||
void Shader::setUniformVec4(std::string uniformName, glm::vec4 vector4) const
|
||||
{
|
||||
glUniform4fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector4));
|
||||
}
|
||||
void Shader::setUniformVec3(std::string uniformName, glm::vec3 vector3) const
|
||||
{
|
||||
glUniform3fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector3));
|
||||
}
|
||||
void Shader::setUniformVec2(std::string uniformName, glm::vec2 vector2) const
|
||||
{
|
||||
glUniform2fv(glGetUniformLocation(id, uniformName.c_str()),1, glm::value_ptr(vector2));
|
||||
}
|
||||
|
||||
void Shader::setUniformFloat(std::string uniformName, float value) const
|
||||
{
|
||||
glUniform1f(glGetUniformLocation(id, uniformName.c_str()), value);
|
||||
}
|
||||
|
||||
void Shader::setUniformInt(std::string uniformName, int value) const
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(id, uniformName.c_str()), value);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
|
||||
class Shader {
|
||||
private:
|
||||
|
||||
char* readFile (const char* filePath);
|
||||
public:
|
||||
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
||||
void Use() const;
|
||||
void setUniformMat4(std::string uniformName, glm::mat4 matrix4)const;
|
||||
void setUniformVec4(std::string uniformName, glm::vec4 vector4)const;
|
||||
void setUniformVec3(std::string uniformName, glm::vec3 vector3)const;
|
||||
void setUniformVec2(std::string uniformName, glm::vec2 vector2)const;
|
||||
void setUniformFloat(std::string uniformName, float value)const;
|
||||
void setUniformInt(std::string uniformName, int value) const ;
|
||||
|
||||
int id;
|
||||
|
||||
};
|
@ -1,40 +0,0 @@
|
||||
#include "Texture.h"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "../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,18 +0,0 @@
|
||||
#pragma once
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
class Texture {
|
||||
public:
|
||||
Texture(const std::string texturePath);
|
||||
|
||||
void Bind();
|
||||
void Unbind();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
unsigned int Id;
|
||||
|
||||
};
|
@ -1,46 +0,0 @@
|
||||
#include "RenderSurface.h";
|
||||
|
||||
RenderSurface::RenderSurface(){
|
||||
shader = new Shader("build/SandboxAppliction/Debug/renderSuface.vs", "build/SandboxApplication/Debug/renderSurface.fs");
|
||||
|
||||
|
||||
|
||||
verts = std::vector<glm::vec3>{
|
||||
{-0.5f, 0.5f, 0.0f}, // 0
|
||||
{-0.5f, -0.5f, 0.0f}, // 1
|
||||
{0.5f, -0.5f, 0.0f}, // 2
|
||||
{0.5f, 0.5f, 0.0f}, // 3
|
||||
};
|
||||
|
||||
indices = std::vector<unsigned int>{
|
||||
0,2,1,
|
||||
0,3,2
|
||||
};
|
||||
|
||||
VAO.Create();
|
||||
VAO.Bind();
|
||||
|
||||
vertexBuffer.createBuffer();
|
||||
vertexBuffer.Bind(false);
|
||||
vertexBuffer.setBufferData(&verts[0], verts.size() * sizeof(glm::vec3), false);
|
||||
|
||||
elementBuffer.createBuffer();
|
||||
elementBuffer.Bind(true);
|
||||
elementBuffer.setBufferData(&indices[0], indices.size() * sizeof(unsigned int), true);
|
||||
|
||||
VAO.AttachAttribute(0, 3, 0);
|
||||
|
||||
vertexBuffer.Unbind(false);
|
||||
VAO.Unbind();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
RenderSurface::~RenderSurface() {
|
||||
delete shader;
|
||||
}
|
||||
|
||||
void RenderSurface::Draw() {
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
#include "../BarinkEngine.h"
|
||||
#include <vector>
|
||||
class RenderSurface
|
||||
{
|
||||
public:
|
||||
RenderSurface();
|
||||
~RenderSurface();
|
||||
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
// would normally be a material
|
||||
// however rendersurface is special and
|
||||
// thus does not contain a material
|
||||
Shader* shader;
|
||||
|
||||
// Basically a mesh
|
||||
std::vector<glm::vec3> verts;
|
||||
std::vector<unsigned int > indices;
|
||||
|
||||
|
||||
GpuBuffer vertexBuffer;
|
||||
GpuBuffer elementBuffer;
|
||||
|
||||
VertexArray VAO;
|
||||
|
||||
|
||||
|
||||
};
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include "Primitives/Mesh.h"
|
||||
#include "Primitives/Material.h"
|
||||
#include "Primitives/Texture.h"
|
||||
#include "../Scene/Scene.h"
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
struct Renderable {
|
||||
BarinkEngine::Mesh* mesh;
|
||||
Material* material;
|
||||
Texture* texture;
|
||||
};
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
#include "Renderer.h"
|
||||
#include "../Scene/Components.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
float Angle = 0.0;
|
||||
Camera cam = Camera(glm::vec3(16.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
||||
glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
||||
|
||||
BarinkEngine::Renderer::Renderer(){}
|
||||
|
||||
BarinkEngine::Renderer::~Renderer(){}
|
||||
|
||||
void BarinkEngine::Renderer::Prepare(Scene& scene ) {
|
||||
auto group = scene.getReg().view<BarinkEngine::Render3DComponent>();
|
||||
group.each([](auto enity, BarinkEngine::Render3DComponent& renderComponent) {
|
||||
VertexArray va = VertexArray();
|
||||
GpuBuffer vertexBuffer = GpuBuffer();
|
||||
GpuBuffer elementBuffer = GpuBuffer();
|
||||
|
||||
va.Create();
|
||||
va.Bind();
|
||||
|
||||
vertexBuffer.createBuffer();
|
||||
vertexBuffer.Bind(false);
|
||||
vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
||||
|
||||
elementBuffer.createBuffer();
|
||||
elementBuffer.Bind(true);
|
||||
elementBuffer.setBufferData((void*)&renderComponent.mesh.elements[0], renderComponent.mesh.elements.size() * sizeof(unsigned int), true);
|
||||
|
||||
va.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
|
||||
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
va.Unbind();
|
||||
vertexBuffer.Unbind(false);
|
||||
elementBuffer.Unbind(true);
|
||||
|
||||
renderComponent.VAO = va.getID();
|
||||
renderComponent.IBO = elementBuffer.getBufferID();
|
||||
});
|
||||
}
|
||||
|
||||
void BarinkEngine::Renderer::Render(Scene& scene)
|
||||
{
|
||||
auto group = scene.getReg().view<TransformComponent, Render3DComponent>();
|
||||
group.each([](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
|
||||
{
|
||||
|
||||
glBindVertexArray(renderComponent.VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderComponent.IBO);
|
||||
|
||||
renderComponent.shader.Use();
|
||||
|
||||
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
|
||||
|
||||
renderComponent.shader.setUniformMat4("M", glm::mat4(1.0f));
|
||||
renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix());
|
||||
renderComponent.shader.setUniformMat4("P", projection);
|
||||
|
||||
|
||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(renderComponent.mesh.elements.size()) ,
|
||||
GL_UNSIGNED_INT, NULL);
|
||||
|
||||
glBindVertexArray(0);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void Render(Framebuffer& framebuffer)
|
||||
{}
|
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include "glad/glad.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include "../PerfCounter.h"
|
||||
|
||||
#include "Primitives/Camera.h"
|
||||
#include "Renderable.h"
|
||||
#include "GPUBucket.h"
|
||||
#include "Memory/Framebuffer.h"
|
||||
#include "../Scene/Components.h"
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
void Prepare(Scene& scene);
|
||||
void Render(Scene& scene );
|
||||
|
||||
void Render(Framebuffer& framebuffer);
|
||||
};
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
#include "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*>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "../EventSystem/EventEmitter.h"
|
||||
#include "../EventSystem/EventListener.h"
|
||||
#include "../Platform/Window.h"
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
class InputManager : EventEmitter {
|
||||
public:
|
||||
InputManager();
|
||||
|
||||
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);
|
||||
static void CursorEnterCallback(GLFWwindow* window, int entered);
|
||||
static void MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||
static void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
private:
|
||||
std::vector<BarinkWindow*> windows;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
extern BarinkEngine::InputManager InputSystem;
|
@ -1,52 +0,0 @@
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
#include <imgui.h>
|
||||
|
||||
struct EngineStatistics {
|
||||
float frameTime;
|
||||
uint32_t verts;
|
||||
uint32_t DC;
|
||||
|
||||
long long lastSampleTime;
|
||||
long long frames;
|
||||
long long FPS;
|
||||
};
|
||||
extern EngineStatistics ES;
|
||||
|
||||
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 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;
|
||||
ES.FPS = ES.frames;
|
||||
ES.frames = 0;
|
||||
ES.lastSampleTime = now;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void ShowStats() {
|
||||
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||
|
||||
ImGui::Text("FPS: %i", ES.FPS);
|
||||
ImGui::Text("Frame Time: %f", ES.frameTime);
|
||||
ImGui::Text("Verts: %i", ES.verts);
|
||||
ImGui::Text("Draw Calls: %i", ES.DC);
|
||||
|
||||
|
||||
ImGui::End();
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
#include "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);
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
|
||||
// No window decorations such as a border, a close widget
|
||||
// glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
||||
// glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
|
||||
// Disable resizing the window
|
||||
//glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
|
||||
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,37 +0,0 @@
|
||||
#pragma once
|
||||
#define GLFW_STATIC
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "../EventSystem/Event.h"
|
||||
#include "../EventSystem/EventListener.h"
|
||||
|
||||
class BarinkWindow : EventListener {
|
||||
private:
|
||||
GLFWwindow* window;
|
||||
bool FullScreen;
|
||||
bool VulkanSupported;
|
||||
int Width, Height;
|
||||
|
||||
static bool InitGLFW();
|
||||
|
||||
public:
|
||||
BarinkWindow(const int width, const int height);
|
||||
~BarinkWindow();
|
||||
|
||||
GLFWwindow* windowptr();
|
||||
|
||||
void ReceiveEvent(Event& incident) override ;
|
||||
bool WindowShouldClose();
|
||||
|
||||
void Poll();
|
||||
void SwapBuffers();
|
||||
|
||||
|
||||
};
|
@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
#include "../Graphics/Primitives/Shader.h"
|
||||
#include "../Graphics/Primitives/Mesh.h"
|
||||
namespace BarinkEngine {
|
||||
struct IdentifierComponent {
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct TransformComponent {
|
||||
glm::mat4& transform = glm::mat4(1.0f);
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct CameraComponent {
|
||||
glm::mat4& view;
|
||||
|
||||
};
|
||||
|
||||
struct Render3DComponent {
|
||||
unsigned int VAO = 0;
|
||||
unsigned int IBO = 0;
|
||||
Mesh mesh;
|
||||
|
||||
// TODO: becomes a material
|
||||
glm::vec3 color;
|
||||
Shader shader;
|
||||
|
||||
Render3DComponent()
|
||||
: shader(Shader("build/Debug/test.vs", "build/Debug/test.fs")),
|
||||
color(glm::vec3(1.0f, 0.0f, 0.0f))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct Render2DComponent {
|
||||
glm::vec3 Colour;
|
||||
|
||||
};
|
||||
};
|
@ -1,7 +0,0 @@
|
||||
#include "Entity.h"
|
||||
|
||||
Entity::Entity(entt::entity e, Scene* scene)
|
||||
: m_entity(e), m_scene(scene)
|
||||
{
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
#include <entt/entt.hpp>
|
||||
class Scene;
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity() = default;
|
||||
Entity(entt::entity e, Scene* scene);
|
||||
Entity(const Entity& other) = default;
|
||||
|
||||
|
||||
template<class T >
|
||||
T& AddComponent() {
|
||||
return m_scene->m_registry.emplace<T>(m_entity);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* GetComponent() {
|
||||
return m_scene->m_registry.try_get<T>(m_entity);
|
||||
}
|
||||
|
||||
private:
|
||||
entt::entity m_entity;
|
||||
Scene* m_scene;
|
||||
|
||||
};
|
||||
|
@ -1,21 +0,0 @@
|
||||
#include "Scene.h"
|
||||
#include "Entity.h"
|
||||
#include "Components.h"
|
||||
Scene::Scene()
|
||||
{
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
{}
|
||||
|
||||
Entity Scene::AddEntity(std::string& name)
|
||||
{
|
||||
Entity entity = { m_registry.create(), this };
|
||||
|
||||
entity.AddComponent<BarinkEngine::IdentifierComponent>();
|
||||
entity.AddComponent<BarinkEngine::TransformComponent>();
|
||||
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <entt/entt.hpp>
|
||||
class Entity;
|
||||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
|
||||
Entity AddEntity(std::string& name);
|
||||
|
||||
entt::registry& getReg() { return m_registry; }
|
||||
|
||||
private:
|
||||
entt::registry m_registry;
|
||||
|
||||
friend class Entity;
|
||||
};
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
#include "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()) {}
|
@ -1,24 +0,0 @@
|
||||
#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;
|
||||
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
#include "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,22 +0,0 @@
|
||||
#pragma once
|
||||
#include "../../Graphics/Primitives/Camera.h"
|
||||
#include "../../Graphics/Renderable.h"
|
||||
#include "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,11 +0,0 @@
|
||||
#include "LuaScript.h"
|
||||
/*
|
||||
LuaScript::LuaScript(const std::string& path)
|
||||
: filePath(path) {
|
||||
}
|
||||
|
||||
void LuaScript::execute(lua_State& l)
|
||||
{
|
||||
luaL_dofile(&l, filePath.c_str());
|
||||
}
|
||||
*/
|
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "lauxlib.h"
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
|
||||
#include "LuaScriptingManager.h"
|
||||
|
||||
|
||||
/*
|
||||
class LuaScript {
|
||||
public:
|
||||
|
||||
LuaScript(const std::string&);
|
||||
void execute(lua_State& l);
|
||||
|
||||
private:
|
||||
std::string filePath;
|
||||
|
||||
};
|
||||
|
||||
|
||||
*/
|
@ -1,18 +0,0 @@
|
||||
#include "LuaScriptingManager.h"
|
||||
/*
|
||||
LuaScriptingManager::LuaScriptingManager()
|
||||
{
|
||||
L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
}
|
||||
|
||||
|
||||
void LuaScriptingManager::ExecuteLuaString(const std::string& code) {
|
||||
luaL_dostring(L, code.c_str());
|
||||
}
|
||||
|
||||
lua_State& LuaScriptingManager::getState()
|
||||
{
|
||||
return (*L);
|
||||
}
|
||||
*/
|
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "lauxlib.h"
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
|
||||
#include "LuaScript.h"
|
||||
|
||||
/*
|
||||
class LuaScriptingManager
|
||||
{
|
||||
public:
|
||||
std::vector<LuaScript*> scripts;
|
||||
|
||||
LuaScriptingManager();
|
||||
|
||||
void ExecuteLuaString(const std::string&);
|
||||
|
||||
private:
|
||||
lua_State* L;
|
||||
|
||||
lua_State& getState();
|
||||
};*/
|
21
CmakeLists.txt
Normal file
21
CmakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 4.0)
|
||||
project(Yoggie)
|
||||
set(EXPORT_COMPILE_COMMANDS_JSON ON)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4099")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wclass-struct-conversion")
|
||||
endif()
|
||||
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
add_compile_definitions(GLFW_STATIC)
|
||||
|
||||
add_subdirectory(Editor)
|
||||
add_subdirectory(SandboxApp)
|
||||
include(libraries.cmake)
|
||||
add_subdirectory(YoggieEngine)
|
||||
|
||||
|
23
DEVELOPMENT.md
Normal file
23
DEVELOPMENT.md
Normal file
@ -0,0 +1,23 @@
|
||||
## Requirements
|
||||
*_NOTE:_ Right now the build proces of some third party libraries have not been converted and may need special tooling*
|
||||
|
||||
#### Software
|
||||
* Premake
|
||||
* Git
|
||||
* C++ Compiler
|
||||
|
||||
## Windows development workflow
|
||||
User premake to generate project files for the approperiate build method.
|
||||
On Windows I assume you'll build with visual studio
|
||||
|
||||
```bash
|
||||
User:~$ premake vs2022
|
||||
```
|
||||
|
||||
## Linux development workflow
|
||||
Use premake to generate project files for the approperiate build method.
|
||||
On Linux I assume you'll build with something like make.
|
||||
|
||||
```bash
|
||||
User@Machine:~$ premake gmake2
|
||||
```
|
1
Editor/.gitignore
vendored
Normal file
1
Editor/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
**.dll
|
17
Editor/CMakeLists.txt
Normal file
17
Editor/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
file(GLOB SOURCE_FILES "src/*.cpp")
|
||||
file(GLOB HEADER_FILES "src/*.h")
|
||||
add_executable(Editor ${SOURCE_FILES} "../libs/glad/src/glad.c" ${HEADER_FILES})
|
||||
|
||||
target_include_directories(Editor PRIVATE
|
||||
"../YoggieEngine/src"
|
||||
"../libs/guizmo"
|
||||
)
|
||||
target_link_directories(Editor PRIVATE
|
||||
"../libs/ImGui/build/Release"
|
||||
"../libs/guizmo/build/Release" )
|
||||
target_link_libraries(Editor
|
||||
thirdparty_tools
|
||||
YoggieEngine
|
||||
ImGui
|
||||
ImGuizmo
|
||||
)
|
@ -1,40 +0,0 @@
|
||||
project "Editor"
|
||||
kind "ConsoleApp"
|
||||
|
||||
buildmessage "Building editor ..."
|
||||
|
||||
links{
|
||||
"BarinkEngine"
|
||||
}
|
||||
|
||||
includedirs{
|
||||
"./../BarinkEngine/Include",
|
||||
|
||||
-- I'd prefer if didn't need these..
|
||||
-- We'll figure that out some time later
|
||||
"./../libs/lua/include",
|
||||
"./../libs/spdlog/include",
|
||||
"./../libs/glm",
|
||||
"./../libs/GorillaAudio/include",
|
||||
|
||||
"./../libs/assimp/include",
|
||||
"./../libs/glad/include",
|
||||
"./../libs/glfw/include",
|
||||
"./../libs/tinygltf",
|
||||
"./../libs/glew/include",
|
||||
"./../libs/glm",
|
||||
"./../libs/ImGui",
|
||||
|
||||
|
||||
"./include"
|
||||
|
||||
}
|
||||
|
||||
libdirs {
|
||||
'./../build/BarinkEngine/Debug'
|
||||
}
|
||||
|
||||
files {
|
||||
"./include/*.h",
|
||||
"./src/*.cpp"
|
||||
}
|
BIN
Editor/rsc/AssetIcon.png
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/AssetIcon.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Editor/rsc/AssetIcon.xcf
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/AssetIcon.xcf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Editor/rsc/FodlerIcon.xcf
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/FodlerIcon.xcf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Editor/rsc/FolderIcon.png
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/FolderIcon.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Editor/rsc/Yoggie.png
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/Yoggie.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Editor/rsc/Yoggie2.jpeg
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/Yoggie2.jpeg
(Stored with Git LFS)
Normal file
Binary file not shown.
38
Editor/src/Console.cpp
Normal file
38
Editor/src/Console.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "Console.h"
|
||||
#include <stdio.h>
|
||||
|
||||
Console::Console()
|
||||
: EditorWindow("Console"), Items(ImVector<char*>()), AutoScroll(false), ScrollToBottom(false)
|
||||
{
|
||||
AddLog("Hello Editor console!");
|
||||
}
|
||||
|
||||
Console::~Console() {
|
||||
|
||||
}
|
||||
|
||||
void Console::Show() {
|
||||
Draw();
|
||||
}
|
||||
|
||||
void Console::Draw() {
|
||||
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
|
||||
|
||||
|
||||
for (int i = 0; i < Items.Size; i++)
|
||||
{
|
||||
const char* item = Items[i];
|
||||
ImGui::TextUnformatted(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Console::AddLog(const char* fmt, ...) {
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
|
||||
buf[IM_ARRAYSIZE(buf) - 1] = 0;
|
||||
va_end(args);
|
||||
Items.push_back(strdup(buf));
|
||||
}
|
22
Editor/src/Console.h
Normal file
22
Editor/src/Console.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||
#include "EditorWindow.h"
|
||||
#include <imgui.h>
|
||||
|
||||
class Console : public EditorWindow {
|
||||
public:
|
||||
|
||||
Console();
|
||||
~Console();
|
||||
|
||||
void Draw() override;
|
||||
|
||||
void Show();
|
||||
|
||||
void AddLog(const char* fmt, ...);
|
||||
|
||||
private:
|
||||
ImVector<char*> Items;
|
||||
bool AutoScroll;
|
||||
bool ScrollToBottom;
|
||||
};
|
72
Editor/src/Dialog.h
Normal file
72
Editor/src/Dialog.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <imgui.h>
|
||||
#include <nfd.h>
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include "Project/Project.h"
|
||||
struct DialogSpec {
|
||||
const std::string& id;
|
||||
const std::string& Title;
|
||||
const std::string& confirmText;
|
||||
DialogSpec() = default;
|
||||
};
|
||||
|
||||
//classes based on RAII
|
||||
class Dialog {
|
||||
public:
|
||||
Dialog( DialogSpec spec, std::function<void(std::string&)> onConfirm)
|
||||
: path(nullptr), location() {
|
||||
if (ImGui::BeginPopupModal(spec.id.c_str(), NULL, ImGuiWindowFlags_NoMove))
|
||||
{
|
||||
ImGui::Text(spec.Title.c_str());
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::LabelText("##Directory", "Directory: %s", location.c_str());
|
||||
if (ImGui::Button("...")) {
|
||||
nfdresult_t result = NFD_OpenDialog(NULL, NULL, &path);
|
||||
|
||||
switch (result) {
|
||||
case (NFD_OKAY):
|
||||
location = std::string(path);
|
||||
break;
|
||||
case(NFD_CANCEL):
|
||||
spdlog::info("NFD_CANCEL" );
|
||||
case (NFD_ERROR):
|
||||
spdlog::error("NFD_Error: {0}" , NFD_GetError() );
|
||||
break;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (ImGui::Button(spec.confirmText.c_str(), ImVec2(120, 0)))
|
||||
{
|
||||
onConfirm(location);
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
ImGui::SetItemDefaultFocus();
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("Cancel", ImVec2(120, 0)))
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
~Dialog() {
|
||||
delete path;
|
||||
}
|
||||
|
||||
protected :
|
||||
char* path;
|
||||
std::string location;
|
||||
};
|
||||
|
||||
|
19
Editor/src/EditorCamera.h
Normal file
19
Editor/src/EditorCamera.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||
|
||||
class EditorCamera : public YoggieEngine::Camera {
|
||||
public:
|
||||
EditorCamera () : Camera(){
|
||||
Front = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
Right = glm::vec3(-1.0f, 0.0f, 0.0f);
|
||||
Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
glm::vec3 Front;
|
||||
glm::vec3 Right;
|
||||
glm::vec3 Up;
|
||||
};
|
517
Editor/src/EditorLayer.h
Normal file
517
Editor/src/EditorLayer.h
Normal file
@ -0,0 +1,517 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <mini/ini.h>
|
||||
#include <nfd.h>
|
||||
#include <ImGuizmo.h>
|
||||
#include <memory>
|
||||
|
||||
#include "Inspector.h"
|
||||
#include "Console.h"
|
||||
#include "IconsMaterialDesign.h"
|
||||
#include "Project.h"
|
||||
#include "EditorCamera.h"
|
||||
using namespace YoggieEngine;
|
||||
|
||||
|
||||
class EditorLayer : public Layer {
|
||||
|
||||
|
||||
public:
|
||||
EditorLayer() : Layer()
|
||||
{
|
||||
|
||||
Logo.Load("rsc/Yoggie.png");
|
||||
Selected = YoggieEngine::Entity{ (entt::entity)-1, (scene.get()) };
|
||||
|
||||
}
|
||||
|
||||
void OnStartup() override {
|
||||
std::string path = (std::filesystem::current_path()).string();
|
||||
scene = std::make_unique<Scene>();
|
||||
project = std::make_unique<Project>();
|
||||
project.get()->setProjectDirectory(path);
|
||||
LoadLastOrEmptyProject();
|
||||
//Console console = Console();
|
||||
|
||||
}
|
||||
|
||||
void OnUpdate() override {
|
||||
scene.get()->Update();
|
||||
renderer.get()->Render(*scene, *camera);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OnUI() override {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { ImGui::GetWindowWidth(), 7 });
|
||||
ImGui::BeginMainMenuBar();
|
||||
int scaleFactor = 30;
|
||||
ImGui::Image((ImTextureID)Logo.GetID(), { Logo.getSize().x / scaleFactor , Logo.getSize().y / scaleFactor });
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (ImGui::BeginMenu("App")) {
|
||||
|
||||
if (ImGui::MenuItem("Load Project"))
|
||||
{
|
||||
nfdresult_t result = NFD_OpenDialog({ "yproj" }, NULL, &path);
|
||||
switch (result) {
|
||||
case(NFD_OKAY):
|
||||
//Project::LoadProject(path, project);
|
||||
//AssetRegistry::setAssetPath(project.GetProjectDirectory());
|
||||
//AssetRegistry::BuildAssetView();
|
||||
break;
|
||||
case(NFD_CANCEL):
|
||||
break;
|
||||
case(NFD_ERROR):
|
||||
spdlog::error("NFD_Error: {0}", NFD_GetError());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Save project as...")) {
|
||||
nfdresult_t result = NFD_SaveDialog({ "yproj" }, NULL, &path);
|
||||
switch (result) {
|
||||
case(NFD_OKAY):
|
||||
spdlog::info("Save as: {0}", path);
|
||||
//Project::SaveProject(path, project);
|
||||
break;
|
||||
case(NFD_CANCEL):
|
||||
break;
|
||||
case(NFD_ERROR):
|
||||
spdlog::error("NFD_Error: {0}", NFD_GetError());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Scene")) {
|
||||
|
||||
if (ImGui::MenuItem("Save scene"))
|
||||
{
|
||||
nfdresult_t result = NFD_SaveDialog({ "yscene" }, NULL, &path);
|
||||
switch (result) {
|
||||
case(NFD_OKAY):
|
||||
//SaveScene(path, scene);
|
||||
|
||||
//project.AddScene(scene);
|
||||
|
||||
break;
|
||||
case(NFD_CANCEL):
|
||||
break;
|
||||
case(NFD_ERROR):
|
||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Load scene"))
|
||||
{
|
||||
auto result = NFD_OpenDialog({ "yscene" }, NULL, &path);
|
||||
switch (result) {
|
||||
case (NFD_OKAY):
|
||||
//LoadScene(path, scene);
|
||||
break;
|
||||
case(NFD_CANCEL):
|
||||
break;
|
||||
case(NFD_ERROR):
|
||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Add Entity"))
|
||||
{
|
||||
//scene.AddEntity("New Entity");
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Import Model"))
|
||||
{
|
||||
auto result = NFD_OpenDialog("obj,fbx,gltf", NULL, &path);
|
||||
switch (result) {
|
||||
case(NFD_OKAY):
|
||||
// Import Model
|
||||
/*
|
||||
AssetRegistry::LoadFromSource(
|
||||
path,
|
||||
"build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets"
|
||||
);
|
||||
*/
|
||||
|
||||
break;
|
||||
case(NFD_CANCEL):
|
||||
break;
|
||||
case(NFD_ERROR):
|
||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Import MeshAsset (temp)"))
|
||||
{
|
||||
auto result = NFD_OpenDialog("mesh", NULL, &path);
|
||||
|
||||
switch (result) {
|
||||
case(NFD_OKAY):
|
||||
{
|
||||
}
|
||||
break;
|
||||
|
||||
case(NFD_CANCEL):
|
||||
spdlog::debug("User cancelled action");
|
||||
break;
|
||||
case(NFD_ERROR):
|
||||
spdlog::warn("Something went wrong!");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() / 4 * 3);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
ImGui::Button(ICON_MD_ROCKET_LAUNCH "Project");
|
||||
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - 120);
|
||||
|
||||
ImGui::PopStyleColor(1);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
|
||||
|
||||
ImGui::Begin("RuntimeControls");
|
||||
|
||||
ImGui::BeginGroup();
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(ICON_MD_TRANSFORM);
|
||||
|
||||
auto spacing = 10;
|
||||
float buttonWidth = 75.0f;
|
||||
float buttonHeight = 30;
|
||||
float ColorIntensity = 0.5f;
|
||||
float ColorIntensityHovered = 0.75;
|
||||
float ColorIntensityActive = 0.85;
|
||||
float yPadding = 6.f;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{0, yPadding });
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.0f,ColorIntensity ,0.0f ,1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.0f,ColorIntensityHovered ,0.0f ,1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.0f,ColorIntensityActive ,0.0f ,1.0f });
|
||||
ImGui::SameLine(0, spacing);
|
||||
if (ImGui::Button("Translate", { buttonWidth,buttonHeight }))
|
||||
activeOperation = ImGuizmo::OPERATION::TRANSLATE;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 0, yPadding });
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ ColorIntensity, 0.0f ,0.0f ,1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ ColorIntensityHovered, 0.0f ,0.0f ,1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ ColorIntensityActive, 0.0f ,0.0f ,1.0f });
|
||||
ImGui::SameLine(0, spacing);
|
||||
if (ImGui::Button("Rotate", { buttonWidth,buttonHeight }))
|
||||
activeOperation = ImGuizmo::OPERATION::ROTATE;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 0, yPadding });
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.0f, 0.0f ,ColorIntensity ,1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.0f, 0.0f ,ColorIntensityHovered ,1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.0f, 0.0f ,ColorIntensityActive ,1.0f });
|
||||
ImGui::SameLine(0, spacing);
|
||||
if (ImGui::Button("Scale", { buttonWidth,buttonHeight }))
|
||||
activeOperation = ImGuizmo::OPERATION::SCALE;
|
||||
|
||||
ImGui::PopStyleColor(9);
|
||||
ImGui::PopStyleVar(3);
|
||||
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::SameLine((ImGui::GetWindowContentRegionMax().x / 2) - (90));
|
||||
auto color = ImVec4{ 0.001 * 12 , 0.001 * 201 , 0.001 * 69, 1.0f };
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
||||
const float strengthIncrease = 1.5f;
|
||||
ImGui::PushStyleColor(
|
||||
ImGuiCol_ButtonHovered,
|
||||
ImVec4{
|
||||
color.x * strengthIncrease,
|
||||
color.y * strengthIncrease,
|
||||
color.z * strengthIncrease,
|
||||
color.w
|
||||
}
|
||||
);
|
||||
if (ImGui::Button(ICON_MD_PLAY_ARROW, { 90,25 })) {
|
||||
// Play game
|
||||
}
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::SameLine();
|
||||
color = ImVec4{ 0.001 * 14, 0.001 * 157, 0.001 * 201, 1.0f };
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
||||
|
||||
ImGui::PushStyleColor(
|
||||
ImGuiCol_ButtonHovered,
|
||||
ImVec4{
|
||||
color.x * strengthIncrease,
|
||||
color.y * strengthIncrease,
|
||||
color.z * strengthIncrease,
|
||||
color.w
|
||||
}
|
||||
);
|
||||
|
||||
if (ImGui::Button(ICON_MD_ELECTRIC_BOLT, { 90,25 })) {
|
||||
// Simulate physics
|
||||
}
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::End();
|
||||
|
||||
|
||||
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoTitleBar
|
||||
| ImGuiWindowFlags_NoDecoration
|
||||
| ImGuiWindowFlags_NoScrollbar
|
||||
| ImGuiWindowFlags_NoMove
|
||||
| ImGuiWindowFlags_NoCollapse;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 });
|
||||
ImGui::Begin("SceneView",nullptr,viewportWindowFlags);
|
||||
// spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||
SceneisFocused = ImGui::IsWindowFocused() || ImGui::IsWindowHovered();
|
||||
ImGui::Image((ImTextureID)(intptr_t)renderer.get()->getCurrentFrameBuffer().GetColourAttachment(),
|
||||
ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()});
|
||||
|
||||
|
||||
|
||||
//ImGuizmo::ViewManipulate(glm::value_ptr(cameraView), 1, ImGui::GetWindowPos(), { 90,90 }, 0x22CCCCCCC);
|
||||
|
||||
|
||||
if(Selected.isValid()){
|
||||
|
||||
|
||||
ImGuizmo::SetOrthographic(false);
|
||||
ImGuizmo::SetDrawlist();
|
||||
|
||||
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||
|
||||
const auto& ProjMatrix = camera->getProjection(ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||
const glm::mat4& viewMatrix = glm::inverse(camera->getTransform());
|
||||
|
||||
|
||||
auto& tc = Selected.GetComponent<YoggieEngine::TransformComponent>();
|
||||
auto transform = tc.GetTransform();
|
||||
ImGuizmo::Manipulate(
|
||||
glm::value_ptr(viewMatrix),
|
||||
glm::value_ptr(ProjMatrix),
|
||||
activeOperation, ImGuizmo::LOCAL, glm::value_ptr(transform));
|
||||
if (ImGuizmo::IsUsing())
|
||||
{
|
||||
tc.Decompose(transform);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::Begin("EditorCamera");
|
||||
|
||||
ImGui::SliderFloat3("position", glm::value_ptr(camera->Position), -50, 50);
|
||||
ImGui::End();
|
||||
|
||||
|
||||
|
||||
|
||||
ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr);
|
||||
scene.get()->getReg().each([&](entt::entity enttNumber) {
|
||||
YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &*scene.get());
|
||||
auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>();
|
||||
if (ImGui::Selectable(id.name.c_str(), entity == Selected)) {
|
||||
Selected = YoggieEngine::Entity(enttNumber, &*scene);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ImGui::End();
|
||||
|
||||
|
||||
{
|
||||
ImGui::Begin("Asset", nullptr);
|
||||
|
||||
const char* hidden_extensions[]{
|
||||
".exe",
|
||||
".pdb",
|
||||
".idb",
|
||||
".dll",
|
||||
".ini"
|
||||
};
|
||||
|
||||
|
||||
std::vector <Asset> files = std::vector<Asset>();
|
||||
|
||||
int iconSize = 60;
|
||||
int maxColumns = 3;
|
||||
|
||||
YoggieEngine::Texture folderIcon;
|
||||
YoggieEngine::Texture assetIcon;
|
||||
|
||||
//assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png");
|
||||
|
||||
|
||||
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
|
||||
ImGui::DragInt("Max. Columns", &maxColumns, 1, 1, 6);
|
||||
|
||||
if (ImGui::BeginTable("##Resources", 3)) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f));
|
||||
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
for (auto& asset : files) {
|
||||
if (column % 3 == 0) {
|
||||
ImGui::TableNextRow();
|
||||
column = 0;
|
||||
row++;
|
||||
}
|
||||
|
||||
ImGui::TableSetColumnIndex(column);
|
||||
|
||||
ImGui::ImageButton(
|
||||
(ImTextureID)assetIcon.GetID(),
|
||||
ImVec2{ (float)iconSize, (float)iconSize });
|
||||
ImGui::Text(asset.Handle.String().c_str(), row);
|
||||
|
||||
|
||||
|
||||
column++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImGui::PopStyleColor(3);
|
||||
ImGui::EndTable();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImGui::ShowDemoWindow();
|
||||
//ImGui::ShowMetricsWindow();
|
||||
}
|
||||
|
||||
|
||||
void OnCreate() override {
|
||||
spdlog::info(" Layer Create!" );
|
||||
|
||||
}
|
||||
|
||||
void OnDestroy() override {
|
||||
spdlog::info( " Layer Destroy!" );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool OnKey(int key, int mode) override {
|
||||
float movement_speed = 0.10f;
|
||||
|
||||
if (SceneisFocused) {
|
||||
if (key == YOGGIE_KEY_UP)
|
||||
camera->Rotation.x += movement_speed;
|
||||
|
||||
if (key == YOGGIE_KEY_DOWN)
|
||||
camera->Rotation.x -= movement_speed;
|
||||
|
||||
if (key == YOGGIE_KEY_LEFT)
|
||||
camera->Rotation.y += movement_speed;
|
||||
|
||||
if (key == YOGGIE_KEY_RIGHT)
|
||||
camera->Rotation.y -= movement_speed;
|
||||
|
||||
|
||||
|
||||
if (key == YOGGIE_KEY_A)
|
||||
camera->Position += glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed;
|
||||
|
||||
if (key == YOGGIE_KEY_S)
|
||||
camera->Position += glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed;
|
||||
|
||||
if (key == YOGGIE_KEY_D)
|
||||
camera->Position -= glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed;
|
||||
|
||||
if (key == GLFW_KEY_W)
|
||||
camera->Position -= glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::unique_ptr<Inspector> inspector = std::make_unique<Inspector>(Selected);
|
||||
std::unique_ptr<Renderer> renderer = std::make_unique<Renderer>();
|
||||
std::unique_ptr<EditorCamera> camera = std::make_unique<EditorCamera>();
|
||||
std::unique_ptr<Project> project;
|
||||
std::unique_ptr<Scene> scene;
|
||||
|
||||
Texture Logo;
|
||||
|
||||
|
||||
bool SimulatePhysics = true;
|
||||
bool SceneisFocused = false;
|
||||
|
||||
YoggieEngine::Entity Selected;
|
||||
ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE;
|
||||
|
||||
char* path = nullptr;
|
||||
|
||||
void LoadLastOrEmptyProject() {
|
||||
// Check if there is a last known loaded project and
|
||||
// load that one .
|
||||
|
||||
// Otherwise load no project..
|
||||
// OR
|
||||
// Load an empty project.
|
||||
mINI::INIStructure ini;
|
||||
|
||||
if (std::filesystem::exists("build\\Debug\\Editor.ini"))
|
||||
{
|
||||
mINI::INIFile file("build\\Debug\\Editor.ini");
|
||||
file.read(ini);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::debug("Could not find an `Editor.ini` file.");
|
||||
}
|
||||
|
||||
if (ini["editor"]["openlastproject"] == "TRUE")
|
||||
{
|
||||
|
||||
Project::LoadProject(ini["cache"]["project"], *project);
|
||||
///LoadScene(ini["cache"]["scene"], scene);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::debug("Starting without a project. Please create one.");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
27
Editor/src/EditorWindow.h
Normal file
27
Editor/src/EditorWindow.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <imgui.h>
|
||||
#include <string>
|
||||
|
||||
class EditorWindow {
|
||||
|
||||
public:
|
||||
EditorWindow (const std::string& name, ImGuiWindowFlags_ flags = ImGuiWindowFlags_None ) : name(name) , flags(flags) {}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
ImGui::Begin(name.c_str(), nullptr, flags);
|
||||
Draw();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
~EditorWindow() = default;
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
|
||||
private:
|
||||
ImGuiWindowFlags_ flags;
|
||||
|
||||
virtual void Draw() = 0;
|
||||
};
|
2244
Editor/src/IconsMaterialDesign.h
Normal file
2244
Editor/src/IconsMaterialDesign.h
Normal file
File diff suppressed because it is too large
Load Diff
197
Editor/src/Inspector.cpp
Normal file
197
Editor/src/Inspector.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
#include "Inspector.h"
|
||||
#include "TransformVec3.h"
|
||||
#include "IconsMaterialDesign.h"
|
||||
|
||||
void Inspector::Draw()
|
||||
{
|
||||
if (selected.isValid()) {
|
||||
AddComponentDropDown();
|
||||
ShowComponents();
|
||||
}
|
||||
}
|
||||
void AddComponent(YoggieEngine::Entity selected , int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
selected.AddComponent<YoggieEngine::ScriptComponent>();
|
||||
break;
|
||||
case 1:
|
||||
selected.AddComponent<YoggieEngine::CameraComponent>();
|
||||
break;
|
||||
case 2:
|
||||
selected.AddComponent<YoggieEngine::LightComponent>();
|
||||
break;
|
||||
case 3:
|
||||
selected.AddComponent<YoggieEngine::Render3DComponent>();
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Inspector::AddComponentDropDown()
|
||||
{
|
||||
static char* names[] = { "Script Component", "Camera Component", "Light Component", "Render3D"};
|
||||
if (ImGui::Button("Add Component"))
|
||||
ImGui::OpenPopup("Component picker");
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::BeginPopup("Component picker")) {
|
||||
|
||||
for (int i = 0; i < IM_ARRAYSIZE(names); i++) {
|
||||
if (ImGui::MenuItem(names[i]))
|
||||
AddComponent(selected, i);
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
|
||||
}
|
||||
ImGui::NewLine();
|
||||
}
|
||||
|
||||
|
||||
void Inspector::ShowComponents()
|
||||
{
|
||||
auto component = selected.GetComponent<YoggieEngine::IdentifierComponent>();
|
||||
ImGui::InputText("Name:", (char*)component.name.c_str(), component.name.size() * sizeof(char), ImGuiInputTextFlags_ReadOnly);
|
||||
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::TransformComponent>()) {
|
||||
auto& transform = selected.GetComponent<YoggieEngine::TransformComponent>();
|
||||
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
|
||||
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - 20);
|
||||
ImGui::Button(ICON_MD_SETTINGS, { 20,20 });
|
||||
ImGui::OpenPopupOnItemClick("##myContext", ImGuiPopupFlags_MouseButtonRight);
|
||||
if (ImGui::BeginPopupContextWindow("##myContext")) {
|
||||
if (ImGui::MenuItem("Reset")) {
|
||||
spdlog::info("Reset component");
|
||||
}
|
||||
if (ImGui::MenuItem("Copy Component")) {
|
||||
spdlog::info("Copy component");
|
||||
}
|
||||
|
||||
|
||||
ImGui::EndPopup();
|
||||
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
/*
|
||||
ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f);
|
||||
ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f);
|
||||
ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.1f, 0.0f);
|
||||
*/
|
||||
auto something = glm::value_ptr(transform.Position);
|
||||
|
||||
ImGuiExtension::TransformVec3("Position", transform.Position);
|
||||
ImGuiExtension::TransformVec3("Rotation", transform.Rotation);
|
||||
ImGuiExtension::TransformVec3("Scale", transform.Scale);
|
||||
|
||||
|
||||
}
|
||||
if (selected.HasComponent<YoggieEngine::RelationComponent>()) {
|
||||
ImGui::Text("Has relation");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::Render3DComponent>()) {
|
||||
auto& render3d = selected.GetComponent<YoggieEngine::Render3DComponent>();
|
||||
const char* AssetNames[]{ "Asset1" , "Asset2" };
|
||||
if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
|
||||
if (ImGui::Button("Select Renderable Asset"))
|
||||
ImGui::OpenPopup("Renderable_list_popup");
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(render3d.mesh.elements.empty() ? "<None>" : "ASSET_GUID_OR_ID");
|
||||
if (ImGui::BeginPopup("Renderable_list_popup")) {
|
||||
ImGui::Text("None");
|
||||
ImGui::Separator();
|
||||
for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) {
|
||||
if(ImGui::Selectable(AssetNames[i]))
|
||||
{ }
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color));
|
||||
|
||||
ImGui::Checkbox("Use static rendering:", &render3d.isStatic);
|
||||
}
|
||||
}
|
||||
static bool deferred = true;
|
||||
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::LightComponent>()) {
|
||||
auto& light = selected.GetComponent<YoggieEngine::LightComponent>();
|
||||
if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color));
|
||||
ImGui::Checkbox("Deferred", &deferred);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (selected.HasComponent <YoggieEngine::CameraComponent>()) {
|
||||
auto& camera = selected.GetComponent<YoggieEngine::CameraComponent>();
|
||||
if (ImGui::CollapsingHeader("Camera")) {
|
||||
ImGui::DragFloat3("Position:", glm::value_ptr(camera.Position), 0.01f);
|
||||
ImGui::DragFloat3("Rotation:", glm::value_ptr(camera.Rotation), 0.01f);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::RigidBody>()) {
|
||||
auto& rigibody = selected.GetComponent<YoggieEngine::RigidBody>();
|
||||
if (ImGui::CollapsingHeader("RigidBody")) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (selected.HasComponent<YoggieEngine::ScriptComponent>()) {
|
||||
const char* AssetNames[]{ "Script 1" , "Script 2" };
|
||||
if (ImGui::CollapsingHeader("Script", ImGuiTreeNodeFlags_Leaf)) {
|
||||
|
||||
if (ImGui::Button("Select Renderable Asset"))
|
||||
ImGui::OpenPopup("Scripts_list_popup");
|
||||
|
||||
if (ImGui::BeginPopup("Scripts_list_popup")) {
|
||||
ImGui::Text("None");
|
||||
ImGui::Separator();
|
||||
for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) {
|
||||
if (ImGui::Selectable(AssetNames[i]))
|
||||
{
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
std::string scriptAssetId = "<Random_GUID>";
|
||||
ImGui::InputText("asset", scriptAssetId.data(), scriptAssetId.length(), ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AutoSelectAll);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ComponentView(const std::string& componentName, voidFunction func)
|
||||
{
|
||||
ImGuiWindowFlags_ window_flags = ImGuiWindowFlags_None;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f);
|
||||
ImGui::BeginChild(componentName.c_str());
|
||||
|
||||
func();
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
22
Editor/src/Inspector.h
Normal file
22
Editor/src/Inspector.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||
#include "EditorWindow.h"
|
||||
|
||||
typedef void (*voidFunction) (void);
|
||||
|
||||
inline void ComponentView(const std::string& componentName, voidFunction func);
|
||||
|
||||
class Inspector : public EditorWindow {
|
||||
public:
|
||||
Inspector( YoggieEngine::Entity& selected ) : EditorWindow("Inspector"), selected(selected){}
|
||||
|
||||
void Draw()override;
|
||||
|
||||
private:
|
||||
|
||||
void AddComponentDropDown();
|
||||
void ShowComponents();
|
||||
|
||||
|
||||
YoggieEngine::Entity& selected;
|
||||
};
|
86
Editor/src/Project.cpp
Normal file
86
Editor/src/Project.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
#include "Project.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
|
||||
void Project::SaveProject(std::filesystem::path path, Project& project)
|
||||
{
|
||||
YAML::Emitter projectYAML;
|
||||
projectYAML << YAML::BeginMap;
|
||||
projectYAML << YAML::Key << "Project" << YAML::Value << project.Name;
|
||||
projectYAML << YAML::Key << "Directory" << YAML::Value << path.parent_path().u8string();
|
||||
projectYAML << YAML::EndMap;
|
||||
projectYAML << YAML::BeginMap;
|
||||
|
||||
|
||||
projectYAML << YAML::Key << "Scenes" << YAML::Value << YAML::BeginSeq;
|
||||
for (auto scene : project.Scenes) {
|
||||
projectYAML << scene->name;
|
||||
}
|
||||
projectYAML << YAML::EndSeq;
|
||||
|
||||
std::ofstream projectFile;
|
||||
|
||||
projectFile.open(path.u8string());
|
||||
projectFile << projectYAML.c_str();
|
||||
projectFile.close();
|
||||
}
|
||||
|
||||
void Project::LoadProject(std::filesystem::path path, Project& project)
|
||||
{
|
||||
|
||||
if (!std::filesystem::exists(path)) {
|
||||
throw std::runtime_error("Couldn't find project file!");
|
||||
}
|
||||
|
||||
std::string YAMLProject;
|
||||
std::stringstream sstream;
|
||||
std::ifstream projectFile;
|
||||
projectFile.open(path.u8string());
|
||||
|
||||
sstream << projectFile.rdbuf();
|
||||
YAMLProject = sstream.str();
|
||||
|
||||
projectFile.close();
|
||||
|
||||
|
||||
YAML::Node node = YAML::Load(YAMLProject);
|
||||
|
||||
// this is probably not perfect but it seems to work for now
|
||||
project = node.as<Project>();
|
||||
|
||||
spdlog::info("loaded project {0}", project.Name);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace YAML {
|
||||
|
||||
template<>
|
||||
class convert<Project> {
|
||||
public:
|
||||
static bool decode(const Node& node , Project& rhs)
|
||||
{
|
||||
if (!node.IsMap())
|
||||
return false;
|
||||
|
||||
std::string projectName = node["Project"].as<std::string>();
|
||||
rhs.setName(projectName);
|
||||
|
||||
|
||||
std::string projectDirectory = node["Directory"].as<std::string>();
|
||||
rhs.setProjectDirectory(projectDirectory);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
37
Editor/src/Project.h
Normal file
37
Editor/src/Project.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
|
||||
class Project {
|
||||
public:
|
||||
Project() = default;
|
||||
Project(const std::string& name): Name(name){}
|
||||
~Project() { spdlog::info("Unloading project {0}...", Name);}
|
||||
|
||||
void setName(std::string& name) { Name = name; }
|
||||
const std::string& GetName()const { return Name; }
|
||||
|
||||
void setProjectDirectory(std::string& path) { ProjectDirectory = std::filesystem::path(path); }
|
||||
const std::filesystem::path GetProjectDirectory() { return ProjectDirectory; }
|
||||
|
||||
|
||||
void AddScene(YoggieEngine::Scene& scene)
|
||||
{
|
||||
Scenes.push_back(&scene);
|
||||
}
|
||||
|
||||
static void SaveProject(std::filesystem::path path, Project& project);
|
||||
static void LoadProject(std::filesystem::path path, Project& project);
|
||||
private:
|
||||
std::string Name;
|
||||
std::filesystem::path ProjectDirectory;
|
||||
|
||||
std::vector<YoggieEngine::Scene*> Scenes;
|
||||
|
||||
friend class YAML::convert<Project>;
|
||||
|
||||
};
|
||||
|
59
Editor/src/TransformVec3.h
Normal file
59
Editor/src/TransformVec3.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
#include <imgui_widgets.cpp>
|
||||
#include <glm/glm.hpp>
|
||||
namespace ImGuiExtension {
|
||||
|
||||
|
||||
void TransformVec3(const char* label, glm::vec3& vector) {
|
||||
|
||||
ImGui::PushID(label);
|
||||
ImGui::Columns(2);
|
||||
ImGui::SetColumnWidth(0, 100.0f);
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f,0.2f,0.2f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.8f,0.1f,0.15f, 1.0f });
|
||||
if (ImGui::Button("X"))
|
||||
vector.x = 0;
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##X", &glm::value_ptr(vector)[0], 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.3f,0.8f,0.3f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.2f,0.7f,0.2f, 1.0f });
|
||||
if (ImGui::Button("Y"))
|
||||
vector.y = 0;
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Y", &glm::value_ptr(vector)[1], 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.1f, 0.25f, 0.8f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.2f,0.35f,0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.1f,0.25f,0.8f, 1.0f });
|
||||
if (ImGui::Button("Z"))
|
||||
vector.z = 0;
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Z", &glm::value_ptr(vector)[2], 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::Columns(1);
|
||||
ImGui::PopID();
|
||||
|
||||
}
|
||||
}
|
17
Editor/src/app.cpp
Normal file
17
Editor/src/app.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "EditorLayer.h"
|
||||
#include "EntryPoint.h"
|
||||
#include <stack>
|
||||
|
||||
using namespace YoggieEngine;
|
||||
|
||||
class Editor : public Application {
|
||||
public:
|
||||
Editor() : Application("Editor") {}
|
||||
|
||||
void Run() override {
|
||||
PushLayer(new EditorLayer());
|
||||
Application::Run();
|
||||
}
|
||||
};
|
||||
|
||||
YoggieEngine::Application *CreateApplication() { return new Editor(); }
|
@ -1,138 +0,0 @@
|
||||
#include "../../BarinkEngine/src/BarinkEngine.h"
|
||||
#include "../../BarinkEngine/src/Scene/SceneManager.h"
|
||||
#include "../../BarinkEngine/src/Scene/SceneNodeTypes.h"
|
||||
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
|
||||
#include "../../BarinkEngine/src/Graphics/Framebuffer.h"
|
||||
#include <imgui.h>
|
||||
|
||||
/*
|
||||
* Define globals
|
||||
*/
|
||||
Shader* shader;
|
||||
|
||||
char* code = new char[254];
|
||||
|
||||
const std::string vertexShaderSource = "build/Debug/test.vs";
|
||||
const std::string fragmentShaderSource = "build/Debug/test.fs";
|
||||
|
||||
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
|
||||
Framebuffer* framebuffer;
|
||||
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
|
||||
|
||||
// Create a level and load it as the current level
|
||||
std::string levelName("Test Level");
|
||||
Level1 = SceneManager::CreateScene(levelName);
|
||||
SceneManager::LoadScene(*Level1);
|
||||
|
||||
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
||||
|
||||
// Create a cube node
|
||||
|
||||
cube = MI->Import("build/Debug/Models/cube.obj");
|
||||
cube->renderable->material = new Material(*shader);
|
||||
cube->renderable->material->Color = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
|
||||
// What is in cube now ??
|
||||
std::cout << "mesh vertices: " << cube->renderable->mesh->vertices.size() << std::endl;
|
||||
std::cout << "mesh elements: " << cube->renderable->mesh->elements.size() << std::endl;
|
||||
|
||||
Level1->GetRoot().addChild(*cube);
|
||||
|
||||
memset(code, '\0', 254);
|
||||
framebuffer = new Framebuffer();
|
||||
|
||||
std::cout << "Colour attachment id; " << framebuffer->GetColourAttachment() << std::endl;
|
||||
// TODO: Move to runtime/ Engine
|
||||
// NOTE: Submits should later be done through walking the sceneTree
|
||||
|
||||
renderer.Submit(cube->renderable);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs every frame
|
||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||
*/
|
||||
void ImmediateGraphicsDraw()
|
||||
{
|
||||
|
||||
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||
|
||||
// Show a menu bar
|
||||
ImGui::BeginMainMenuBar();
|
||||
|
||||
if (ImGui::BeginMenu("Application")) {
|
||||
|
||||
|
||||
if (ImGui::MenuItem("Exit")) {
|
||||
// TODO: Exit application
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
|
||||
|
||||
// Show internal BarinkEngine stats
|
||||
ShowStats();
|
||||
|
||||
ImGui::Begin("Viewport");
|
||||
ImGui::Image((void*)(intptr_t)framebuffer->GetColourAttachment(), ImVec2{ 800,600 });
|
||||
ImGui::End();
|
||||
|
||||
static float Zoom = 90;
|
||||
static glm::vec3 Position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
static glm::vec3 Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
ImGui::Begin("Camera");
|
||||
ImGui::SliderFloat("Zoom", &Zoom, 10, 190);
|
||||
ImGui::InputFloat3("Position:", &Position[0]);
|
||||
|
||||
ImGui::InputFloat3("Rotation:", &Rotation[0]);
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Scripting");
|
||||
ImGui::Text("Lua Code");
|
||||
ImGui::InputTextMultiline("##", code, 255);
|
||||
bool runCode = ImGui::Button("Run");
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Scene Explorer");
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs every frame
|
||||
* - Meant for game logic ( non-physics related)
|
||||
*/
|
||||
void Update()
|
||||
{
|
||||
// glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GetId());
|
||||
|
||||
renderer.Render(*framebuffer);
|
||||
|
||||
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs at the end of the program
|
||||
* - Meant for cleanup
|
||||
*/
|
||||
void Stop()
|
||||
{
|
||||
delete framebuffer;
|
||||
delete MI;
|
||||
delete shader;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
project "ImGui"
|
||||
kind "StaticLib"
|
||||
|
||||
includedirs {
|
||||
"../libs/glfw/include",
|
||||
"../libs/ImGui"
|
||||
}
|
||||
|
||||
files {
|
||||
"../libs/ImGui/*.cpp",
|
||||
"../libs/ImGui/backends/imgui_impl_glfw.cpp",
|
||||
"../libs/ImGui/backends/imgui_impl_Opengl3.cpp",
|
||||
}
|
||||
|
||||
libdirs{
|
||||
"../libs/ImGui",
|
||||
"../libs/glad"
|
||||
}
|
84
README.md
84
README.md
@ -1,76 +1,34 @@
|
||||
# BarinkEngine
|
||||
```
|
||||
,---,. ,-. ,---,.
|
||||
,' .' \ ,--, ,--/ /| ,' .' | ,--,
|
||||
,---.' .' | __ ,-,--.'| ,---,,--. :/ |,---.' | ,---, ,--.'| ,---,
|
||||
| | |: | ,' ,'/ /| |, ,-+-. / : : ' / | | .' ,-+-. / | ,----._,| |, ,-+-. / |
|
||||
: : : / ,--.--. ' | |' `--'_ ,--.'|' | ' / : : |-,,--.'|' |/ / ' `--'_ ,--.'|' | ,---.
|
||||
: | ; / \| | ,,' ,'| | | ,"' ' | : : | ;/| | ,"' | : ,' ,'| | | ,"' | / \
|
||||
| : .--. .-. ' : / ' | | | | / | | | \ | : .| | / | | | .\ ' | | | | / | |/ / |
|
||||
| | . |\__\/: . | | ' | | : | | | | ' : |. \| | |-| | | | . ; '; | | : | | | | . ' / |
|
||||
' : '; |," .--.; ; : | ' : |__| | | |/| | ' \ ' : ;/| | | |/' . . ' : |__| | | |/' ; /|
|
||||
| | | ;/ / ,. | , ; | | '.'| | |--' ' : |--'| | | | |--' `---`-'| | | '.'| | |--' ' | / |
|
||||
| : /; : .' ---' ; : | |/ ; |,' | : .| |/ .'__/\_: ; : | |/ | : |
|
||||
| | ,' | , .-./ | , /'---' '--' | | ,' '---' | : | , /'---' \ \ /
|
||||
`----' `--`---' ---`-' `----' \ \ / ---`-' `----'
|
||||
`--`-'
|
||||
```
|
||||
# Yoggie Engine
|
||||
|
||||
<img src="Screenshots/Yoggie.webp" width="160" ></img>
|
||||
## Goal
|
||||
Must support building a full game in 48 hours.
|
||||
The goal is to build a mature enough engine to be capable of using during game jams.
|
||||
|
||||
|
||||
## Features
|
||||
**NOTE** __Not in any particular order__
|
||||
*_NOTE:_ Just because it is listed as a feature here does not imply it has been nor guarantees it ever will be implemented*
|
||||
- Rendering
|
||||
- OpenGL
|
||||
- Vulkan
|
||||
|
||||
- Metal (Possibly)
|
||||
- Logging
|
||||
- Different for debug and release
|
||||
- Different per OS
|
||||
|
||||
- Physics
|
||||
- PhysX
|
||||
- Alternative for non-nvidia stuff?!
|
||||
|
||||
- Basic Entity Component system
|
||||
|
||||
- Graphical scripting ??
|
||||
|
||||
- Scripting support ( idk what language)
|
||||
- Jolt Physics
|
||||
- Entity Component system
|
||||
- Graphical scripting (Possibly)
|
||||
- Scripting support
|
||||
- LUA
|
||||
- C# (for object orientated approaches to gamedev)
|
||||
- Configuration options
|
||||
- JSON
|
||||
- LUA
|
||||
- others ?!?!?
|
||||
- YAML
|
||||
- INI
|
||||
|
||||
## Screenshots
|
||||
|
||||
<img src="Screenshots/screen1.png" width="300"></img>
|
||||
<img src="Screenshots/screen2.png" width="300"></img>
|
||||
|
||||
## Planning
|
||||
see [TODO](docs/TODO.md)
|
||||
|
||||
_NOTE:_
|
||||
|
||||
The planning is moving away from markdown in favor
|
||||
of gitea Projects. New planning will be visible on [this page](https://git.barink.dev/Nigel/MyGameEngine/projects).
|
||||
## Requirements
|
||||
#### Software
|
||||
* Premake
|
||||
* Git
|
||||
* C++ Compiler
|
||||
|
||||
## Windows development workflow
|
||||
User premake to generate project files for the approperiate build method.
|
||||
On Windows I assume you'll build with visual studio
|
||||
|
||||
```bash
|
||||
User:~$ premake vs2022
|
||||
```
|
||||
|
||||
## Linux development workflow
|
||||
Use premake to generate project files for the approperiate build method.
|
||||
On Linux I assume you'll build with something like make.
|
||||
|
||||
```bash
|
||||
User@Machine:~$ premake gmake2
|
||||
```
|
||||
## More docs
|
||||
[Todo list](TODO.md) \
|
||||
[Planning](https://git.barink.dev/Nigel/MyGameEngine/projects)\
|
||||
[Development](DEVELOPMENT.md)\
|
||||
[Show case](SHOWCASE.md)
|
||||
|
@ -1,39 +0,0 @@
|
||||
project "Runtime"
|
||||
kind "ConsoleApp"
|
||||
|
||||
buildmessage "Building the runtime ..."
|
||||
|
||||
links{
|
||||
"BarinkEngine"
|
||||
}
|
||||
|
||||
includedirs{
|
||||
"./../BarinkEngine/src",
|
||||
-- I'd prefer if didn't need these..
|
||||
-- We'll figure that out some time later
|
||||
"./../libs/lua/include",
|
||||
"./../libs/spdlog/include",
|
||||
"./../libs/glm",
|
||||
"./../libs/GorillaAudio/include",
|
||||
|
||||
"./../libs/assimp/include",
|
||||
"./../libs/glad/include",
|
||||
"./../libs/glfw/include",
|
||||
"./../libs/tinygltf",
|
||||
"./../libs/glew/include",
|
||||
"./../libs/glm",
|
||||
"./../libs/ImGui",
|
||||
|
||||
|
||||
"./include"
|
||||
|
||||
}
|
||||
|
||||
libdirs {
|
||||
'./../build/BarinkEngine/Debug'
|
||||
}
|
||||
|
||||
files {
|
||||
"./src/*.h",
|
||||
"./src/*.cpp"
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Welcome to the runtime!" << std::endl;
|
||||
}
|
17
SHOWCASE.md
Normal file
17
SHOWCASE.md
Normal file
@ -0,0 +1,17 @@
|
||||
## The engine development in pictures
|
||||
|
||||
__Testing OpenGl with ImGui as a concept__
|
||||
|
||||
<img src="Screenshots/OpenGLAndImGuiTest.png" width="300"></img>
|
||||
|
||||
__Working on docking with different windows using ImGui__
|
||||
|
||||
<img src="Screenshots/YoggieEditor_workingGuizmo.png" width="300"></img>
|
||||
|
||||
__A first more complete look of the engine__
|
||||
|
||||
<img src="Screenshots/YoggieEditorV0.2.png" width="300"></img>
|
||||
|
||||
__Mixing deferred and forward rendering and adding a skybox__
|
||||
|
||||
<img src="Screenshots/ImprovedRendering.png" width="300"></img>
|
6
SandboxApp/CMakeLists.txt
Normal file
6
SandboxApp/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
file(GLOB SOURCE_FILES "src/*.cpp")
|
||||
file(GLOB HEADER_FILES "src/*.h")
|
||||
add_executable(SandboxApp ${SOURCE_FILES} ${HEADER_FILES} )
|
||||
target_link_directories(SandboxApp PRIVATE "../build/YoggieEngine/Debug")
|
||||
target_link_libraries(SandboxApp YoggieEngine)
|
||||
target_include_directories(SandboxApp PRIVATE "../YoggieEngine/src")
|
@ -1,40 +0,0 @@
|
||||
project "SandboxApp"
|
||||
kind "ConsoleApp"
|
||||
|
||||
buildmessage "Building SandboxApp ..."
|
||||
|
||||
links{
|
||||
"BarinkEngine"
|
||||
}
|
||||
|
||||
includedirs{
|
||||
"./../BarinkEngine/Include",
|
||||
|
||||
-- I'd prefer if didn't need these..
|
||||
-- We'll figure that out some time later
|
||||
"./../libs/lua/include",
|
||||
"./../libs/spdlog/include",
|
||||
"./../libs/glm",
|
||||
"./../libs/GorillaAudio/include",
|
||||
|
||||
"./../libs/assimp/include",
|
||||
"./../libs/glad/include",
|
||||
"./../libs/glfw/include",
|
||||
"./../libs/tinygltf",
|
||||
"./../libs/glew/include",
|
||||
"./../libs/glm",
|
||||
"./../libs/ImGui",
|
||||
|
||||
"../libs/entt/src",
|
||||
|
||||
|
||||
}
|
||||
|
||||
libdirs {
|
||||
'./../build/BarinkEngine/Debug'
|
||||
}
|
||||
|
||||
files {
|
||||
"./src/*.h",
|
||||
"./src/*.cpp"
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
#include "YoggieEngine.h"
|
||||
#include "imgui.h"
|
||||
#include "../../BarinkEngine/src/BarinkEngine.h"
|
||||
#include "../../BarinkEngine/src/Graphics/Memory/Framebuffer.h"
|
||||
|
||||
void CameraTool();
|
||||
void ScriptingTool(char* code);
|
||||
///void transformWindow(Transform& transform, std::string PanelName);
|
||||
void materialWindow(Material& material, std::string PanelName);
|
||||
void SceneExplorer(const std::string& PanelName);
|
||||
void SceneView(Framebuffer& framebuffer);
|
||||
void ScriptingTool(char *code);
|
||||
/// void transformWindow(Transform& transform, std::string PanelName);
|
||||
void materialWindow(Material &material, std::string PanelName);
|
||||
void SceneExplorer(const std::string &PanelName);
|
||||
void SceneView(Framebuffer &framebuffer);
|
||||
|
@ -1,75 +1,102 @@
|
||||
#include "../../BarinkEngine/src/BarinkEngine.h"
|
||||
#include "../../BarinkEngine/src/Scene/Components.h"
|
||||
#include "../../BarinkEngine/src/Scene/Scene.h"
|
||||
#include "../../BarinkEngine/src/Scene/Entity.h"
|
||||
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
|
||||
#include <imgui.h>
|
||||
#include "GUI.h"
|
||||
#include "Util.h"
|
||||
#include <entt/entt.hpp>
|
||||
#include <imgui.h>
|
||||
|
||||
#include "YoggieEngine.h"
|
||||
|
||||
/*
|
||||
* Define globals
|
||||
*/
|
||||
* Define globals
|
||||
*/
|
||||
Scene scene;
|
||||
|
||||
BarinkEngine::Renderable* renderable;
|
||||
BarinkEngine::SceneObject* object;
|
||||
BarinkEngine::Renderable *renderable;
|
||||
BarinkEngine::SceneObject *object;
|
||||
Entity cube;
|
||||
/*
|
||||
* Runs once at startup
|
||||
* - USe to initialize the game/sandbox/demo
|
||||
*/
|
||||
void Start() {
|
||||
|
||||
cube = scene.AddEntity((std::string&)"cube");
|
||||
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
/*
|
||||
* Runs once at startup
|
||||
* - USe to initialize the game/sandbox/demo
|
||||
*/
|
||||
void Start() {
|
||||
auto importer = BarinkEngine::ModelImporter();
|
||||
|
||||
// Load in asset(S)
|
||||
object = importer.Import("build/Debug/Models/Cube.obj");
|
||||
renderable = object->renderable;
|
||||
|
||||
// Add Entities to the scene
|
||||
cube = scene.AddEntity("cube");
|
||||
auto &render3DComponent =
|
||||
cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
render3DComponent.mesh = *renderable->mesh;
|
||||
cube.GetComponent<BarinkEngine::TransformComponent>().transform =
|
||||
glm::rotate(glm::mat4(1.0f), 32.0f, glm::vec3(0.5f, 1.0f, 0.0f));
|
||||
|
||||
// Create a second cube
|
||||
|
||||
auto cube2 = scene.AddEntity("Cube2");
|
||||
auto &cube2Render = cube2.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
cube2Render.mesh = *renderable->mesh;
|
||||
cube2Render.color = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
auto &cube2Trans = cube2.GetComponent<BarinkEngine::TransformComponent>();
|
||||
cube2Trans.transform =
|
||||
glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0.0f, 5.0f));
|
||||
|
||||
// Create a light
|
||||
auto AmbientLight = scene.AddEntity("AmbientLight");
|
||||
AmbientLight.AddComponent<BarinkEngine::LightComponent>();
|
||||
|
||||
renderer.Prepare(scene);
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs every frame
|
||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||
*/
|
||||
void ImmediateGraphicsDraw()
|
||||
{
|
||||
* Runs every frame
|
||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||
*/
|
||||
void ImmediateGraphicsDraw() {
|
||||
// Show internal BarinkEngine stats
|
||||
ShowStats();
|
||||
|
||||
ImGui::Begin("Render edit");
|
||||
|
||||
auto a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
||||
|
||||
ImGui::DragFloat3("Color", &a->color[0], 0.01f, 0.0f, 1.0f);
|
||||
EngineInstrumentation::ShowStats();
|
||||
|
||||
ImGui::Begin("Scene view");
|
||||
auto group = scene.getReg().view<BarinkEngine::IdentifierComponent>();
|
||||
group.each([](auto entity, BarinkEngine::IdentifierComponent &identifier) {
|
||||
ImGui::Text("%s", identifier.name.c_str());
|
||||
});
|
||||
ImGui::End();
|
||||
|
||||
ImGui::ShowMetricsWindow();
|
||||
|
||||
ImGui::Begin("Settings");
|
||||
|
||||
auto &a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
||||
|
||||
auto &b = cube.GetComponent<BarinkEngine::TransformComponent>();
|
||||
|
||||
ImGui::DragFloat3("Color", &a.color[0], 0.01f, 0.0f, 1.0f);
|
||||
|
||||
ImGui::DragFloat3("Position", &b.transform[3][0], 0.01f, 0.0f, 16.0f);
|
||||
|
||||
auto l = scene.getReg().view<BarinkEngine::LightComponent>();
|
||||
l.each([](auto entity, BarinkEngine::LightComponent &light) {
|
||||
ImGui::Text("Lighting");
|
||||
ImGui::SliderFloat("Intensity", &light.Strength, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat3("l-Color", &light.Color[0], 0.0f, 1.0f);
|
||||
});
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs every frame
|
||||
* - Meant for game logic ( non-physics related)
|
||||
*/
|
||||
void Update()
|
||||
{
|
||||
renderer.Render(scene);
|
||||
* Runs every frame
|
||||
* - Meant for game logic ( non-physics related)
|
||||
*/
|
||||
void Update() {}
|
||||
|
||||
}
|
||||
void Render() { renderer.Render(scene); }
|
||||
|
||||
/*
|
||||
* Runs at the end of the program
|
||||
* - Meant for cleanup
|
||||
*/
|
||||
void Stop()
|
||||
{
|
||||
}
|
||||
* Runs at the end of the program
|
||||
* - Meant for cleanup
|
||||
*/
|
||||
void Stop() {}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "../../BarinkEngine/src/BarinkEngine.h"
|
||||
#include "YoggieEngine.h"
|
||||
|
||||
//void PrintSceneTree(Node& node, int depth);
|
||||
// void PrintSceneTree(Node& node, int depth);
|
||||
|
||||
//glm::mat4 CalculateModelMat(Transform& transform);
|
||||
// glm::mat4 CalculateModelMat(Transform& transform);
|
||||
|
BIN
Screenshots/ImprovedRendering.png
(Stored with Git LFS)
Normal file
BIN
Screenshots/ImprovedRendering.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Screenshots/Yoggie.webp
(Stored with Git LFS)
Normal file
BIN
Screenshots/Yoggie.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Screenshots/YoggieEditorV0.2.png
(Stored with Git LFS)
Normal file
BIN
Screenshots/YoggieEditorV0.2.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Screenshots/YoggieEditor_workingGuizmo.png
(Stored with Git LFS)
Normal file
BIN
Screenshots/YoggieEditor_workingGuizmo.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Screenshots/screen2.png
(Stored with Git LFS)
BIN
Screenshots/screen2.png
(Stored with Git LFS)
Binary file not shown.
37
TODO.md
37
TODO.md
@ -1,24 +1,23 @@
|
||||
# Project Planning
|
||||
|
||||
**NOTE:** __Fairly detailed planning__
|
||||
|
||||
|
||||
<input type="checkbox" checked></input> Setup build system \
|
||||
<input type="checkbox" checked></input> Link with GLFW \
|
||||
<input type="checkbox" checked></input> Basic Window \
|
||||
<input type="checkbox" checked></input> Basic Triangle rendering \
|
||||
<input type="checkbox" checked></input> Basic IMGui \
|
||||
<input type="checkbox"></input> Basic Textures \
|
||||
<input type="checkbox" checked></input> Link GLEW or GLAD \
|
||||
<input type="checkbox" checked></input> Work on basic logging \
|
||||
<input type="checkbox" checked></input> Input handling \
|
||||
<input type="checkbox"></input> More shader work \
|
||||
<input type="checkbox" checked></input> Load FBX model files \
|
||||
<input type="checkbox"></input> Basic Physics \
|
||||
<input type="checkbox" checked> Running LUA \
|
||||
<input type="checkbox"> Lua Scripting \
|
||||
<input type="checkbox"></input> To far in the future
|
||||
|
||||
<input type="checkbox" checked> Setup build system</input>\
|
||||
<input type="checkbox" checked>Link with GLFW</input>\
|
||||
<input type="checkbox" checked>Link GLEW or GLAD</input>\
|
||||
<input type="checkbox" checked>Basic Window</input>\
|
||||
<input type="checkbox" checked>Work on basic logging</input>\
|
||||
<input type="checkbox" checked>Running LUA</input>\
|
||||
<input type="checkbox" checked>Basic triangle rendering</input>\
|
||||
<input type="checkbox" checked>Load model files</input>\
|
||||
<input type="checkbox" checked>Basic ImGui </input>\
|
||||
<input type="checkbox" checked>Skybox support</input>\
|
||||
<input type="checkbox">Basic Textures <i>(Soon)</i></input>\
|
||||
<input type="checkbox">More shader work <i>(Hopefully coming in January)</i></input> \
|
||||
<input type="checkbox">Input handling <i>(Soon)</i></input>\
|
||||
<input type="checkbox">Basic Physics <i>(Almost implemented)</i></input>\
|
||||
<input type="checkbox">Lua Scripting <i>(Soon)</i> </input>\
|
||||
<input type="checkbox">Basic Sound system</input>
|
||||
### What's next?
|
||||
I am not sure what's going to be added next
|
||||
|
||||
## Resources
|
||||
https://renderdoc.org/ \
|
||||
|
22
YoggieEngine/CMakeLists.txt
Normal file
22
YoggieEngine/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
file(GLOB SOURCE_FILES src/*.cpp)
|
||||
add_library(YoggieEngine ${SOURCE_FILES} )
|
||||
#target_precompile_headers(YoggieEngine PUBLIC src/YoggieEngine.h )
|
||||
|
||||
target_link_directories(YoggieEngine PUBLIC
|
||||
"../libs/physx/physx/bin/win.x86_64.vc142.md/debug"
|
||||
)
|
||||
target_link_libraries(YoggieEngine
|
||||
thirdparty_tools
|
||||
PhysX_64
|
||||
PhysXCooking_64
|
||||
PhysXCommon_64
|
||||
PhysXFoundation_64
|
||||
PhysXPvdSDK_static_64
|
||||
PhysXExtensions_static_64
|
||||
)
|
||||
|
||||
target_include_directories(YoggieEngine PUBLIC
|
||||
"../libs/physx/pxshared/include"
|
||||
"../libs/physx/physx/include"
|
||||
)
|
||||
|
161
YoggieEngine/src/Application.cpp
Normal file
161
YoggieEngine/src/Application.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
#include <YoggieEngine.h>
|
||||
#include "Application.h"
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include "../../libs/guizmo/ImGuizmo.h"
|
||||
#include "../../Editor/src/IconsMaterialDesign.h"
|
||||
|
||||
namespace YoggieEngine {
|
||||
|
||||
Application::Application(const std::string& name)
|
||||
: m_AppName(name)
|
||||
{
|
||||
appWindow = CreateNativeWindow(1200, 700, m_AppName.c_str());
|
||||
|
||||
// Initialize engine should possibly happen here
|
||||
EngineInstrumentation::PerfomanceSamplerInit();
|
||||
|
||||
// Initilize ImGui for this application
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable;
|
||||
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18);
|
||||
ImFontConfig config;
|
||||
config.MergeMode = true;
|
||||
config.GlyphMinAdvanceX = 18.0f;
|
||||
static const ImWchar icon_ranges[] = { ICON_MIN_MD , ICON_MAX_MD, 0 };
|
||||
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/MaterialIcons-Regular.ttf", 24, &config, icon_ranges);
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
/*
|
||||
ImGuiStyle* style = &ImGui::GetStyle();
|
||||
ImVec4* colors = style->Colors;
|
||||
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.72f, 0.24f, 0.87f, 1.00f);
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.72f, 0.24f, 0.87f, 1.00f);
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.53f, 0.09f, 0.67f, 1.00f);
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL((GLFWwindow*)appWindow->GetHandle(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 450");
|
||||
|
||||
ImGuizmo::SetImGuiContext(ImGui::GetCurrentContext());
|
||||
//ImGuizmo::SetOrthographic(true);
|
||||
|
||||
|
||||
//init_inputSystem(appWindow);
|
||||
glfwSetWindowUserPointer((GLFWwindow*)this->appWindow->GetHandle(), this);
|
||||
glfwSetKeyCallback((GLFWwindow*)this->appWindow->GetHandle(), HandleKey);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Application::HandleKey(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||
auto app = (Application*)glfwGetWindowUserPointer(window);
|
||||
for (auto i = app->AppLayerstack.begin(); i < app->AppLayerstack.end(); i++) {
|
||||
if ((*i)->OnKey(key, action)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::Run() {
|
||||
|
||||
|
||||
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||
(*i)->OnStartup();
|
||||
}
|
||||
|
||||
double previous = glfwGetTime();
|
||||
double lag = 0.0;
|
||||
|
||||
while (!appWindow->WindowShouldClose()) {
|
||||
PollEvents();
|
||||
double now = glfwGetTime();
|
||||
double elapsed = now - previous;
|
||||
previous = now;
|
||||
lag += elapsed;
|
||||
|
||||
|
||||
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||
(*i)->OnUpdate();
|
||||
}
|
||||
|
||||
GuiBegin();
|
||||
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||
(*i)->OnUI();
|
||||
}
|
||||
GuiEnd();
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||
(*i)->OnDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Application::PollEvents() {
|
||||
appWindow->Poll();
|
||||
}
|
||||
|
||||
void Application::SwapBuffers()
|
||||
{
|
||||
appWindow->SwapBuffers();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void Application::GuiBegin() {
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
ImGuizmo::BeginFrame();
|
||||
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Application::GuiEnd() {
|
||||
|
||||
ImGui::EndFrame();
|
||||
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
|
||||
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
GLFWwindow* last_context = glfwGetCurrentContext();
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
glfwMakeContextCurrent(last_context);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::PushLayer(Layer* layer)
|
||||
{
|
||||
AppLayerstack.PushLayer(layer);
|
||||
layer->OnAttach();
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
delete appWindow;
|
||||
|
||||
}
|
||||
}
|
38
YoggieEngine/src/Application.h
Normal file
38
YoggieEngine/src/Application.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include "YoggieEngine.h"
|
||||
#include "LayerStack.h"
|
||||
|
||||
|
||||
namespace YoggieEngine {
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application(const std::string& name);
|
||||
~Application();
|
||||
virtual void Run();
|
||||
|
||||
void PollEvents();
|
||||
|
||||
void SwapBuffers();
|
||||
|
||||
void GuiBegin();
|
||||
void GuiEnd();
|
||||
|
||||
void PushLayer(Layer* layer);
|
||||
static Application& Get() { return *Application::instance; }
|
||||
static void HandleKey(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void HandleMouseButton(GLFWwindow* window, int button, int action, int mods);
|
||||
static void HandleScroll(GLFWwindow* window, double xoffset, double yoffset);
|
||||
protected:
|
||||
std::string m_AppName;
|
||||
NativeWindow* appWindow;
|
||||
|
||||
LayerStack AppLayerstack;
|
||||
Layer* guiLayer;
|
||||
static Application* instance ;
|
||||
|
||||
friend class ImGuiLayer;
|
||||
|
||||
};
|
||||
|
||||
};
|
22
YoggieEngine/src/Assets/Asset.h
Normal file
22
YoggieEngine/src/Assets/Asset.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "uuid.h"
|
||||
|
||||
|
||||
typedef uuid::v4::UUID AssetHandle;
|
||||
|
||||
|
||||
enum class AssetType {
|
||||
Unknown = -1,
|
||||
Mesh,
|
||||
Texture,
|
||||
Material,
|
||||
Shader
|
||||
};
|
||||
|
||||
struct Asset {
|
||||
AssetHandle Handle;
|
||||
|
||||
template<class T >
|
||||
static AssetType GetType(T t) { return t.GetType(); }
|
||||
virtual AssetType GetType() { return AssetType::Unknown; }
|
||||
};
|
143
YoggieEngine/src/Assets/AssetImporter.cpp
Normal file
143
YoggieEngine/src/Assets/AssetImporter.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
#include <YoggieEngine.h>
|
||||
#include "AssetImporter.h"
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
|
||||
namespace YoggieEngine {
|
||||
|
||||
void ProcessVertices(aiMesh* mesh, std::vector<YoggieEngine::Vertex>& out_vertices) {
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||
YoggieEngine::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) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
YoggieEngine::Mesh processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||
std::vector<unsigned int> indices;
|
||||
std::vector<YoggieEngine::Vertex> vertices;
|
||||
|
||||
ProcessVertices(mesh, vertices);
|
||||
ProcessIndices(mesh, indices);
|
||||
|
||||
YoggieEngine::Mesh result;
|
||||
result.vertices = vertices;
|
||||
result.elements = indices;
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
std::vector<YoggieEngine::Mesh> processNode(aiNode* node, const aiScene* scene) {
|
||||
|
||||
std::vector<YoggieEngine::Mesh> meshes = std::vector<YoggieEngine::Mesh>();
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LoadModelFile(std::filesystem::path path) {
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile(path.string(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||
aiNode* currentNode = scene->mRootNode;
|
||||
auto meshes = processNode(currentNode, scene);
|
||||
}
|
||||
|
||||
bool IsSupportedImageFormat(const std::string& extension) {
|
||||
static std::vector<std::string> supported_image_extensions = { "jpeg", "jpg", "png","bmp","hdr","psd","tga","gif","pic","psd","pgm","ppm" };
|
||||
|
||||
for (auto support_extension : supported_image_extensions) {
|
||||
if (extension == support_extension)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Asset AssetImporter::ImportAsset(AssetMetadata& metadata) {
|
||||
|
||||
static Asset emptyAsset;
|
||||
|
||||
|
||||
// Check file extension so we can choose our loader
|
||||
if (metadata.filepath.has_extension() == true)
|
||||
{
|
||||
spdlog::error("Asset file has no extension!");
|
||||
}
|
||||
|
||||
const auto extension = metadata.filepath.extension().string();
|
||||
|
||||
// Handle as Model file
|
||||
bool IsSupportedModelFile = importer.IsExtensionSupported(extension);
|
||||
if (IsSupportedModelFile) {
|
||||
LoadModelFile(metadata.filepath);
|
||||
return emptyAsset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Handle as Texture
|
||||
if (IsSupportedImageFormat(extension))
|
||||
{
|
||||
Texture texture;
|
||||
texture.Load(metadata.filepath.string());
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Handle as shader
|
||||
if (extension == "glsl" || extension == "vert" || extension == "frag") {
|
||||
//Shader shader;
|
||||
//shader.
|
||||
return emptyAsset;
|
||||
}
|
||||
|
||||
return emptyAsset;
|
||||
|
||||
}
|
||||
};
|
12
YoggieEngine/src/Assets/AssetImporter.h
Normal file
12
YoggieEngine/src/Assets/AssetImporter.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "AssetMetadata.h"
|
||||
#include <assimp/Importer.hpp>
|
||||
namespace YoggieEngine{
|
||||
class AssetImporter {
|
||||
public:
|
||||
static Asset ImportAsset(AssetMetadata& metadata);
|
||||
private:
|
||||
static Assimp::Importer importer;
|
||||
|
||||
};
|
||||
}
|
16
YoggieEngine/src/Assets/AssetManager.h
Normal file
16
YoggieEngine/src/Assets/AssetManager.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include "AssetMetaData.h"
|
||||
|
||||
typedef std::map<AssetHandle, AssetMetadata> AssetRegistry;
|
||||
|
||||
class AssetManager {
|
||||
public:
|
||||
virtual Asset& GetAsset(AssetHandle handle) = 0;
|
||||
|
||||
protected:
|
||||
AssetRegistry Assets;
|
||||
std::map<AssetHandle, Asset> LoadedAssets;
|
||||
|
||||
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user