MAYBE IF IMGUI JUST WORKEDDDDDDDDDDDD
This commit is contained in:
@@ -38,7 +38,7 @@ include_directories(${executable}
|
||||
file(GLOB SourceFiles
|
||||
${SrcDIR}/*
|
||||
${SrcDIR}/util/*
|
||||
${SrcDIR}/util/imgui*
|
||||
${SrcDIR}/util/imgui/*
|
||||
${SrcDIR}/renderer/*
|
||||
)
|
||||
|
||||
|
||||
28
CMakeSettings.json
Normal file
28
CMakeSettings.json
Normal 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": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -90,8 +90,6 @@ typedef enum {
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
std::stringstream outStream;
|
||||
std::map<LogType, std::string> lookupTable;
|
||||
Logger();
|
||||
|
||||
Logger& operator<< (const LogType type) {
|
||||
@@ -119,6 +117,9 @@ public:
|
||||
outStream << data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::stringstream outStream;
|
||||
std::map<LogType, std::string> lookupTable;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,9 +5,17 @@
|
||||
#include <glm/gtc/matrix_transform.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 <KHR/khrplatform.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#if _WIN32
|
||||
#include <SDL.h>
|
||||
#else
|
||||
|
||||
66
src/game.cpp
66
src/game.cpp
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
13
src/game.hpp
13
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 <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#if _WIN32
|
||||
#include <SDL.h>
|
||||
@@ -33,7 +42,7 @@ private:
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "game.hpp"
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
Game game;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -20,8 +20,8 @@ public:
|
||||
|
||||
private:
|
||||
float roll, pitch, yaw;
|
||||
glm::vec3 eyeVector;
|
||||
glm::mat4 viewMatrix;
|
||||
glm::vec3 eyeVector = {};
|
||||
glm::mat4 viewMatrix = {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,4 +3,10 @@
|
||||
|
||||
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user