From 6cf95572d545291649f21e6ac1250036926303bc Mon Sep 17 00:00:00 2001 From: anulax1225 Date: Wed, 5 Jun 2024 14:33:14 +0200 Subject: [PATCH] Should have commited sooner... --- bakara/src/bakara.h | 10 ++++++ bakara/src/bakara/core/application.cpp | 7 +++- bakara/src/bakara/core/application.h | 9 +++-- bakara/src/bakara/core/entry.cpp | 4 +++ bakara/src/bakara/imgui/imgui_layer.cpp | 33 ++++++++++++++++++- bakara/src/bakara/imgui/imgui_layer.h | 23 ++++++++++++- bakara/src/bakara/io/window.h | 4 ++- .../bakara/plaforms/window/glfw/win_glfw.cpp | 8 ++--- .../bakara/plaforms/window/glfw/win_glfw.h | 2 ++ build.sh | 10 ++++-- 10 files changed, 98 insertions(+), 12 deletions(-) diff --git a/bakara/src/bakara.h b/bakara/src/bakara.h index 33199b0..b0bb862 100644 --- a/bakara/src/bakara.h +++ b/bakara/src/bakara.h @@ -4,6 +4,16 @@ Precompiled headers for external pragrams. */ +/*! \namespace Bk +Global namespace doc +*/ +namespace Bk {} + +/*! \namespace Bk::Plaform +Plaform namespace doc +*/ +namespace Bk::Plaform {} + #include #include #include diff --git a/bakara/src/bakara/core/application.cpp b/bakara/src/bakara/core/application.cpp index c43e25d..ce4e630 100644 --- a/bakara/src/bakara/core/application.cpp +++ b/bakara/src/bakara/core/application.cpp @@ -1,10 +1,15 @@ #include "application.h" namespace Bk { + Application* Application::p_instance = nullptr; + Application::Application() { - h_window = Window::create_window(); + BK_CORE_MSG_ASSERT(p_instance == nullptr, "Application already exists, can not create two application.") + Application::p_instance = this; + h_window = std::shared_ptr(Window::create_window()); h_window->set_event_callback(BK_BIND_EVENT_FN(on_event)); + p_running = true; } Application::~Application() { } diff --git a/bakara/src/bakara/core/application.h b/bakara/src/bakara/core/application.h index 1c5a825..6a6d8d0 100644 --- a/bakara/src/bakara/core/application.h +++ b/bakara/src/bakara/core/application.h @@ -69,12 +69,17 @@ namespace Bk { */ void run(); + std::shared_ptr get_window() { return std::shared_ptr(h_window); } + + static Application& get() { return *p_instance; } + protected: - std::unique_ptr h_window; //!< Pointer to the main window + std::shared_ptr h_window; //!< Pointer to the main window private: LayerStack p_layer_stack; //!< Layer stack of the application - bool p_running = true; //!< Flag that indicates if the update loop should stop or not + bool p_running; //!< Flag that indicates if the update loop should stop or not + static Application* p_instance; }; /*! \fn std::unique_ptr Bk::create_app() Is used to retrive the user app class instance, made from inheritance. diff --git a/bakara/src/bakara/core/entry.cpp b/bakara/src/bakara/core/entry.cpp index 0e9fed3..7ca12b7 100644 --- a/bakara/src/bakara/core/entry.cpp +++ b/bakara/src/bakara/core/entry.cpp @@ -2,6 +2,10 @@ #include "log.h" #include "application.h" +/*! \file entry.cpp + This file contains the entry point of the program. +*/ + /*! \fn std::unique_ptr Bk::create_app() External function implemented client side. */ diff --git a/bakara/src/bakara/imgui/imgui_layer.cpp b/bakara/src/bakara/imgui/imgui_layer.cpp index 86ff038..7de732d 100644 --- a/bakara/src/bakara/imgui/imgui_layer.cpp +++ b/bakara/src/bakara/imgui/imgui_layer.cpp @@ -1 +1,32 @@ -#include "imgui_layer.h" \ No newline at end of file +#include "imgui_layer.h" + +namespace Bk { + void ImguiLayer::on_attach() + { + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + + + Application& app = Application::get(); + GLFWwindow* window = static_cast(app.get_window()->get_native_window()); + + // Setup Platform/Renderer bindings + ImGui_ImplGlfw_InitForOpenGL(window, true); + ImGui_ImplOpenGL3_Init("#version 410"); + } + + void ImguiLayer::on_detach() + { + + } + + void ImguiLayer::on_event(Bk::Event& e) + { + + } + + void ImguiLayer::on_update() + { + + } +} \ No newline at end of file diff --git a/bakara/src/bakara/imgui/imgui_layer.h b/bakara/src/bakara/imgui/imgui_layer.h index 91ecec2..111744d 100644 --- a/bakara/src/bakara/imgui/imgui_layer.h +++ b/bakara/src/bakara/imgui/imgui_layer.h @@ -1,2 +1,23 @@ +#pragma once + +#include #include -#include \ No newline at end of file +#include +#include +#include + +namespace Bk { + class ImguiLayer : public Layer + { + public: + ImguiLayer() + : Layer("Imgui") {} + + ~ImguiLayer() = default; + + void on_attach() override; + void on_detach() override; + void on_event(Bk::Event& e) override; + void on_update() override; + }; +} \ No newline at end of file diff --git a/bakara/src/bakara/io/window.h b/bakara/src/bakara/io/window.h index fd249f4..a1ec832 100644 --- a/bakara/src/bakara/io/window.h +++ b/bakara/src/bakara/io/window.h @@ -91,12 +91,14 @@ namespace Bk { */ bool is_open() { return h_is_open; } + virtual void* get_native_window() = 0; + /*! \fn Bk::Window::create_window() Static function implemented in the api window class to get a window specifique api. If no parameter is specified, creates the window with the default settings. @param props : Window information */ - static std::unique_ptr create_window(const WindowProps& props = WindowProps()); + static Window* create_window(const WindowProps& props = WindowProps()); protected: bool h_is_open; //!< indicaste if the window is opened or not }; diff --git a/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp b/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp index a4cee7c..53e3d87 100644 --- a/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp +++ b/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp @@ -2,9 +2,9 @@ #include "win_glfw.h" namespace Bk { - std::unique_ptr Window::create_window(const WindowProps& props) + Window* Window::create_window(const WindowProps& props) { - return std::unique_ptr(new Plaform::WinGLFW(props)); + return new Plaform::WinGLFW(props); } namespace Plaform { @@ -42,9 +42,9 @@ namespace Bk { glfwMakeContextCurrent(p_window); int success = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); - BK_CORE_ASSERT(success) + BK_CORE_MSG_ASSERT(success, "Couldn't load glad!") - BK_CORE_TRACE("Opengl Raw Version : {0}",GL_VERSION); + BK_CORE_INFO("Opengl Raw Version : {0}",GL_VERSION); glfwSetWindowUserPointer(p_window, &p_data); set_vsync(true); diff --git a/bakara/src/bakara/plaforms/window/glfw/win_glfw.h b/bakara/src/bakara/plaforms/window/glfw/win_glfw.h index 24c17bf..dc851d3 100644 --- a/bakara/src/bakara/plaforms/window/glfw/win_glfw.h +++ b/bakara/src/bakara/plaforms/window/glfw/win_glfw.h @@ -23,6 +23,8 @@ namespace Bk::Plaform { void close() override; void open() override; + + void* get_native_window() override { return p_window; } private: GLFWwindow* p_window; diff --git a/build.sh b/build.sh index 60fa7cd..69adb48 100755 --- a/build.sh +++ b/build.sh @@ -2,12 +2,17 @@ clear echo ================== echo [BUILDING PROJECT] echo ================== - +echo number of lines : +find ./bakara/src -name *.cpp -or -name *.h -exec cat {} \; | wc -l if [ -z ${clear} ]; then clear=0 +else + clear=1 fi if [ -z ${exec} ]; then exec=0 +else + exec=1 fi if [ 1 -eq ${clear} ]; then @@ -16,8 +21,9 @@ if [ 1 -eq ${clear} ]; then else echo Caching bin/bin-int dirs fi - +echo premake5 gmake +echo make $1 if [ $? -eq 0 ]; then echo Compilation Success