From 5a06b068f3c23bfc0a7e4bf742c829b280a1275f Mon Sep 17 00:00:00 2001 From: nigel Date: Sat, 6 Aug 2022 18:21:42 +0200 Subject: [PATCH] Moving source files to a src folder --- BarinkEngine/Include/Scene/SceneBuilder.h | 3 +- BarinkEngine/premake5.lua | 8 +- BarinkEngine/{ => src}/BarinkEngine.cpp | 128 +++++----- .../{ => src}/EventSystem/EventEmitter.cpp | 0 .../{graphics => src/Graphics}/Buffer.cpp | 92 +++---- .../{graphics => src/Graphics}/Camera.cpp | 0 .../Graphics}/GUI/GUIManager.cpp | 0 .../{graphics => src/Graphics}/Material.cpp | 18 +- .../Graphics}/ModelImporter.cpp | 186 +++++++------- .../Graphics}/RenderSurface.cpp | 0 .../{graphics => src/Graphics}/Renderable.cpp | 106 ++++---- .../{graphics => src/Graphics}/Renderer.cpp | 50 ++-- .../{graphics => src/Graphics}/Shader.cpp | 0 .../{graphics => src/Graphics}/Texture.cpp | 78 +++--- .../Graphics}/VertexArray.cpp | 50 ++-- .../shaders/RenderSurfaceFrag.shader | 0 .../shaders/RenderSurfaceVert.shader | 0 .../Graphics}/shaders/fragment.shader | 20 +- .../Graphics}/shaders/vertex.shader | 0 .../{graphics => src/Graphics}/window.cpp | 166 ++++++------ BarinkEngine/{ => src}/Input/InputManager.cpp | 236 +++++++++--------- BarinkEngine/{ => src}/Scene.cpp | 0 BarinkEngine/{ => src}/Scene/Node.cpp | 0 BarinkEngine/{ => src}/Scene/SceneManager.cpp | 0 .../{ => src}/Scene/SceneNodeTypes.cpp | 0 .../{ => src}/Scripting/LuaScript.cpp | 0 .../Scripting/LuaScriptingManager.cpp | 0 SandboxApplication/GUI.cpp | 33 +-- 28 files changed, 589 insertions(+), 585 deletions(-) rename BarinkEngine/{ => src}/BarinkEngine.cpp (93%) rename BarinkEngine/{ => src}/EventSystem/EventEmitter.cpp (100%) rename BarinkEngine/{graphics => src/Graphics}/Buffer.cpp (94%) rename BarinkEngine/{graphics => src/Graphics}/Camera.cpp (100%) rename BarinkEngine/{graphics => src/Graphics}/GUI/GUIManager.cpp (100%) rename BarinkEngine/{graphics => src/Graphics}/Material.cpp (94%) rename BarinkEngine/{graphics => src/Graphics}/ModelImporter.cpp (96%) rename BarinkEngine/{graphics => src/Graphics}/RenderSurface.cpp (100%) rename BarinkEngine/{graphics => src/Graphics}/Renderable.cpp (96%) rename BarinkEngine/{graphics => src/Graphics}/Renderer.cpp (93%) rename BarinkEngine/{graphics => src/Graphics}/Shader.cpp (100%) rename BarinkEngine/{graphics => src/Graphics}/Texture.cpp (96%) rename BarinkEngine/{graphics => src/Graphics}/VertexArray.cpp (95%) rename BarinkEngine/{graphics => src/Graphics}/shaders/RenderSurfaceFrag.shader (100%) rename BarinkEngine/{graphics => src/Graphics}/shaders/RenderSurfaceVert.shader (100%) rename BarinkEngine/{graphics => src/Graphics}/shaders/fragment.shader (94%) rename BarinkEngine/{graphics => src/Graphics}/shaders/vertex.shader (100%) rename BarinkEngine/{graphics => src/Graphics}/window.cpp (94%) rename BarinkEngine/{ => src}/Input/InputManager.cpp (95%) rename BarinkEngine/{ => src}/Scene.cpp (100%) rename BarinkEngine/{ => src}/Scene/Node.cpp (100%) rename BarinkEngine/{ => src}/Scene/SceneManager.cpp (100%) rename BarinkEngine/{ => src}/Scene/SceneNodeTypes.cpp (100%) rename BarinkEngine/{ => src}/Scripting/LuaScript.cpp (100%) rename BarinkEngine/{ => src}/Scripting/LuaScriptingManager.cpp (100%) diff --git a/BarinkEngine/Include/Scene/SceneBuilder.h b/BarinkEngine/Include/Scene/SceneBuilder.h index ab459de..9c0af66 100644 --- a/BarinkEngine/Include/Scene/SceneBuilder.h +++ b/BarinkEngine/Include/Scene/SceneBuilder.h @@ -3,12 +3,13 @@ #include "Scene/SceneNodeTypes.h" #include +#include "../../src/Scene/SceneNodeTypes.cpp" /* * Define a helper class to more easily build a proper scene */ static class SceneBuilder { static Group* AddGroup(std::string name); - static SceneObject* AddVisual(std::string name, Renderable& object, glm::vec3 position ); + static BarinkEngine::SceneObject* AddVisual(std::string name, BarinkEngine::Renderable& object, glm::vec3 position ); }; \ No newline at end of file diff --git a/BarinkEngine/premake5.lua b/BarinkEngine/premake5.lua index 45c6dc6..a919578 100644 --- a/BarinkEngine/premake5.lua +++ b/BarinkEngine/premake5.lua @@ -52,10 +52,10 @@ project "BarinkEngine" files { "../libs/glad/src/glad.c", - "./*.cpp", - "./*.h", - "./**/*.cpp", - "./**/*.h" + "./src/*.cpp", + "./Include/*.h", + "./src/**/*.cpp", + "./Include/**/*.h" } diff --git a/BarinkEngine/BarinkEngine.cpp b/BarinkEngine/src/BarinkEngine.cpp similarity index 93% rename from BarinkEngine/BarinkEngine.cpp rename to BarinkEngine/src/BarinkEngine.cpp index 914eebf..a49800d 100644 --- a/BarinkEngine/BarinkEngine.cpp +++ b/BarinkEngine/src/BarinkEngine.cpp @@ -1,64 +1,64 @@ -#include "BarinkEngine.h" -#include - -EngineStatistics* ES; -BarinkEngine::InputManager InputSystem; - -int main(int argc, char* argv[]) { - // Setup performance sampler - PerfomanceSamplerInit(); - - - // Startup services - BarinkWindow MainWindow = BarinkWindow(800, 600); - - BarinkEngine::Renderer renderer = BarinkEngine::Renderer(); - InputSystem = BarinkEngine::InputManager(); - - InputSystem.attach(&MainWindow); - - GUIManager GUISystem = GUIManager(&MainWindow); - - - glEnable(GL_DEPTH_TEST); - - - - // First call to setup game - Start(); - - - - // Runtime loop - while (!MainWindow.WindowShouldClose()) { - - SamplePerformance(); - - - // Execute main logic - InputSystem.PollEvents(); - - Update(); - - renderer.Render(); - - ImmediateGraphicsDraw(); - - GUISystem.Render(); - - - - MainWindow.SwapBuffers(); - } - - - // Shutdown game - Stop(); - - - // Shutdown Services - delete ES; - - return 0; -} - +#include "BarinkEngine.h" +#include + +EngineStatistics* ES; +BarinkEngine::InputManager InputSystem; + +int main(int argc, char* argv[]) { + // Setup performance sampler + PerfomanceSamplerInit(); + + + // Startup services + BarinkWindow MainWindow = BarinkWindow(800, 600); + + BarinkEngine::Renderer renderer = BarinkEngine::Renderer(); + InputSystem = BarinkEngine::InputManager(); + + InputSystem.attach(&MainWindow); + + GUIManager GUISystem = GUIManager(&MainWindow); + + + glEnable(GL_DEPTH_TEST); + + + + // First call to setup game + Start(); + + + + // Runtime loop + while (!MainWindow.WindowShouldClose()) { + + SamplePerformance(); + + + // Execute main logic + InputSystem.PollEvents(); + + Update(); + + renderer.Render(); + + ImmediateGraphicsDraw(); + + GUISystem.Render(); + + + + MainWindow.SwapBuffers(); + } + + + // Shutdown game + Stop(); + + + // Shutdown Services + delete ES; + + return 0; +} + diff --git a/BarinkEngine/EventSystem/EventEmitter.cpp b/BarinkEngine/src/EventSystem/EventEmitter.cpp similarity index 100% rename from BarinkEngine/EventSystem/EventEmitter.cpp rename to BarinkEngine/src/EventSystem/EventEmitter.cpp diff --git a/BarinkEngine/graphics/Buffer.cpp b/BarinkEngine/src/Graphics/Buffer.cpp similarity index 94% rename from BarinkEngine/graphics/Buffer.cpp rename to BarinkEngine/src/Graphics/Buffer.cpp index 0f0a23e..9071098 100644 --- a/BarinkEngine/graphics/Buffer.cpp +++ b/BarinkEngine/src/Graphics/Buffer.cpp @@ -1,47 +1,47 @@ -#include "Graphics/Buffer.h" - - -int GpuBuffer::getBufferID() { - return id; -} - -void GpuBuffer::createBuffer() { - glGenBuffers(1, (GLuint*) &id); -} - -void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) { - - if (elementBuffer) { - glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW); - - } - else { - glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW); - } - -} - -void GpuBuffer::Bind(bool elementBuffer = false ) { - if (elementBuffer) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id); - - } - else { - glBindBuffer(GL_ARRAY_BUFFER, id); - - } -} - -void GpuBuffer::Unbind(bool elementBuffer = false) { - if (elementBuffer) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - } - else { - glBindBuffer(GL_ARRAY_BUFFER, 0); - - } -} - -void GpuBuffer::Delete() { - glDeleteBuffers(1, (GLuint*) &id); +#include "Graphics/Buffer.h" + + +int GpuBuffer::getBufferID() { + return id; +} + +void GpuBuffer::createBuffer() { + glGenBuffers(1, (GLuint*) &id); +} + +void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) { + + if (elementBuffer) { + glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW); + + } + else { + glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW); + } + +} + +void GpuBuffer::Bind(bool elementBuffer = false ) { + if (elementBuffer) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id); + + } + else { + glBindBuffer(GL_ARRAY_BUFFER, id); + + } +} + +void GpuBuffer::Unbind(bool elementBuffer = false) { + if (elementBuffer) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } + else { + glBindBuffer(GL_ARRAY_BUFFER, 0); + + } +} + +void GpuBuffer::Delete() { + glDeleteBuffers(1, (GLuint*) &id); } \ No newline at end of file diff --git a/BarinkEngine/graphics/Camera.cpp b/BarinkEngine/src/Graphics/Camera.cpp similarity index 100% rename from BarinkEngine/graphics/Camera.cpp rename to BarinkEngine/src/Graphics/Camera.cpp diff --git a/BarinkEngine/graphics/GUI/GUIManager.cpp b/BarinkEngine/src/Graphics/GUI/GUIManager.cpp similarity index 100% rename from BarinkEngine/graphics/GUI/GUIManager.cpp rename to BarinkEngine/src/Graphics/GUI/GUIManager.cpp diff --git a/BarinkEngine/graphics/Material.cpp b/BarinkEngine/src/Graphics/Material.cpp similarity index 94% rename from BarinkEngine/graphics/Material.cpp rename to BarinkEngine/src/Graphics/Material.cpp index 8951ad6..06d53cc 100644 --- a/BarinkEngine/graphics/Material.cpp +++ b/BarinkEngine/src/Graphics/Material.cpp @@ -1,10 +1,10 @@ -#include "../Include/Graphics/Material.h" - -Material::Material(const Shader& shader) : -shader(shader) { -} - - -void Material::Apply() { - shader.setUniformVec3("Color", Color); +#include "../Include/Graphics/Material.h" + +Material::Material(const Shader& shader) : +shader(shader) { +} + + +void Material::Apply() { + shader.setUniformVec3("Color", Color); } \ No newline at end of file diff --git a/BarinkEngine/graphics/ModelImporter.cpp b/BarinkEngine/src/Graphics/ModelImporter.cpp similarity index 96% rename from BarinkEngine/graphics/ModelImporter.cpp rename to BarinkEngine/src/Graphics/ModelImporter.cpp index 5a554f0..d353059 100644 --- a/BarinkEngine/graphics/ModelImporter.cpp +++ b/BarinkEngine/src/Graphics/ModelImporter.cpp @@ -1,94 +1,94 @@ -#include "AssetManager/ModelImporter.h" - - -BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path) -{ - - SceneObject* root = new SceneObject(std::string(path), nullptr); - - Assimp::Importer importer; - const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs); - - aiNode* currentNode = scene->mRootNode; - - std::vector meshes = processNode(currentNode, scene); - - return root; - -} - -std::vector BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene) -{ - - std::vector 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 indices; - std::vector vertices; - - ProcessVertices(mesh, vertices); - - ProcessIndices(mesh, indices); - - BarinkEngine::Mesh result; - result.vertices = vertices; - result.elements = indices; - - - return result; - -} - -void ProcessVertices(aiMesh* mesh, std::vector& 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& 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]); - } - } +#include "AssetManager/ModelImporter.h" + + +BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path) +{ + + SceneObject* root = new SceneObject(std::string(path), nullptr); + + Assimp::Importer importer; + const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs); + + aiNode* currentNode = scene->mRootNode; + + std::vector meshes = processNode(currentNode, scene); + + return root; + +} + +std::vector BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene) +{ + + std::vector 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 indices; + std::vector vertices; + + ProcessVertices(mesh, vertices); + + ProcessIndices(mesh, indices); + + BarinkEngine::Mesh result; + result.vertices = vertices; + result.elements = indices; + + + return result; + +} + +void ProcessVertices(aiMesh* mesh, std::vector& 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& 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]); + } + } } \ No newline at end of file diff --git a/BarinkEngine/graphics/RenderSurface.cpp b/BarinkEngine/src/Graphics/RenderSurface.cpp similarity index 100% rename from BarinkEngine/graphics/RenderSurface.cpp rename to BarinkEngine/src/Graphics/RenderSurface.cpp diff --git a/BarinkEngine/graphics/Renderable.cpp b/BarinkEngine/src/Graphics/Renderable.cpp similarity index 96% rename from BarinkEngine/graphics/Renderable.cpp rename to BarinkEngine/src/Graphics/Renderable.cpp index 990136e..7394915 100644 --- a/BarinkEngine/graphics/Renderable.cpp +++ b/BarinkEngine/src/Graphics/Renderable.cpp @@ -1,53 +1,53 @@ -#include "Graphics/Renderable.h" -#include "AssetManager/ModelImporter.h" -#include "PerfCounter.h" - - -BarinkEngine::Renderable::Renderable() -{ - /* - - VAO.Create(); - VAO.Bind(); - - - vertexBuffer.createBuffer(); - vertexBuffer.Bind(false); - vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(BarinkEngine::Vertex), false); - - elementBuffer.createBuffer(); - elementBuffer.Bind(true); - elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true); - - VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex)); - - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices)); - glEnableVertexAttribArray(1); - - //vertexBuffer.Unbind(false); - - VAO.Unbind(); - */ - -} - -BarinkEngine::Renderable::~Renderable() -{ - // glDeleteBuffers(1, &UV_id); -} - -// Draw call Example !! -/* - VAO.Bind(); - elementBuffer.Bind(true); - - glActiveTexture(GL_TEXTURE0); - glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0); - texture->Bind(); - - ES->verts = meshes[0].vertices.size(); - ES->DC++; - glDrawElements(GL_TRIANGLES, static_cast(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL); - VAO.Unbind(); - */ - +#include "Graphics/Renderable.h" +#include "AssetManager/ModelImporter.h" +#include "PerfCounter.h" + + +BarinkEngine::Renderable::Renderable() +{ + /* + + VAO.Create(); + VAO.Bind(); + + + vertexBuffer.createBuffer(); + vertexBuffer.Bind(false); + vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(BarinkEngine::Vertex), false); + + elementBuffer.createBuffer(); + elementBuffer.Bind(true); + elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true); + + VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex)); + + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices)); + glEnableVertexAttribArray(1); + + //vertexBuffer.Unbind(false); + + VAO.Unbind(); + */ + +} + +BarinkEngine::Renderable::~Renderable() +{ + // glDeleteBuffers(1, &UV_id); +} + +// Draw call Example !! +/* + VAO.Bind(); + elementBuffer.Bind(true); + + glActiveTexture(GL_TEXTURE0); + glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0); + texture->Bind(); + + ES->verts = meshes[0].vertices.size(); + ES->DC++; + glDrawElements(GL_TRIANGLES, static_cast(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL); + VAO.Unbind(); + */ + diff --git a/BarinkEngine/graphics/Renderer.cpp b/BarinkEngine/src/Graphics/Renderer.cpp similarity index 93% rename from BarinkEngine/graphics/Renderer.cpp rename to BarinkEngine/src/Graphics/Renderer.cpp index a6d2833..ac6f8a9 100644 --- a/BarinkEngine/graphics/Renderer.cpp +++ b/BarinkEngine/src/Graphics/Renderer.cpp @@ -1,25 +1,25 @@ -#include "Graphics/Renderer.h" - -BarinkEngine::Renderer::Renderer() -{ - models = std::vector(); -} - -BarinkEngine::Renderer::~Renderer() -{ - // CleanUp! -} - -void BarinkEngine::Renderer::Render() -{ - - for (auto model : models) { - //model->Draw(); - } - -} - -void BarinkEngine::Renderer::Submit(Renderable* model) -{ - models.push_back(model); -} +#include "Graphics/Renderer.h" + +BarinkEngine::Renderer::Renderer() +{ + models = std::vector(); +} + +BarinkEngine::Renderer::~Renderer() +{ + // CleanUp! +} + +void BarinkEngine::Renderer::Render() +{ + + for (auto model : models) { + //model->Draw(); + } + +} + +void BarinkEngine::Renderer::Submit(Renderable* model) +{ + models.push_back(model); +} diff --git a/BarinkEngine/graphics/Shader.cpp b/BarinkEngine/src/Graphics/Shader.cpp similarity index 100% rename from BarinkEngine/graphics/Shader.cpp rename to BarinkEngine/src/Graphics/Shader.cpp diff --git a/BarinkEngine/graphics/Texture.cpp b/BarinkEngine/src/Graphics/Texture.cpp similarity index 96% rename from BarinkEngine/graphics/Texture.cpp rename to BarinkEngine/src/Graphics/Texture.cpp index 0af7e6d..63ecffe 100644 --- a/BarinkEngine/graphics/Texture.cpp +++ b/BarinkEngine/src/Graphics/Texture.cpp @@ -1,40 +1,40 @@ -#include "../Include/Graphics/Texture.h" -#include -#include -#define STB_IMAGE_IMPLEMENTATION -#include "Graphics/stb_image.h" -#include - -Texture::Texture(const std::string texturePath) { - - int width, height, channels; - unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0); - std::cout << channels << std::endl; - - if (data) { - glGenTextures(1, &Id); - - glBindTexture(GL_TEXTURE_2D, Id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); - glGenerateMipmap(GL_TEXTURE_2D); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - } - else { - spdlog::error("Failed to load image (%s)", texturePath ); - } - stbi_image_free(data); - -} - -void Texture::Bind() { - glBindTexture(GL_TEXTURE_2D, Id); -} - -void Texture::Unbind() { - glBindTexture(GL_TEXTURE_2D, 0); +#include "../Include/Graphics/Texture.h" +#include +#include +#define STB_IMAGE_IMPLEMENTATION +#include "Graphics/stb_image.h" +#include + +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); } \ No newline at end of file diff --git a/BarinkEngine/graphics/VertexArray.cpp b/BarinkEngine/src/Graphics/VertexArray.cpp similarity index 95% rename from BarinkEngine/graphics/VertexArray.cpp rename to BarinkEngine/src/Graphics/VertexArray.cpp index edfb031..01d9c70 100644 --- a/BarinkEngine/graphics/VertexArray.cpp +++ b/BarinkEngine/src/Graphics/VertexArray.cpp @@ -1,25 +1,25 @@ -#include "Graphics/VertexArray.h" -#include - -void VertexArray::Create(){ - glGenVertexArrays(1, &id); -} - -void VertexArray::Bind(){ - glBindVertexArray(id); -} - -void VertexArray::Unbind(){ - glBindVertexArray(0); -} - -void VertexArray::Delete() { - glDeleteVertexArrays(1, &id); -} - - -void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){ - glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0); - glEnableVertexAttribArray(0); -} - +#include "Graphics/VertexArray.h" +#include + +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); +} + diff --git a/BarinkEngine/graphics/shaders/RenderSurfaceFrag.shader b/BarinkEngine/src/Graphics/shaders/RenderSurfaceFrag.shader similarity index 100% rename from BarinkEngine/graphics/shaders/RenderSurfaceFrag.shader rename to BarinkEngine/src/Graphics/shaders/RenderSurfaceFrag.shader diff --git a/BarinkEngine/graphics/shaders/RenderSurfaceVert.shader b/BarinkEngine/src/Graphics/shaders/RenderSurfaceVert.shader similarity index 100% rename from BarinkEngine/graphics/shaders/RenderSurfaceVert.shader rename to BarinkEngine/src/Graphics/shaders/RenderSurfaceVert.shader diff --git a/BarinkEngine/graphics/shaders/fragment.shader b/BarinkEngine/src/Graphics/shaders/fragment.shader similarity index 94% rename from BarinkEngine/graphics/shaders/fragment.shader rename to BarinkEngine/src/Graphics/shaders/fragment.shader index 8ffc39b..92cc822 100644 --- a/BarinkEngine/graphics/shaders/fragment.shader +++ b/BarinkEngine/src/Graphics/shaders/fragment.shader @@ -1,11 +1,11 @@ -#version 440 core - -out vec4 FragColor; -uniform vec3 Color; -in vec2 TexCoord; -uniform sampler2D Texture; - - -void main(){ - FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f); +#version 440 core + +out vec4 FragColor; +uniform vec3 Color; +in vec2 TexCoord; +uniform sampler2D Texture; + + +void main(){ + FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f); } \ No newline at end of file diff --git a/BarinkEngine/graphics/shaders/vertex.shader b/BarinkEngine/src/Graphics/shaders/vertex.shader similarity index 100% rename from BarinkEngine/graphics/shaders/vertex.shader rename to BarinkEngine/src/Graphics/shaders/vertex.shader diff --git a/BarinkEngine/graphics/window.cpp b/BarinkEngine/src/Graphics/window.cpp similarity index 94% rename from BarinkEngine/graphics/window.cpp rename to BarinkEngine/src/Graphics/window.cpp index 3843a0c..d61153c 100644 --- a/BarinkEngine/graphics/window.cpp +++ b/BarinkEngine/src/Graphics/window.cpp @@ -1,84 +1,84 @@ -#include "Graphics/Window.h" -#include -#include -#include -#include -#include -#include "../Include/EventSystem/Event.h" - -bool BarinkWindow::InitGLFW(){ - if(!glfwInit()) - { - spdlog::error("Failed to initialise GLFW!"); - return false; - } - - return true; -} - -BarinkWindow::BarinkWindow(const int width, const int height) : -Width(width), Height(height), FullScreen(false){ - if (InitGLFW()==false) { - exit(-1); - } - - window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL); - - if( !window) - { - spdlog::error("GLFW failed to create window!"); - glfwTerminate(); - return; - } - - glfwMakeContextCurrent(window); - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { - printf("Failed to initialize GLAD!\n"); - exit(-1); - } - - // Set vsync off !! - glfwSwapInterval(0); - - VulkanSupported = glfwVulkanSupported(); - - glfwGetFramebufferSize(window, &Width, &Height); - glViewport(0,0, Width, Height); - - - - glClearColor(0.2f, 0.2f, 0.2f, 1.0f); - -} - - -BarinkWindow::~BarinkWindow(){ - - glfwTerminate(); -} - -GLFWwindow* BarinkWindow::windowptr() -{ - return window; -} - -bool BarinkWindow::WindowShouldClose(){ - return glfwWindowShouldClose(window); -} - -void BarinkWindow::Poll() -{ - glfwPollEvents(); -} - -void BarinkWindow::SwapBuffers() -{ - glfwSwapBuffers(window); -} - - -void BarinkWindow::ReceiveEvent(Event& incident) -{ - std::cout << "EVENT RECEIVED: " << incident.name << std::endl; - +#include "Graphics/Window.h" +#include +#include +#include +#include +#include +#include "../Include/EventSystem/Event.h" + +bool BarinkWindow::InitGLFW(){ + if(!glfwInit()) + { + spdlog::error("Failed to initialise GLFW!"); + return false; + } + + return true; +} + +BarinkWindow::BarinkWindow(const int width, const int height) : +Width(width), Height(height), FullScreen(false){ + if (InitGLFW()==false) { + exit(-1); + } + + window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL); + + if( !window) + { + spdlog::error("GLFW failed to create window!"); + glfwTerminate(); + return; + } + + glfwMakeContextCurrent(window); + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { + printf("Failed to initialize GLAD!\n"); + exit(-1); + } + + // Set vsync off !! + glfwSwapInterval(0); + + VulkanSupported = glfwVulkanSupported(); + + glfwGetFramebufferSize(window, &Width, &Height); + glViewport(0,0, Width, Height); + + + + glClearColor(0.2f, 0.2f, 0.2f, 1.0f); + +} + + +BarinkWindow::~BarinkWindow(){ + + glfwTerminate(); +} + +GLFWwindow* BarinkWindow::windowptr() +{ + return window; +} + +bool BarinkWindow::WindowShouldClose(){ + return glfwWindowShouldClose(window); +} + +void BarinkWindow::Poll() +{ + glfwPollEvents(); +} + +void BarinkWindow::SwapBuffers() +{ + glfwSwapBuffers(window); +} + + +void BarinkWindow::ReceiveEvent(Event& incident) +{ + std::cout << "EVENT RECEIVED: " << incident.name << std::endl; + } \ No newline at end of file diff --git a/BarinkEngine/Input/InputManager.cpp b/BarinkEngine/src/Input/InputManager.cpp similarity index 95% rename from BarinkEngine/Input/InputManager.cpp rename to BarinkEngine/src/Input/InputManager.cpp index 9922080..ba0f8b2 100644 --- a/BarinkEngine/Input/InputManager.cpp +++ b/BarinkEngine/src/Input/InputManager.cpp @@ -1,118 +1,118 @@ -#include "BarinkEngine.h" -#include "Input/InputManager.h" -#include "GLFW/glfw3.h" -#include "spdlog/spdlog.h" -#include -void BarinkEngine::InputManager::PollEvents() -{ - for (auto it = windows.begin(); it != windows.end(); ++it) { - (*it)->Poll(); - } -} - -void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) -{ - - Event KeyEvent{}; - KeyEvent.name = "KEY"; - - InputSystem.EmitEvent(KeyEvent); - - - if (key == GLFW_KEY_A && action == GLFW_PRESS) - { - - std::cout << "'a' key was pressed" << std::endl; - } - -} - -void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y) -{ - //std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl; - Event CursorPosUpdate{}; - CursorPosUpdate.name = "UPDATE::CURSOR:POSITION"; - - InputSystem.EmitEvent(CursorPosUpdate); - - - -} - -void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered) -{ - if (entered) { - Event mouseEntered {}; - mouseEntered.name = "Mouse Entered Window's confines!"; - mouseEntered.argc = 0; - - InputSystem.EmitEvent(mouseEntered); - - - - } - else { - Event mouseLeft{}; - mouseLeft.name = "Mouse Left Window's confines!"; - mouseLeft.argc = 0; - - InputSystem.EmitEvent(mouseLeft); - - - } -} - - -void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) -{ - - Event MouseButtonEvent{}; - MouseButtonEvent.name = "MOUSEBUTTON"; - - InputSystem.EmitEvent(MouseButtonEvent); - - - if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) { - std::cout << "Right mouse button was pressed!" << std::endl; - } - -} - -void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) -{ - std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl; - - Event ScrollEvent{}; - ScrollEvent.name = "SCROLL"; - - InputSystem.EmitEvent(ScrollEvent); - - -} - - -void BarinkEngine::InputManager::attach(BarinkWindow* window) -{ - - windows.push_back(window); - - // Attach callbacks - glfwSetKeyCallback(window->windowptr(), KeyCallback); - glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback); - glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback); - glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback); - glfwSetScrollCallback(window->windowptr(), ScrollCallback); - - this->Subscribe( (EventListener&)(*window)); - - - -} - -BarinkEngine::InputManager::InputManager() : EventEmitter () -{ - windows = std::vector(); -} - - - +#include "BarinkEngine.h" +#include "Input/InputManager.h" +#include "GLFW/glfw3.h" +#include "spdlog/spdlog.h" +#include +void BarinkEngine::InputManager::PollEvents() +{ + for (auto it = windows.begin(); it != windows.end(); ++it) { + (*it)->Poll(); + } +} + +void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) +{ + + Event KeyEvent{}; + KeyEvent.name = "KEY"; + + InputSystem.EmitEvent(KeyEvent); + + + if (key == GLFW_KEY_A && action == GLFW_PRESS) + { + + std::cout << "'a' key was pressed" << std::endl; + } + +} + +void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y) +{ + //std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl; + Event CursorPosUpdate{}; + CursorPosUpdate.name = "UPDATE::CURSOR:POSITION"; + + InputSystem.EmitEvent(CursorPosUpdate); + + + +} + +void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered) +{ + if (entered) { + Event mouseEntered {}; + mouseEntered.name = "Mouse Entered Window's confines!"; + mouseEntered.argc = 0; + + InputSystem.EmitEvent(mouseEntered); + + + + } + else { + Event mouseLeft{}; + mouseLeft.name = "Mouse Left Window's confines!"; + mouseLeft.argc = 0; + + InputSystem.EmitEvent(mouseLeft); + + + } +} + + +void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) +{ + + Event MouseButtonEvent{}; + MouseButtonEvent.name = "MOUSEBUTTON"; + + InputSystem.EmitEvent(MouseButtonEvent); + + + if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) { + std::cout << "Right mouse button was pressed!" << std::endl; + } + +} + +void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) +{ + std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl; + + Event ScrollEvent{}; + ScrollEvent.name = "SCROLL"; + + InputSystem.EmitEvent(ScrollEvent); + + +} + + +void BarinkEngine::InputManager::attach(BarinkWindow* window) +{ + + windows.push_back(window); + + // Attach callbacks + glfwSetKeyCallback(window->windowptr(), KeyCallback); + glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback); + glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback); + glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback); + glfwSetScrollCallback(window->windowptr(), ScrollCallback); + + this->Subscribe( (EventListener&)(*window)); + + + +} + +BarinkEngine::InputManager::InputManager() : EventEmitter () +{ + windows = std::vector(); +} + + + diff --git a/BarinkEngine/Scene.cpp b/BarinkEngine/src/Scene.cpp similarity index 100% rename from BarinkEngine/Scene.cpp rename to BarinkEngine/src/Scene.cpp diff --git a/BarinkEngine/Scene/Node.cpp b/BarinkEngine/src/Scene/Node.cpp similarity index 100% rename from BarinkEngine/Scene/Node.cpp rename to BarinkEngine/src/Scene/Node.cpp diff --git a/BarinkEngine/Scene/SceneManager.cpp b/BarinkEngine/src/Scene/SceneManager.cpp similarity index 100% rename from BarinkEngine/Scene/SceneManager.cpp rename to BarinkEngine/src/Scene/SceneManager.cpp diff --git a/BarinkEngine/Scene/SceneNodeTypes.cpp b/BarinkEngine/src/Scene/SceneNodeTypes.cpp similarity index 100% rename from BarinkEngine/Scene/SceneNodeTypes.cpp rename to BarinkEngine/src/Scene/SceneNodeTypes.cpp diff --git a/BarinkEngine/Scripting/LuaScript.cpp b/BarinkEngine/src/Scripting/LuaScript.cpp similarity index 100% rename from BarinkEngine/Scripting/LuaScript.cpp rename to BarinkEngine/src/Scripting/LuaScript.cpp diff --git a/BarinkEngine/Scripting/LuaScriptingManager.cpp b/BarinkEngine/src/Scripting/LuaScriptingManager.cpp similarity index 100% rename from BarinkEngine/Scripting/LuaScriptingManager.cpp rename to BarinkEngine/src/Scripting/LuaScriptingManager.cpp diff --git a/SandboxApplication/GUI.cpp b/SandboxApplication/GUI.cpp index 733fb66..bdeb0ad 100644 --- a/SandboxApplication/GUI.cpp +++ b/SandboxApplication/GUI.cpp @@ -1,30 +1,33 @@ #include "GUI.h" void SceneExplorer(Scene& scene, std::string PanelName) { - ImGui::Begin(PanelName.c_str()); + if (ImGui::Begin(PanelName.c_str())) { + ImGui::ListBoxHeader("##ObjectList"); - ImGui::ListBoxHeader("##ObjectList"); + Node& current = scene.GetRoot(); - Node& current = scene.GetRoot(); + Node* next = ¤t; - Node* next = ¤t; + // Show first node + ImGui::Selectable(next->name.c_str(), true); - // Show first node - ImGui::Selectable(next->name.c_str(), true); + ImGui::Indent(); - ImGui::Indent(); - - if (next->children.size() != 0) { - for (auto child : next->children) - { - std::string& name = child->name; - ImGui::Selectable(name.c_str(), false); + if (next->children.size() != 0) { + for (auto child : next->children) + { + std::string& name = child->name; + ImGui::Selectable(name.c_str(), false); + } } - } - ImGui::ListBoxFooter(); + ImGui::ListBoxFooter(); + + } ImGui::End(); + + } void CameraTool(Camera* cam) {