diff --git a/BarinkEngine/BarinkEngine.cpp b/BarinkEngine/BarinkEngine.cpp index ab7c038..d613cdb 100644 --- a/BarinkEngine/BarinkEngine.cpp +++ b/BarinkEngine/BarinkEngine.cpp @@ -1,31 +1,64 @@ #include "BarinkEngine.h" +#include extern void Start(int argc, char* argv[]); -extern void UpdateApplication(); +extern void Update(); +extern void Stop(); using namespace BarinkEngine; +void DrawMyGUI(); -bool ShouldQuit = false; +BarinkWindow* MainWindow; int main(int argc, char* argv[]) { - // Start Engine - Engine::Startup(); + // Startup services + MainWindow = new BarinkWindow(800, 600); + Renderer renderer = Renderer(); + InputManager InputSystem = InputManager(); + + + InputSystem.attach(MainWindow); + + GUIManager GUISystem = GUIManager(MainWindow); + + + + + // First call to setup game Start(argc, argv); - while (!ShouldQuit) { - //InputManager::PollEvents(); + // Runtime loop + while (!MainWindow->WindowShouldClose()) { + InputSystem.PollEvents(); + + Update(); - UpdateApplication(); + + renderer.Render(); + + + DrawMyGUI(); + + GUISystem.Render(); + + + + + MainWindow->SwapBuffers(); } + // Shutdown game + + Stop(); - // Kill Engine - Engine::Shutdown(); + // Shutdown Services + delete MainWindow; + return 0; } @@ -33,5 +66,41 @@ int main(int argc, char* argv[]) { void WARN(std::string message) { spdlog::warn(message); +} + + +void DrawMyGUI() { + ImGui::NewFrame(); + + ImGui::Begin("Transform"); + ImGui::Text("Cube"); + /* + ImGui::InputFloat3("Position:", (float*)nullptr); + ImGui::InputFloat3("Rotation:", (float*)nullptr); + ImGui::InputFloat3("Scale:", (float*)nullptr); + + */ + + ImGui::End(); + + ImGui::Begin("Camera"); + + //ImGui::SliderFloat("Zoom:", &NULL, 10, 190); + + ImGui::End(); + + + ImGui::Begin("Scripting!!"); + + //ImGui::InputTextMultiline("Lua Script", nullptr, 255); + //runCode = ImGui::Button("Run"); + + + ImGui::End(); + + + ImGui::ShowDemoWindow(); } + + diff --git a/BarinkEngine/Engine.cpp b/BarinkEngine/Engine.cpp deleted file mode 100644 index fbd6e29..0000000 --- a/BarinkEngine/Engine.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "include/BarinkEngine.h" -namespace BarinkEngine { - void Engine::Startup() { - std::cout << "Starting Engine! vroom vroom!" << std::endl; - } - - void Engine::Shutdown() { - std::cout << "ShutDown Engine!" << std::endl; - } -}; diff --git a/BarinkEngine/Include/BarinkEngine.h b/BarinkEngine/Include/BarinkEngine.h index 88f1203..d377364 100644 --- a/BarinkEngine/Include/BarinkEngine.h +++ b/BarinkEngine/Include/BarinkEngine.h @@ -3,23 +3,18 @@ #include #include - -#include "Engine.h" #include "glm/glm.hpp" - #include "graphics/Shader.h" #include "graphics/Window.h" #include "graphics/Camera.h" #include "graphics/Renderable.h" #include "spdlog/spdlog.h" -#include "MemoryManager.h" +#include "Input/InputManager.h" +#include "Graphics/Renderer.h" +#include "Graphics/GUI/GUIManager.h" + +void WARN(std::string message); + -extern "C" -{ - #include "lauxlib.h" - #include "lua.h" - #include "lualib.h" -} -void WARN(std::string message); \ No newline at end of file diff --git a/BarinkEngine/Include/Engine.h b/BarinkEngine/Include/Engine.h deleted file mode 100644 index 069e8d4..0000000 --- a/BarinkEngine/Include/Engine.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -namespace BarinkEngine { - -class Engine { - public: - static void Startup(); - static void Shutdown(); - - }; -}; diff --git a/BarinkEngine/Include/Graphics/GUI/GUIManager.h b/BarinkEngine/Include/Graphics/GUI/GUIManager.h new file mode 100644 index 0000000..4eaa079 --- /dev/null +++ b/BarinkEngine/Include/Graphics/GUI/GUIManager.h @@ -0,0 +1,15 @@ +#pragma once +#include "Graphics/Window.h" + + +class GUIManager { +public: + GUIManager(BarinkWindow* window); + ~GUIManager(); + + void Render(); + + +private: + BarinkWindow* currentwindow; +}; \ No newline at end of file diff --git a/BarinkEngine/Include/Graphics/Renderable.h b/BarinkEngine/Include/Graphics/Renderable.h index 48b537f..b7d4fd3 100644 --- a/BarinkEngine/Include/Graphics/Renderable.h +++ b/BarinkEngine/Include/Graphics/Renderable.h @@ -13,10 +13,6 @@ */ class Renderable { -private: - std::vector meshes; - Renderable(); - public: Buffer vertexBuffer; Buffer elementBuffer; @@ -27,4 +23,7 @@ public: static Renderable Load(); void Draw(); +private: + std::vector meshes; + Renderable(); }; \ No newline at end of file diff --git a/BarinkEngine/Include/Graphics/Renderer.h b/BarinkEngine/Include/Graphics/Renderer.h new file mode 100644 index 0000000..dad948a --- /dev/null +++ b/BarinkEngine/Include/Graphics/Renderer.h @@ -0,0 +1,21 @@ +#pragma once +#include "Graphics/Renderable.h" + +#include + +namespace BarinkEngine { + + class Renderer { + public: + Renderer(); + ~Renderer(); + + void Render(); + + void Submit(Renderable* model); + + private: + std::vector models; + + }; +} diff --git a/BarinkEngine/Include/Input/InputManager.h b/BarinkEngine/Include/Input/InputManager.h new file mode 100644 index 0000000..74f5524 --- /dev/null +++ b/BarinkEngine/Include/Input/InputManager.h @@ -0,0 +1,18 @@ +#pragma once +#include + +#include "Graphics/Window.h" + +namespace BarinkEngine { + + class InputManager { + public: + InputManager(); + + void PollEvents(); + void attach(BarinkWindow* window); + + private: + std::vector windows; + }; +} diff --git a/BarinkEngine/Include/MemoryManager.h b/BarinkEngine/Include/MemoryManager.h deleted file mode 100644 index d8fb12e..0000000 --- a/BarinkEngine/Include/MemoryManager.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include -#include - -static int HeapAllocations = 0; -static int HeapDeallocations = 0; - -inline void* operator new(std::size_t sz) { - HeapAllocations++; - return std::malloc(sz); -} - -inline void operator delete(void* ptr) noexcept { - HeapDeallocations++; - std::free(ptr); -} - diff --git a/BarinkEngine/Include/Scripting/LuaScript.h b/BarinkEngine/Include/Scripting/LuaScript.h new file mode 100644 index 0000000..54806eb --- /dev/null +++ b/BarinkEngine/Include/Scripting/LuaScript.h @@ -0,0 +1,28 @@ +#pragma once +#include + +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; + +}; + + +*/ \ No newline at end of file diff --git a/BarinkEngine/Include/Scripting/LuaScriptingManager.h b/BarinkEngine/Include/Scripting/LuaScriptingManager.h new file mode 100644 index 0000000..fdbab4e --- /dev/null +++ b/BarinkEngine/Include/Scripting/LuaScriptingManager.h @@ -0,0 +1,28 @@ +#pragma once +#include + +extern "C" +{ + #include "lauxlib.h" + #include "lua.h" + #include "lualib.h" +} + + +#include "LuaScript.h" + +/* +class LuaScriptingManager +{ +public: + std::vector scripts; + + LuaScriptingManager(); + + void ExecuteLuaString(const std::string&); + +private: + lua_State* L; + + lua_State& getState(); +};*/ \ No newline at end of file diff --git a/BarinkEngine/Input/InputManager.cpp b/BarinkEngine/Input/InputManager.cpp new file mode 100644 index 0000000..66b5336 --- /dev/null +++ b/BarinkEngine/Input/InputManager.cpp @@ -0,0 +1,19 @@ +#include "Input/InputManager.h" + +void BarinkEngine::InputManager::PollEvents() +{ + + for (std::vector::iterator it = windows.begin(); it != windows.end(); ++it) { + (*it)->Poll(); + } +} + +void BarinkEngine::InputManager::attach(BarinkWindow* window) +{ + windows.push_back(window); +} + +BarinkEngine::InputManager::InputManager() +{ + windows = std::vector(); +} diff --git a/BarinkEngine/Scripting/LuaScript.cpp b/BarinkEngine/Scripting/LuaScript.cpp new file mode 100644 index 0000000..8e63a74 --- /dev/null +++ b/BarinkEngine/Scripting/LuaScript.cpp @@ -0,0 +1,11 @@ +#include "Scripting/LuaScript.h" +/* +LuaScript::LuaScript(const std::string& path) +: filePath(path) { +} + +void LuaScript::execute(lua_State& l) +{ + luaL_dofile(&l, filePath.c_str()); +} +*/ \ No newline at end of file diff --git a/BarinkEngine/Scripting/LuaScriptingManager.cpp b/BarinkEngine/Scripting/LuaScriptingManager.cpp new file mode 100644 index 0000000..f005bb9 --- /dev/null +++ b/BarinkEngine/Scripting/LuaScriptingManager.cpp @@ -0,0 +1,18 @@ +#include "Scripting/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); +} +*/ \ No newline at end of file diff --git a/BarinkEngine/graphics/GUI/GUIManager.cpp b/BarinkEngine/graphics/GUI/GUIManager.cpp new file mode 100644 index 0000000..c1e9d99 --- /dev/null +++ b/BarinkEngine/graphics/GUI/GUIManager.cpp @@ -0,0 +1,38 @@ +#include "Graphics/GUI/GUIManager.h" +#include "imgui.h" +#include "backends/imgui_impl_opengl3.h" +#include + +GUIManager::GUIManager(BarinkWindow* window) + : currentwindow(window) +{ + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + (void)io; + + ImGui::StyleColorsDark(); + ImGui_ImplGlfw_InitForOpenGL(currentwindow->windowptr(), true); + ImGui_ImplOpenGL3_Init("#version 440"); + + + ImGui_ImplGlfw_NewFrame(); + ImGui_ImplOpenGL3_NewFrame(); + +} + +GUIManager::~GUIManager() +{ + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); +} + + +void GUIManager::Render() +{ + + + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); +} diff --git a/BarinkEngine/graphics/Renderer.cpp b/BarinkEngine/graphics/Renderer.cpp new file mode 100644 index 0000000..38f3b30 --- /dev/null +++ b/BarinkEngine/graphics/Renderer.cpp @@ -0,0 +1,24 @@ +#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/window.cpp b/BarinkEngine/graphics/window.cpp index f189aa0..f4990cf 100644 --- a/BarinkEngine/graphics/window.cpp +++ b/BarinkEngine/graphics/window.cpp @@ -1,12 +1,14 @@ #include "Graphics/Window.h" #include #include +#include +#include bool BarinkWindow::InitGLFW(){ if(!glfwInit()) { -// spdlog::error("Failed to initialise GLFW!"); + spdlog::error("Failed to initialise GLFW!"); return false; } @@ -23,7 +25,7 @@ Width(width), Height(height), FullScreen(false){ if( !window) { -// spdlog::error("GLFW failed to create window!"); + spdlog::error("GLFW failed to create window!"); glfwTerminate(); return; } @@ -43,8 +45,6 @@ Width(width), Height(height), FullScreen(false){ glClearColor(0.2f, 0.2f, 0.2f, 1.0f); - - } @@ -63,8 +63,7 @@ bool BarinkWindow::WindowShouldClose(){ } void BarinkWindow::Poll() -{ - +{ glfwPollEvents(); } diff --git a/SandboxApplication/Sandbox.cpp b/SandboxApplication/Sandbox.cpp index 9bbadc2..826f0be 100644 --- a/SandboxApplication/Sandbox.cpp +++ b/SandboxApplication/Sandbox.cpp @@ -1,146 +1,62 @@ #include "BarinkEngine.h" +using namespace BarinkEngine; +Camera* cam; +Renderable* Cube; +Shader* shader; void Start(int argc, char* argv[]) { - std::cout << "Hello start!" << std::endl; - std::cout << "h" << std::endl; + - char cwd[256]; - memset(cwd, '\0', 256); - // getcwd(cwd, 256); - //spdlog::info("Working directory: {}", cwd); - - WARN("Hello warning"); - - // BarinkWindow GameWindow(800, 600); - -} - -void UpdateApplication() -{ -} - -/* - -int main(int argc, char* argv[]) { - - char cwd[256]; - memset(cwd, '\0', 256); - getcwd(cwd, 256); - spdlog::info("Working directory: {}", cwd); - - - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); - (void)io; - - ImGui::StyleColorsDark(); - ImGui_ImplGlfw_InitForOpenGL(GameWindow.windowptr(), true); - ImGui_ImplOpenGL3_Init("#version 440"); - - Camera cam(glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f); - Renderable Cube = Renderable::Load(); + cam = new Camera (glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f); + Cube = &Renderable::Load(); spdlog::info("==== Load Shader(s) ===="); std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs"; std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs"; - Shader shader (vertexShaderSource, fragmentShaderSource); + shader = new Shader(vertexShaderSource, fragmentShaderSource); - lua_State* L = luaL_newstate(); - luaL_openlibs(L); - luaL_dostring(L, "print('BarinkEngine')"); - spdlog::info("==== Run script ===="); - luaL_dofile(L,"build/SandboxApplication/Debug/script.lua"); - - - - char* lua_code = new char[255]; - memset(lua_code, '\0', 255); - - bool runCode = false; - - - while (!GameWindow.WindowShouldClose()) { - if (runCode == true) { - luaL_dostring(L,lua_code); - runCode = false; - } - - glm::mat4 tran = glm::translate(glm::mat4(), Cube.transform.Position); - glm::mat4 scale = glm::scale(glm::mat4(), Cube.transform.Scale); - glm::mat4 rot = - glm::rotate(glm::mat4(), glm::radians(Cube.transform.Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) * - glm::rotate(glm::mat4(), glm::radians(Cube.transform.Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) * - glm::rotate(glm::mat4(), glm::radians(Cube.transform.Rotation.z), glm::vec3(0.0f, 0.0f, 1.0f)); - - - glm::mat4 model = tran * rot * scale; - - glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f); - - - GameWindow.Poll(); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - - shader.Use(); - shader.setUniformMat4("P", projection); - shader.setUniformMat4("M", model); - shader.setUniformMat4("V", cam.GetViewMatrix()); - - Cube.Draw(); - - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - - ImGui::Begin("Transform"); - ImGui::Text("Cube"); - ImGui::InputFloat3("Position:", (float*)&Cube.transform.Position); - ImGui::InputFloat3("Rotation:", (float*)&Cube.transform.Rotation); - ImGui::InputFloat3("Scale:", (float*)&Cube.transform.Scale); - - ImGui::End(); - - ImGui::Begin("Camera"); - - ImGui::SliderFloat("Zoom:", &cam.Zoom, 10, 190); - - ImGui::End(); - - - ImGui::Begin("Scripting!!"); - - ImGui::InputTextMultiline("Lua Script", lua_code, 255); - runCode = ImGui::Button("Run"); - - - ImGui::End(); - - - ImGui::ShowDemoWindow(); - - - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - - - GameWindow.SwapBuffers(); - } - - // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); - - Cube.VAO.Delete(); - Cube.elementBuffer.Delete(); - } -*/ \ No newline at end of file + +void Update() +{ + glm::mat4 tran = glm::translate(glm::mat4(), Cube->transform.Position); + glm::mat4 scale = glm::scale(glm::mat4(), Cube->transform.Scale); + glm::mat4 rot = + glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) * + glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) * + glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.z), glm::vec3(0.0f, 0.0f, 1.0f)); + + + glm::mat4 model = tran * rot * scale; + + glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f); + + + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + shader->Use(); + shader->setUniformMat4("P", projection); + shader->setUniformMat4("M", model); + shader->setUniformMat4("V", cam->GetViewMatrix()); + + Cube->Draw(); + +} + + +void Stop() { + // Cleanup + Cube->VAO.Delete(); + Cube->elementBuffer.Delete(); + + delete Cube; + delete cam; + delete shader; +} \ No newline at end of file