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

@@ -3,6 +3,8 @@
#define LOGGER_DEFINITION
#include <logger.h>
#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<Camera>();
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);
}