MAYBE IF IMGUI JUST WORKEDDDDDDDDDDDD

This commit is contained in:
Ben
2019-10-04 22:03:07 +01:00
parent aeb6f46435
commit dbd96ca06f
10 changed files with 129 additions and 13 deletions

View File

@@ -38,7 +38,7 @@ include_directories(${executable}
file(GLOB SourceFiles file(GLOB SourceFiles
${SrcDIR}/* ${SrcDIR}/*
${SrcDIR}/util/* ${SrcDIR}/util/*
${SrcDIR}/util/imgui* ${SrcDIR}/util/imgui/*
${SrcDIR}/renderer/* ${SrcDIR}/renderer/*
) )

28
CMakeSettings.json Normal file
View File

@@ -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": []
}
]
}

View File

@@ -90,8 +90,6 @@ typedef enum {
class Logger { class Logger {
public: public:
std::stringstream outStream;
std::map<LogType, std::string> lookupTable;
Logger(); Logger();
Logger& operator<< (const LogType type) { Logger& operator<< (const LogType type) {
@@ -119,6 +117,9 @@ public:
outStream << data; outStream << data;
return *this; return *this;
} }
std::stringstream outStream;
std::map<LogType, std::string> lookupTable;
}; };
#endif #endif

View File

@@ -5,9 +5,17 @@
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include <imgui/imgui.h>
#include <imgui/imgui_impl_sdl.h>
#include <imgui/imgui_impl_opengl3.h>
#include <glad/glad.h> #include <glad/glad.h>
#include <KHR/khrplatform.h> #include <KHR/khrplatform.h>
#include <string>
#include <vector>
#include <memory>
#if _WIN32 #if _WIN32
#include <SDL.h> #include <SDL.h>
#else #else

View File

@@ -3,6 +3,8 @@
#define LOGGER_DEFINITION #define LOGGER_DEFINITION
#include <logger.h> #include <logger.h>
#include "renderer/camera.hpp"
#include "common.hpp" #include "common.hpp"
@@ -18,6 +20,9 @@ void Game::Setup(int w, int h) {
*m_logger << "----------------" << LOGGER_ENDL; *m_logger << "----------------" << LOGGER_ENDL;
*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; *m_logger << LOGGER_INFO << "Initializing display" << LOGGER_ENDL;
SDL_Init(SDL_INIT_EVERYTHING); 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_logger << LOGGER_INFO << "Creating OpenGL context" << LOGGER_ENDL;
m_glContext = SDL_GL_CreateContext(m_window); m_glContext = SDL_GL_CreateContext(m_window);
// SDL_WarpMouseInWindow(window, w / 2, h / 2); //SDL_WarpMouseInWindow(m_window, w / 2, h / 2);
// SDL_SetRelativeMouseMode(SDL_TRUE); //SDL_SetRelativeMouseMode(SDL_TRUE);
// Set VSYNC swap interval // Set VSYNC swap interval
SDL_GL_SetSwapInterval(0); SDL_GL_SetSwapInterval(1);
*m_logger << LOGGER_INFO << "Display set up" << LOGGER_ENDL; *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_DEPTH_TEST);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); 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_INFO << "Loaded OpenGL" << LOGGER_ENDL;
*m_logger << LOGGER_ENDL; *m_logger << LOGGER_ENDL;
IsDisplayOpen = true; IsDisplayOpen = true;
m_cameras["Default"] = std::make_shared<Camera>();
m_activeCamera = m_cameras["Default"];
} }
void Game::Input(SDL_Event* e) { void Game::Input(SDL_Event* e) {
while (SDL_PollEvent(e)) while (SDL_PollEvent(e))
if (e->type == SDL_QUIT) if (e->type == SDL_QUIT)
IsDisplayOpen = false; IsDisplayOpen = false;
m_activeCamera->MoveCamera();
m_activeCamera->HandleMouse(*e);
} }
void Game::Run() { void Game::Run() {
SDL_Event e; SDL_Event e;
const float clear[] = { 0.1f, 0.45f, 0.9f, 1.0f };
glClearBufferfv(GL_COLOR, 0, clear);
while (IsDisplayOpen) { while (IsDisplayOpen) {
Input(&e); 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); 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);
} }

View File

@@ -1,8 +1,17 @@
#ifndef MINECRAFT_GAME_H_ #ifndef MINECRAFT_GAME_H_
#define MINECRAFT_GAME_H_ #define MINECRAFT_GAME_H_
#ifdef NDEBUG
#define __DEBUG
#endif
#define __DEBUG
// #define __IMGUI
#include <memory> #include <memory>
#include <vector> #include <string>
#include <map>
#if _WIN32 #if _WIN32
#include <SDL.h> #include <SDL.h>
@@ -33,7 +42,7 @@ private:
std::shared_ptr<Logger> m_logger; std::shared_ptr<Logger> m_logger;
std::vector<std::shared_ptr<Camera>> m_cameras; std::map<std::string, std::shared_ptr<Camera>> m_cameras;
std::shared_ptr<Camera> m_activeCamera; std::shared_ptr<Camera> m_activeCamera;
}; };

View File

@@ -2,6 +2,7 @@
#include "game.hpp" #include "game.hpp"
int main(int argc, char** argv) { int main(int argc, char** argv) {
Game game; Game game;

View File

@@ -1,5 +1,14 @@
#include "camera.hpp" #include "camera.hpp"
Camera::Camera() {
roll = 0.0f;
pitch = 0.0f;
yaw = 0.0f;
eyeVector = {};
viewMatrix = {};
}
void Camera::UpdateView() { void Camera::UpdateView() {
// roll can be removed from here. because is not actually used in FPS camera // roll can be removed from here. because is not actually used in FPS camera
glm::mat4 matRoll = glm::mat4(1.0f);//identity matrix; glm::mat4 matRoll = glm::mat4(1.0f);//identity matrix;

View File

@@ -20,8 +20,8 @@ public:
private: private:
float roll, pitch, yaw; float roll, pitch, yaw;
glm::vec3 eyeVector; glm::vec3 eyeVector = {};
glm::mat4 viewMatrix; glm::mat4 viewMatrix = {};
}; };
#endif #endif

View File

@@ -3,4 +3,10 @@
class Shader {
public:
};
#endif #endif