Made multiple managers for individual pieces
Added UIManager that renders the UI inside the window
This commit is contained in:
parent
dae8830e2b
commit
76c051e407
@ -1,31 +1,64 @@
|
||||
#include "BarinkEngine.h"
|
||||
#include <imgui.h>
|
||||
|
||||
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();
|
||||
|
||||
UpdateApplication();
|
||||
Update();
|
||||
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
@ -3,23 +3,18 @@
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
|
||||
#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"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "lauxlib.h"
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
void WARN(std::string message);
|
||||
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
namespace BarinkEngine {
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
static void Startup();
|
||||
static void Shutdown();
|
||||
|
||||
};
|
||||
};
|
15
BarinkEngine/Include/Graphics/GUI/GUIManager.h
Normal file
15
BarinkEngine/Include/Graphics/GUI/GUIManager.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "Graphics/Window.h"
|
||||
|
||||
|
||||
class GUIManager {
|
||||
public:
|
||||
GUIManager(BarinkWindow* window);
|
||||
~GUIManager();
|
||||
|
||||
void Render();
|
||||
|
||||
|
||||
private:
|
||||
BarinkWindow* currentwindow;
|
||||
};
|
@ -13,10 +13,6 @@
|
||||
*/
|
||||
|
||||
class Renderable {
|
||||
private:
|
||||
std::vector<BarinkEngine::Mesh> meshes;
|
||||
Renderable();
|
||||
|
||||
public:
|
||||
Buffer vertexBuffer;
|
||||
Buffer elementBuffer;
|
||||
@ -27,4 +23,7 @@ public:
|
||||
static Renderable Load();
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
std::vector<BarinkEngine::Mesh> meshes;
|
||||
Renderable();
|
||||
};
|
21
BarinkEngine/Include/Graphics/Renderer.h
Normal file
21
BarinkEngine/Include/Graphics/Renderer.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Graphics/Renderable.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
void Render();
|
||||
|
||||
void Submit(Renderable* model);
|
||||
|
||||
private:
|
||||
std::vector<Renderable*> models;
|
||||
|
||||
};
|
||||
}
|
18
BarinkEngine/Include/Input/InputManager.h
Normal file
18
BarinkEngine/Include/Input/InputManager.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
#include "Graphics/Window.h"
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
class InputManager {
|
||||
public:
|
||||
InputManager();
|
||||
|
||||
void PollEvents();
|
||||
void attach(BarinkWindow* window);
|
||||
|
||||
private:
|
||||
std::vector<BarinkWindow*> windows;
|
||||
};
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
28
BarinkEngine/Include/Scripting/LuaScript.h
Normal file
28
BarinkEngine/Include/Scripting/LuaScript.h
Normal file
@ -0,0 +1,28 @@
|
||||
#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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
*/
|
28
BarinkEngine/Include/Scripting/LuaScriptingManager.h
Normal file
28
BarinkEngine/Include/Scripting/LuaScriptingManager.h
Normal file
@ -0,0 +1,28 @@
|
||||
#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();
|
||||
};*/
|
19
BarinkEngine/Input/InputManager.cpp
Normal file
19
BarinkEngine/Input/InputManager.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "Input/InputManager.h"
|
||||
|
||||
void BarinkEngine::InputManager::PollEvents()
|
||||
{
|
||||
|
||||
for (std::vector<BarinkWindow*>::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<BarinkWindow*>();
|
||||
}
|
11
BarinkEngine/Scripting/LuaScript.cpp
Normal file
11
BarinkEngine/Scripting/LuaScript.cpp
Normal file
@ -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());
|
||||
}
|
||||
*/
|
18
BarinkEngine/Scripting/LuaScriptingManager.cpp
Normal file
18
BarinkEngine/Scripting/LuaScriptingManager.cpp
Normal file
@ -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);
|
||||
}
|
||||
*/
|
38
BarinkEngine/graphics/GUI/GUIManager.cpp
Normal file
38
BarinkEngine/graphics/GUI/GUIManager.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "Graphics/GUI/GUIManager.h"
|
||||
#include "imgui.h"
|
||||
#include "backends/imgui_impl_opengl3.h"
|
||||
#include <backends/imgui_impl_glfw.cpp>
|
||||
|
||||
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());
|
||||
}
|
24
BarinkEngine/graphics/Renderer.cpp
Normal file
24
BarinkEngine/graphics/Renderer.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "Graphics/Renderer.h"
|
||||
|
||||
BarinkEngine::Renderer::Renderer()
|
||||
{
|
||||
models = std::vector<Renderable*>();
|
||||
}
|
||||
|
||||
BarinkEngine::Renderer::~Renderer()
|
||||
{
|
||||
// CleanUp!
|
||||
}
|
||||
|
||||
void BarinkEngine::Renderer::Render()
|
||||
{
|
||||
for (auto model : models) {
|
||||
model->Draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BarinkEngine::Renderer::Submit(Renderable* model)
|
||||
{
|
||||
models.push_back(model);
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
#include "Graphics/Window.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,6 @@ bool BarinkWindow::WindowShouldClose(){
|
||||
|
||||
void BarinkWindow::Poll()
|
||||
{
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
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();
|
||||
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
||||
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user