diff --git a/CMakeLists.txt b/CMakeLists.txt index d6ae629..7e6f40a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ include_directories(${executable} file(GLOB SourceFiles ${SrcDIR}/* ${SrcDIR}/util/* - ${SrcDIR}/util/imgui* + ${SrcDIR}/util/imgui/* ${SrcDIR}/renderer/* ) diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 0000000..cdc79fe --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,28 @@ +{ + "configurations": [ + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "-v", + "ctestCommandArgs": "", + "variables": [] + }, + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "-v", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ], + "variables": [] + } + ] +} \ No newline at end of file diff --git a/include/logger.h b/include/logger.h index 8f75454..1fd2a20 100644 --- a/include/logger.h +++ b/include/logger.h @@ -90,8 +90,6 @@ typedef enum { class Logger { public: - std::stringstream outStream; - std::map lookupTable; Logger(); Logger& operator<< (const LogType type) { @@ -119,6 +117,9 @@ public: outStream << data; return *this; } + + std::stringstream outStream; + std::map lookupTable; }; #endif diff --git a/src/common.hpp b/src/common.hpp index 10af69c..3325660 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -5,9 +5,17 @@ #include #include +#include +#include +#include + #include #include +#include +#include +#include + #if _WIN32 #include #else diff --git a/src/game.cpp b/src/game.cpp index c5429b9..93fe743 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3,6 +3,8 @@ #define LOGGER_DEFINITION #include +#include "renderer/camera.hpp" + #include "common.hpp" @@ -18,6 +20,9 @@ void Game::Setup(int w, int h) { *m_logger << "----------------" << LOGGER_ENDL; *m_logger << LOGGER_ENDL; +#ifdef __DEBUG + *m_logger << LOGGER_DEBUG << "Debug mode enabled" << LOGGER_ENDL; +#endif *m_logger << LOGGER_INFO << "Initializing display" << LOGGER_ENDL; SDL_Init(SDL_INIT_EVERYTHING); @@ -46,11 +51,11 @@ void Game::Setup(int w, int h) { *m_logger << LOGGER_INFO << "Creating OpenGL context" << LOGGER_ENDL; m_glContext = SDL_GL_CreateContext(m_window); - // SDL_WarpMouseInWindow(window, w / 2, h / 2); - // SDL_SetRelativeMouseMode(SDL_TRUE); + //SDL_WarpMouseInWindow(m_window, w / 2, h / 2); + //SDL_SetRelativeMouseMode(SDL_TRUE); // Set VSYNC swap interval - SDL_GL_SetSwapInterval(0); + SDL_GL_SetSwapInterval(1); *m_logger << LOGGER_INFO << "Display set up" << LOGGER_ENDL; @@ -60,31 +65,80 @@ void Game::Setup(int w, int h) { glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); + + +#ifdef __IMGUI + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGui::StyleColorsDark(); + // ImGui_ImplSDL2_InitForOpenGL(m_window, m_glContext); + + ImGuiIO& io = ImGui::GetIO(); + + ImVec2 vec; + vec.x = (float)w; + vec.y = (float)h; + io.DisplaySize = vec; + + vec.x = w > 0 ? ((float)w / w) : 0; + vec.y = h > 0 ? ((float)h / h) : 0; + io.DisplayFramebufferScale = vec; + io.Fonts->AddFontDefault(); + + unsigned char* pixels; + int width, height, bytes_per_pixels; + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &bytes_per_pixels); + + ImGui_ImplOpenGL3_Init("#version 450"); +#endif + *m_logger << LOGGER_INFO << "Loaded OpenGL" << LOGGER_ENDL; *m_logger << LOGGER_ENDL; IsDisplayOpen = true; + + m_cameras["Default"] = std::make_shared(); + m_activeCamera = m_cameras["Default"]; + } void Game::Input(SDL_Event* e) { while (SDL_PollEvent(e)) if (e->type == SDL_QUIT) IsDisplayOpen = false; + + m_activeCamera->MoveCamera(); + m_activeCamera->HandleMouse(*e); + } void Game::Run() { SDL_Event e; + const float clear[] = { 0.1f, 0.45f, 0.9f, 1.0f }; + glClearBufferfv(GL_COLOR, 0, clear); + while (IsDisplayOpen) { Input(&e); + - SDL_GL_SwapWindow(m_window); +#ifdef __IMGUI + ImGui::NewFrame(); + ImGui::Begin("bruh"); + ImGui::Text("Hello, world %d", 123); + if (ImGui::Button("Save")) {} + ImGui::End(); +#endif glClear(GL_DEPTH_BUFFER_BIT); - const float clear[] = { 0.1f, 0.45f, 0.9f, 1.0f }; - glClearBufferfv(GL_COLOR, 0, clear); + +#ifdef __IMGUI + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); +#endif + SDL_GL_SwapWindow(m_window); } diff --git a/src/game.hpp b/src/game.hpp index b2ce27b..c80b96a 100644 --- a/src/game.hpp +++ b/src/game.hpp @@ -1,8 +1,17 @@ #ifndef MINECRAFT_GAME_H_ #define MINECRAFT_GAME_H_ + +#ifdef NDEBUG +#define __DEBUG +#endif + +#define __DEBUG +// #define __IMGUI + #include -#include +#include +#include #if _WIN32 #include @@ -33,7 +42,7 @@ private: std::shared_ptr m_logger; - std::vector> m_cameras; + std::map> m_cameras; std::shared_ptr m_activeCamera; }; diff --git a/src/main.cpp b/src/main.cpp index 6fc4fe4..03951d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "game.hpp" + int main(int argc, char** argv) { Game game; diff --git a/src/renderer/camera.cpp b/src/renderer/camera.cpp index 256f847..3868adb 100644 --- a/src/renderer/camera.cpp +++ b/src/renderer/camera.cpp @@ -1,5 +1,14 @@ #include "camera.hpp" +Camera::Camera() { + roll = 0.0f; + pitch = 0.0f; + yaw = 0.0f; + + eyeVector = {}; + viewMatrix = {}; +} + void Camera::UpdateView() { // roll can be removed from here. because is not actually used in FPS camera glm::mat4 matRoll = glm::mat4(1.0f);//identity matrix; diff --git a/src/renderer/camera.hpp b/src/renderer/camera.hpp index 39255b4..bb1ecc5 100644 --- a/src/renderer/camera.hpp +++ b/src/renderer/camera.hpp @@ -20,8 +20,8 @@ public: private: float roll, pitch, yaw; - glm::vec3 eyeVector; - glm::mat4 viewMatrix; + glm::vec3 eyeVector = {}; + glm::mat4 viewMatrix = {}; }; #endif diff --git a/src/renderer/shader.hpp b/src/renderer/shader.hpp index c414d88..3d83677 100644 --- a/src/renderer/shader.hpp +++ b/src/renderer/shader.hpp @@ -3,4 +3,10 @@ +class Shader { +public: + + +}; + #endif